module Biobase.Structure where
import Data.List (sort,groupBy)
import Biobase.RNA
data Complex = Complex
{ comments :: String
, structures :: [(Primary,Secondary)]
}
deriving (Show)
data Secondary = Secondary
{ len :: Int
, pairings :: [(Int,Int)]
}
deriving (Show)
data SSTree a = SSTree Int Int a [SSTree a]
| SSExt Int a [SSTree a]
deriving (Read,Show,Eq)
toSSTree :: Secondary -> SSTree ()
toSSTree Secondary{..} = ext $ sort pairings where
ext [] = SSExt len () []
ext xs = SSExt len () . map tree $ groupBy (\l r -> snd l > fst r) xs
tree [(i,j)] = SSTree i j () []
tree ((i,j):xs) = SSTree i j () . map tree $ groupBy (\l r -> snd l > fst r) xs