module Biobase.TrainingData.Filter where
import Data.List
import qualified Data.Vector.Unboxed as VU
import Biobase.TrainingData
import Biobase.TrainingData.Manip
fMinRelPairs :: Maybe Double -> TDmanip -> TDmanip
fMinRelPairs Nothing x    = x
fMinRelPairs _ l@(Left _) = l
fMinRelPairs (Just rel) r@(Right td@(TrainingData{..}))
  | rel > numps * 2 / lenpri = Left td
  | otherwise = r
  where
    lenpri = genericLength primary
    numps  = genericLength secondary
fErrorCheck :: TDmanip -> TDmanip
fErrorCheck l@(Left _) = l
fErrorCheck r@(Right td@(TrainingData{..}))
  | any (<0) ixs = Left td 
  | any (>=l) ixs = Left td 
  | any ((=='&') . (v VU.!)) ixs = Left td 
  | otherwise = r
  where
    ixs = concatMap (\((i,j),_) -> [i,j]) secondary
    l = length primary
    v = VU.fromList primary