{-# LANGUAGE BangPatterns #-}
module Bio.Chain.Alignment.Scoring.Loader where
import Control.Applicative ( liftA2 )
class ScoringMatrix a where
scoring :: a -> Char -> Char -> Int
loadMatrix :: String -> [((Char, Char), Int)]
loadMatrix txt = concatMap (lineMap . words) (tail txtlns)
where
txtlns :: [String]
!txtlns = filter (liftA2 (||) null ((/= '#') . head)) (strip <$> lines txt)
letters :: [Char]
!letters = (map head . words . head) txtlns
strip :: String -> String
strip = reverse . dropWhile (== ' ') . reverse . dropWhile (== ' ')
lineMap :: [String] -> [((Char, Char), Int)]
lineMap [] = []
lineMap (x : xs) =
let !hx = head x
g (n, c) = ((hx, c), n)
in g <$> (read <$> xs) `zip` letters