module Bio.Alignment.BlastFlat
(
BlastFlat(..)
, readXML
, flatten
, B.BlastRecord
, B.blastprogram, B.blastversion, B.blastdate, B.blastreferences
, B.database, B.dbsequences, B.dbchars, B.results
, B.Aux(..), B.Strand(..)
)where
import qualified Bio.Alignment.BlastData as B
import qualified Bio.Alignment.BlastXML as X
import Data.ByteString.Lazy.Char8 (empty)
data BlastFlat = BlastFlat {
query :: !B.SeqId, qlength :: !Int
, subject :: !B.SeqId, slength :: !Int
, bits :: !Double, e_val :: !Double
, identity :: (Int,Int)
, q_from, q_to, h_from, h_to :: !Int
, aux :: !B.Aux
}
readXML :: FilePath -> IO [BlastFlat]
readXML f = return . concatMap (flatten . B.results) =<< X.readXML f
flatten :: [B.BlastRecord] -> [BlastFlat]
flatten = concatMap frecord
where frecord r =
concatMap (fhit (bf0 { query = B.query r, qlength = B.qlength r })) $ B.hits r
fhit f h =
map (fmatch f { subject = B.subject h, slength = B.slength h }) $ B.matches h
fmatch f m =
f { bits = B.bits m, e_val = B.e_val m, identity = B.identity m
, q_from = B.q_from m, q_to = B.q_to m
, h_from = B.h_from m, h_to = B.h_to m, aux = B.aux m}
bf0 = BlastFlat e 0 e 0 0 0 (0,0) 0 0 0 0 (B.Frame B.Plus 0)
e = empty