@@ -64,6 +64,20 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
6464 // bp=0 encodes 2 base pairs
6565 for (bpIn=0 ; bpIn<seedE_rec.shape ()[2 ] && (i1+bpIn+1 -offset1)<seed.size1 () && (i2+bpIn+1 -offset2)<seed.size2 (); bpIn++) {
6666
67+ bool validLeftEnd = true ;
68+
69+ // if no LP : check for direct right-stacking of i
70+ if (noLpShift > 0 ) {
71+ // check if feasible extension
72+ if (isFeasibleSeedBasePair (i1+1 ,i2+1 )) {
73+ // get stacking energy
74+ iStackE = energy.getE_interLeft (i1,i1+1 ,i2,i2+1 );
75+ } else {
76+ // no valid noLP extension possible
77+ validLeftEnd = false ;
78+ }
79+ }
80+
6781 // for feasible unpaired in seq1 in increasing order
6882 for (u1=0 ; u1<seedE_rec.shape ()[3 ] && (i1+bpIn+1 +u1-offset1) < seed.size1 (); u1++) {
6983
@@ -76,26 +90,16 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
7690 // get right seed boundaries
7791 j1 = i1+bpIn+1 +u1;
7892 j2 = i2+bpIn+1 +u2;
79- // check if right boundary is complementary and feasible
80- // check if this index range is to be considered for seed search
81- bool validSeedSite = isFeasibleSeedBasePair (j1,j2,true );
82-
83- // if no LP : check for direct right-stacking of i
84- if (noLpShift > 0 ) {
85- // check if feasible extension
86- if (isFeasibleSeedBasePair (i1+1 ,i2+1 )) {
87- // get stacking energy
88- iStackE = energy.getE_interLeft (i1,i1+1 ,i2,i2+1 );
89- } else {
90- validSeedSite = false ;
91- }
92- }
9393
9494 // init current seed energy
9595 curE = E_INF;
9696
97- // check if right boundary is complementary
98- if (validSeedSite) {
97+ // check if this index range is to be considered for seed search
98+ // check if boundaries are complementary
99+ if (validLeftEnd
100+ && isFeasibleSeedBasePair (j1,j2,true )
101+ && (noLpShift==0 || isFeasibleSeedBasePair (j1-1 ,j2-1 )))
102+ {
99103
100104 // base case: only left and right base pair present
101105 if (bpIn==0 ) {
@@ -108,8 +112,8 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
108112 } else {
109113
110114 // explicitly check direct stacking extension in noLP mode
111- if (noLpShift > 0 && E_isNotINF ( getSeedE ( i1+1 -offset1 , i2+1 -offset2 , bpIn-1 , u1, u2 ) )) {
112- curE = std::min ( curE, iStackE + getSeedE ( i1+1 -offset1 , i2+1 -offset2 , bpIn-1 , u1, u2 ) );
115+ if (noLpShift > 0 && E_isNotINF ( getSeedE ( i1+1 , i2+1 , bpIn-1 , u1, u2 ) )) {
116+ curE = std::min ( curE, iStackE + getSeedE ( i1+1 , i2+1 , bpIn-1 , u1, u2 ) );
113117 }
114118
115119 // if enough interior base pairs left
@@ -127,15 +131,15 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
127131 k2 = i2+u2p+1 +noLpShift;
128132 // check if split pair is complementary
129133 // and recursed entry is < E_INF
130- if (! (isFeasibleSeedBasePair (k1,k2) && E_isNotINF ( getSeedE ( k1-offset1 , k2-offset2 , bpIn-1 -noLpShift, u1-u1p, u2-u2p ) ) ) ) {
134+ if (! (isFeasibleSeedBasePair (k1,k2) && E_isNotINF ( getSeedE ( k1, k2, bpIn-1 -noLpShift, u1-u1p, u2-u2p ) ) ) ) {
131135 continue ; // not complementary -> skip
132136 }
133137
134138 // update mfe for split at k1,k2
135139 curE = std::min ( curE,
136140 iStackE
137141 + energy.getE_interLeft (i1+noLpShift,k1,i2+noLpShift,k2)
138- + getSeedE ( k1-offset1 , k2-offset2 , bpIn-1 -noLpShift, u1-u1p, u2-u2p )
142+ + getSeedE ( k1, k2, bpIn-1 -noLpShift, u1-u1p, u2-u2p )
139143 );
140144 } // u2p
141145 } // u1p
@@ -145,8 +149,7 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
145149 } // (j1,j2) complementary
146150
147151 // store seed energy
148- setSeedE ( i1-offset1, i2-offset2, bpIn, u1, u2, curE );
149-
152+ setSeedE ( i1, i2, bpIn, u1, u2, curE );
150153 } // u2
151154 } // u1
152155
@@ -176,7 +179,7 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
176179 }
177180
178181 // get overall interaction energy
179- E_type curEhyb = getSeedE ( i1-offset1 , i2-offset2 , bpIn, u1, u2 ) + energy.getE_init ();
182+ E_type curEhyb = getSeedE ( i1, i2, bpIn, u1, u2 ) + energy.getE_init ();
180183 curE = energy.getE ( i1, j1, i2, j2, curEhyb );
181184
182185 // check hybrid energy bound including Einit
@@ -195,7 +198,7 @@ fillSeed( const size_t i1min, const size_t i1max, const size_t i2min, const size
195198 // reduce bestE to hybridization energy only (init+loops)
196199 if (E_isNotINF ( bestE )) {
197200 // get seed's hybridization loop energies only
198- bestE = getSeedE ( i1-offset1 , i2-offset2 , bpIn, u1best, u2best );
201+ bestE = getSeedE ( i1, i2, bpIn, u1best, u2best );
199202 // count true seed
200203 seedCountNotInf++;
201204 }
@@ -256,13 +259,11 @@ traceBackSeed( Interaction & interaction
256259 // trace each seed base pair (excluding right most)
257260 for ( size_t bpIn=1 +bpInbetween; bpIn-- > 0 ; ) {
258261
259-
260-
261262 // base case: only left and right base pair present
262263 if (bpIn==0 ) {
263264 // add left base pair if not left seed boundary
264265 if (i1 != i1_) {
265- interaction.basePairs .push_back ( energy.getBasePair (i1+offset1 ,i2+offset2 ) );
266+ interaction.basePairs .push_back ( energy.getBasePair (i1,i2) );
266267 }
267268
268269 } else {
@@ -272,12 +273,16 @@ traceBackSeed( Interaction & interaction
272273 // check if feasible extension
273274 assert (isFeasibleSeedBasePair (i1+1 ,i2+1 ));
274275 // get stacking energy
275- iStackE = energy.getE_interLeft (i1+offset1 ,i1+1 +offset1 ,i2+offset2 ,i2+1 +offset2 );
276+ iStackE = energy.getE_interLeft (i1,i1+1 ,i2,i2+1 );
276277 // noLP : check stacking of i
277278 if ( E_equal ( curE, iStackE + getSeedE ( i1+1 , i2+1 , bpIn-1 , u1max, u2max )) ) {
279+ // store left base pair if not left seed boundary
280+ if (i1 != i1_) {
281+ interaction.basePairs .push_back ( energy.getBasePair (i1,i2) );
282+ }
278283 i1++;
279284 i2++;
280- curE = getSeedE ( i1+ 1 , i2+ 1 , bpIn-1 , u1max, u2max );
285+ curE = getSeedE ( i1, i2, bpIn-1 , u1max, u2max );
281286 continue ;
282287 }
283288 // sanity check for noLP mode
@@ -288,36 +293,36 @@ traceBackSeed( Interaction & interaction
288293 // i1 .. i1+u1p+1 .. j1
289294 // i2 .. i2+u2p+1 .. j2
290295 bool traceNotFound = true ;
291- for (u1=1 +u1max ; traceNotFound && u1-- > 0 ; ) {
292- for (u2=1 +u2max ; traceNotFound && u2-- > 0 ; ) {
296+ for (u1=0 ; traceNotFound && u1<=u1max ; u1++ ) {
297+ for (u2=0 ; traceNotFound && u2<=u2max && (u1+u2)<=uMax ; u2++ ) {
293298 // check if overall number of unpaired is not exceeded
294299 // or skip stacked extension since covered above
295- if (u1+u2 > uMax || u1+u2 < noLpShift) {
300+ if (u1+u2 < noLpShift) {
296301 continue ;
297302 }
298303
299304 k1 = i1+u1+1 +noLpShift;
300305 k2 = i2+u2+1 +noLpShift;
301306
302307 // check if valid trace
303- if ( isFeasibleSeedBasePair (k1+offset1 , k2+offset2 ) && E_isNotINF ( getSeedE ( k1, k2, bpIn-1 , u1max-u1, u2max-u2 ) ) ) {
308+ if ( isFeasibleSeedBasePair (k1, k2) && E_isNotINF ( getSeedE ( k1, k2, bpIn-1 -noLpShift , u1max-u1, u2max-u2 ) ) ) {
304309
305310 // check if correct trace
306311 if ( E_equal ( curE, iStackE
307- + energy.getE_interLeft (i1+noLpShift+offset1 ,k1+offset1 ,i2+noLpShift+offset2 ,k2+offset2 )
312+ + energy.getE_interLeft (i1+noLpShift,k1,i2+noLpShift,k2)
308313 + getSeedE ( k1, k2, bpIn-1 -noLpShift, u1max-u1, u2max-u2 )) )
309314 {
315+ // store next energy value to trace
316+ curE = getSeedE ( k1, k2, bpIn-1 -noLpShift, u1max-u1, u2max-u2 );
310317 // store left base pair if not left seed boundary
311318 if (i1 != i1_) {
312- interaction.basePairs .push_back ( energy.getBasePair (i1+offset1 ,i2+offset2 ) );
319+ interaction.basePairs .push_back ( energy.getBasePair (i1,i2) );
313320 }
314321 if (noLpShift > 0 ) {
315- interaction.basePairs .push_back ( energy.getBasePair (i1+noLpShift+offset1 ,i2+noLpShift+offset2 ) );
322+ interaction.basePairs .push_back ( energy.getBasePair (i1+noLpShift,i2+noLpShift) );
316323 // reflect additional base pair
317324 bpIn--;
318325 }
319- // store next energy value to trace
320- curE = getSeedE ( k1, k2, bpIn-1 -noLpShift, u1max-u1, u2max-u2 );
321326 // reset for next trace step
322327 i1 = k1;
323328 i2 = k2;
0 commit comments