module BioInf.RNAwolf.Interior 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
import Debug.Trace
fInteriorOuter :: BaseF (NInteLoop -> ExtFeatures (VU.Vector (PairIdx,Double)))
fInteriorOuter Params{..} inp (NInteLoop nInteLoop) i j ct eI eJ
| ji<4 = VU.empty
| otherwise = VU.map f $ VU.singleton (i,j)
where
f (k,l) = ( (i,j)
, nInteLoop ! (i,j)
+ ijSc
)
ijSc = interiorClose ! (((nI,nJ),(ct,eI,eJ)),nIp1,nJm1)
nI = inp VU.! i
nJ = inp VU.! j
nIp1 = inp VU.! (i+1)
nJm1 = inp VU.! (j1)
btInteriorOuter
:: Params
-> Primary
-> EStem
-> NInteLoop
-> NBT
-> ExtBT
btInteriorOuter ps inp (EStem eStem) nInteLoop btILoop i j ct eI eJ d =
[ (ij:x,z)
| i>=0,i<j,j<=n
, ((k,l),enext) <- VU.toList $ fInteriorOuter ps inp nInteLoop i j ct eI eJ
, let d' = newD d ehere enext
, testD d'
, (x,z) <- btILoop k l d'
] where
ij = ((i,j),(ct,eI,eJ))
ehere = eStem!ij
n = VU.length inp 1
lol = VU.toList $ fInteriorOuter ps inp nInteLoop i j ct eI eJ
iltrc k x = trace (show (k,x)) x
fInteriorLoop :: BaseF (NInte -> Features (VU.Vector (PairIdx,Double)))
fInteriorLoop Params{..} inp (NInte nInte) i j
| ji<4 = VU.empty
| otherwise = VU.map f kls
where
f (k,l) = ( (k,l)
, nInte ! (k,l)
+ interiorLength ! (lenI+lenJ)
+ interiorAsym ! (abs $ lenI lenJ)
) where lenI = ki1; lenJ = jl1
kls = VU.map (\(dI,dJ) -> (i+dI,jdJ)) $ fInteriorKLs i j
btInteriorLoop
:: Params
-> Primary
-> NInteLoop
-> NInte
-> NBT
-> NBT
btInteriorLoop ps inp (NInteLoop nInteLoop) nInte btIL i j d =
[ (x,z)
| i>=0,i<j,j<=n
, ((k,l),enext) <- VU.toList $ fInteriorLoop ps inp nInte i j
, let d' = newD d ehere enext
, testD d'
, (x,z) <- btIL k l d'
] where
ehere = nInteLoop!(i,j)
n = VU.length inp 1
fInteriorInner :: BaseF (EStem -> Features (VU.Vector (ExtPairIdx,Double)))
fInteriorInner Params{..} inp (EStem eStem) i j
| ji<2 = VU.empty
| i==0 || j+1==VU.length inp = VU.empty
| otherwise = VU.map f kls
where
f ijExt@((i,j),(ctIJ,eI,eJ)) =
( ijExt
, eStem ! ijExt
+ interiorClose ! (((nJ,nI),(ctIJ,eJ,eI)),nJp1,nIm1)
) where nI = inp VU.! i
nJ = inp VU.! j
nIm1 = inp VU.! (i1)
nJp1 = inp VU.! (j+1)
kls = VU.fromList [ ((i,j),(ctIJ,eI,eJ))
| eI<-wsh, eJ<-wsh, ctIJ<-citr
]
btInteriorInner
:: Params
-> Primary
-> NInte
-> EStem
-> ExtBT
-> NBT
btInteriorInner ps inp (NInte nInte) eStem btES i j d =
[ (x,z)
| i>=0,i<j,j<=n
, ((_,(eI,eJ,ct)),enext) <- VU.toList $ fInteriorInner ps inp eStem i j
, let d' = newD d ehere enext
, testD d'
, (x,z) <- btES i j eI eJ ct d'
] where
n = VU.length inp 1
ehere = nInte!(i,j)
fInteriorKLs :: Int -> Int -> VU.Vector (Int,Int)
fInteriorKLs i j = didjs where
didjs = VU.unfoldr mkDs (4,2)
mkDs (d,s)
| d>maxd = Nothing
| s>=d2 = Just ((ds,s),(d+1,2))
| otherwise = Just ((ds,s),(d,s+1))
maxd = min maxLength (ji4)