module Biobase.TrainingData.Manip where
import Data.List (sort,sortBy)
import Data.Ord (comparing)
import Biobase.Secondary.PseudoKnots
import Biobase.TrainingData
type TDmanip = Either TrainingData TrainingData
removePK rpk td@TrainingData{..}
| not rpk = td
| otherwise = td{secondary = removeByCounting secondary}
fRemoveTriplets False td = td
fRemoveTriplets True td@TrainingData{..} = td{secondary = sort $ rmTs secondary} where
rmTs [] = []
rmTs (x:xs)
| ys <- triplets x xs
, not $ null ys = if worst x ys then rmTs xs else rmTs xs++[x]
| otherwise = x : rmTs xs
where
triplets ((i,j),_) zs = filter (\((k,l),_) -> i==k || i==l || j==k || j==l) zs
worst z zs = last (sortBy (comparing snd) $ z : zs) == z