module BioInf.RNAwolf.Stem where
import qualified Data.Vector.Unboxed as VU
import Biobase.Primary
import Biobase.Secondary
import Data.PrimitiveArray
import Data.PrimitiveArray.Ix
import BioInf.Params
import BioInf.RNAwolf.Types
fNstem :: BaseF (EStem -> Features (VU.Vector (ExtPairIdx,Double)))
fNstem Params{..} inp (EStem eStem) i j
| i<0 || j>n = error $ "Stem.fNstem: " ++ show (i,j)
| ji<=2 = VU.empty
| otherwise = VU.map f $ VU.fromList [ (ct,eI,eJ) | ct<-citr, eI<-wsh, eJ<-wsh ]
where
f ext = ( idx
, eStem !idx
) where idx = ((i,j),ext)
n = VU.length inp 1
btNstem
:: Params
-> Primary
-> NStem
-> EStem
-> ExtBT
-> NBT
btNstem ps inp nStem eStem btES i j d =
[ (x,z)
| i>=0,i<j,j<=n
, ((_,(ct,eI,eJ)),enext) <- VU.toList $ fNstem ps inp eStem i j
, let d' = newD d ehere enext
, testD d'
, (x,z) <- btES i j ct eI eJ d'
, testD z
] where
ehere = unNStem nStem !(i,j)
n = VU.length inp 1
fStem :: BaseF (EStem -> ExtFeatures (VU.Vector (ExtPairIdx,Double)))
fStem Params{..} inp (EStem eStem) i j ct eI eJ
| ji<3 = VU.empty
| otherwise = VU.map f $ eKLs
where
f (ctKL,eK,eL) = ( ((k,l),(ctKL,eK,eL))
, eStem ! ((k,l),(ctKL,eK,eL))
+ stem ! (ijExt,((inp VU.! l,inp VU.! k),(ctKL,eL,eK)))
)
ijExt = ((inp VU.! i, inp VU.! j),(ct,eI,eJ))
k = i+1
l = j1
eKLs = VU.fromList [ (ctKL,eK,eL) | eK<-wsh, eL<-wsh, ctKL<-citr ]
btStem
:: Params
-> Primary
-> EStem
-> ExtBT
-> ExtBT
btStem ps inp eStem btES i j ct eI eJ d =
[ (ij:x,z)
| i>=0,i<j,j<=n
, (((k,l),(ctKL,eK,eL)),enext) <- VU.toList $ fStem ps inp eStem i j ct eI eJ
, let d' = newD d ehere enext
, testD d'
, (x,z) <- btES k l ctKL eK eL d'
] where
ij = ((i,j),(ct,eI,eJ))
ehere = unEStem eStem !ij
n = VU.length inp 1