-- | Model the BED format, according to the spec at-- http://genome.ucsc.edu/FAQ/FAQformat#format1moduleBio.Alignment.BED(BED(..),Dir(..),readBED,writeBED)whereimportBio.Sequence.SeqData(Offset)importData.WordimportqualifiedData.ByteString.Lazy.Char8asBimportData.ByteString.Lazy.Char8(ByteString)-- | The BED data type Note that the specification allows a variable number of fields, with-- only the three first required. This definition requires all fields to be present.dataBED=BED{chrom::ByteString,chromStart,chromEnd::Offset,name::ByteString,score::Int-- ^ Range 0..1000,strand::Dir,thickStart,thickEnd::Offset,itemRGB::(Word8,Word8,Word8)-- ^ Available BED files appear to not-- support this format. RGB is therefore-- ignored (read and written as '0'),blockSizeStart::[(Offset,Offset)]-- ^ Lists of lenght blockCount, blockStarts-- are relative to chromStart}-- | Yet another direction data structure.dataDir=Fwd|RevderivingEqinstanceShowDirwhereshowFwd="+"showRev="-"instanceReadDirwherereadsPrec_('+':rest)=[(Fwd,rest)]readsPrec_('-':rest)=[(Rev,rest)]readsPrec_x=error("Can't parse '"++x++"' as a Dir")readBED::FilePath->IO[BED]readBEDf=(map(unpack1.myWords).B.lines)`fmap`B.readFilefwhereunpack1[c,cs,ce,nm,sc,str,ts,te,_rgb,_bc,bsz,bst]=BEDc(ics)(ice)nm(isc)(istr)(its)(ite)(0,0,0)(zip(i'bsz)(i'bst))unpack1_x=error("incorrect number of fields in BED record ("++show(length_x)++"):\n"++show_x)i::Reada=>ByteString->ai=read.B.unpacki'::Reada=>ByteString->[a]i'=read.(++"]").('[':).B.unpackmyWords=maprmtabs.B.groupBy(const(/='\t'))rmtabsx=ifnot(B.nullx)&&B.headx=='\t'thenB.drop1xelsexinstanceShowBEDwhereshow=B.unpack.pack1writeBED::FilePath->[BED]->IO()writeBEDf=B.writeFilef.B.unlines.mappack1pack1::BED->ByteStringpack1(BEDccscenmscstrtste_rgbbszst)=letbl=lengthbszst(bsz,bst)=unzipbszstb::Showa=>a->ByteStringb=B.pack.showb'::Showa=>[a]->ByteStringb'=B.pack.drop1.init.showinB.intercalate(B.pack"\t")[c,bcs,bce,nm,bsc,bstr,bts,bte,b(0::Int),bbl,b'bsz,b'bst]