IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
SeedHandlerNoBulge.h
Go to the documentation of this file.
1
2#ifndef INTARNA_SEEDHANDLERNOBULGE_H_
3#define INTARNA_SEEDHANDLERNOBULGE_H_
4
8
9#include <boost/unordered_map.hpp>
10
11
12namespace IntaRNA {
13
21{
22
23protected:
24
26 typedef std::vector<E_type> StackingEnergyList;
27
29 typedef boost::unordered_map< Interaction::BasePair, E_type, Interaction::BasePair::Hash > SeedHash;
30
33
34
35public:
36
45 );
46
50 virtual ~SeedHandlerNoBulge();
51
60 virtual
61 size_t
62 fillSeed(const size_t i1, const size_t j1, const size_t i2, const size_t j2);
63
74 virtual
75 void
76 traceBackSeed( Interaction & interaction, const size_t i1, const size_t i2) const;
77
78
85 virtual
86 E_type
87 getSeedE( const size_t i1, const size_t i2 ) const;
88
97 virtual
98 bool
99 isSeedBound( const size_t i1, const size_t i2 ) const;
100
107 virtual
108 size_t
109 getSeedLength1( const size_t i1, const size_t i2 ) const;
110
117 virtual
118 size_t
119 getSeedLength2( const size_t i1, const size_t i2 ) const;
120
144 virtual
145 bool
146 updateToNextSeed( size_t & i1, size_t & i2
147 , const size_t i1min = 0, const size_t i1max = RnaSequence::lastPos
148 , const size_t i2min = 0, const size_t i2max = RnaSequence::lastPos
149 ) const;
150
151
152protected:
153
162 void
163 storeSeed( const size_t j1, const size_t j2, const StackingEnergyList & bpE );
164
165};
166
167
171
172
173inline
175 const InteractionEnergy & energy
176 , const SeedConstraint & seedConstraint
177 )
178 :
179 SeedHandler(energy,seedConstraint)
180 , seedForLeftEnd()
181{
182#if INTARNA_IN_DEBUG_MODE
183 if ( ! seedConstraint.getExplicitSeeds().empty()) {
184 LOG(WARNING) <<"explicit seeds definitions not supported by noBulge-seed handler (and thus ignored)";
185 }
186 if ( seedConstraint.getMaxUnpaired1() > 0 ) { throw std::runtime_error("SeedHandlerNoBulge() : seedConstraint.maxUnpaired1 > 0"); }
187 if ( seedConstraint.getMaxUnpaired2() > 0 ) { throw std::runtime_error("SeedHandlerNoBulge() : seedConstraint.maxUnpaired2 > 0"); }
188#endif
189}
190
192
193inline
198
200
201inline
202void
204traceBackSeed( Interaction & interaction
205 , const size_t i1
206 , const size_t i2
207 ) const
208{
209#if INTARNA_IN_DEBUG_MODE
210 if ( !( isSeedBound(i1,i2) ) ) throw std::runtime_error("SeedHandlerNoBulge::traceBackSeed(i1="+toString(i1)+",i2="+toString(i2)+") no seed known");
211#endif
212
213 // get number of base pairs within the seed
214 const size_t seedBps = getConstraint().getBasePairs();
215
216 // add seed base pairs
217 // but exclude left- and right-most bp
218 for (size_t k=1; (k+1)<seedBps; k++) {
219 interaction.basePairs.push_back( energy.getBasePair(i1+k,i2+k) );
220 }
221
222}
223
225
226inline
227E_type
229getSeedE( const size_t i1, const size_t i2 ) const
230{
231 // search for seed entry in hash
232 SeedHash::const_iterator seedData = seedForLeftEnd.find( SeedHash::key_type(i1,i2) );
233 // return according energy value
234 return seedData == seedForLeftEnd.end() ? E_INF : seedData->second;
235}
236
238
239inline
240bool
242isSeedBound( const size_t i1, const size_t i2 ) const
243{
244 // search for seed entry in hash
245 return seedForLeftEnd.find( SeedHash::key_type(i1,i2) ) != seedForLeftEnd.end();
246}
247
249
250inline
251size_t
253getSeedLength1( const size_t i1, const size_t i2 ) const
254{
255#if INTARNA_IN_DEBUG_MODE
256 if ( !( isSeedBound(i1,i2) ) ) throw std::runtime_error("SeedHandlerNoBulge::getSeedLength1(i1="+toString(i1)+",i2="+toString(i2)+") no seed known");
257#endif
258 // check if
259 return getConstraint().getBasePairs();
260}
261
263
264inline
265size_t
267getSeedLength2( const size_t i1, const size_t i2 ) const
268{
269#if INTARNA_IN_DEBUG_MODE
270 if ( !( isSeedBound(i1,i2) ) ) throw std::runtime_error("SeedHandlerNoBulge::getSeedLength2(i1="+toString(i1)+",i2="+toString(i2)+") no seed known");
271#endif
272 // check if
273 return getConstraint().getBasePairs();
274}
275
277
278inline
279void
281storeSeed( const size_t j1, const size_t j2, const StackingEnergyList & bpE )
282{
283 const size_t seedBP = seedConstraint.getBasePairs();
284 E_type seedEhybrid = 0;
285
286 // check if EDs of full seed are within boundaries
287 if ( energy.getED1(j1+1-seedBP, j1) < seedConstraint.getMaxED()
288 && energy.getED2(j2+1-seedBP, j2) < seedConstraint.getMaxED() )
289 {
290 // check seed boundaries if needed
292 && (energy.isGU(j1,j2) || energy.isGU(j1+1-seedBP,j2+1-seedBP)) )
293 {
294 return;
295 }
296
297 // compute seed energy
298 for(auto e=bpE.begin(); e!=bpE.end(); e++) { seedEhybrid += *e; } // (left) stacking energies
299 // check hybridization energy bound (incl E_init)
300 if ( (seedEhybrid+energy.getE_init()) >= seedConstraint.getMaxEhybrid()) {
301 return;
302 }
303
304 E_type seedEfull = energy.getE(j1+1-seedBP, j1, j2+1-seedBP, j2, seedEhybrid) + energy.getE_init(); // ED values etc.
305
306 // store seed hybridization energy if overall E is below to threshold
307 if( seedEfull < seedConstraint.getMaxE() ) {
308 seedForLeftEnd[ SeedHash::key_type(j1+1-seedBP,j2+1-seedBP) ] = seedEhybrid ;
309 }
310 }
311
312
313}
314
316
317} // namespace
318
319#endif /* SEEDHANDLERNOBULGE_H_ */
Definition InteractionEnergy.h:20
virtual E_type getE_init() const =0
virtual E_type getE(const size_t i1, const size_t j1, const size_t i2, const size_t j2, const E_type hybridE) const
Definition InteractionEnergy.h:957
virtual E_type getED1(const size_t i1, const size_t j1) const
Definition InteractionEnergy.h:838
virtual Interaction::BasePair getBasePair(const size_t i1, const size_t i2) const
Definition InteractionEnergy.h:808
virtual bool isGU(const size_t i1, const size_t i2) const
Definition InteractionEnergy.h:699
virtual E_type getED2(const size_t i2, const size_t j2) const
Definition InteractionEnergy.h:848
Definition Interaction.h:28
PairingVec basePairs
interacting indices
Definition Interaction.h:229
static const size_t lastPos
Definition RnaSequence.h:57
Definition SeedConstraint.h:20
E_type getMaxEhybrid() const
Definition SeedConstraint.h:334
size_t getMaxUnpaired2() const
Definition SeedConstraint.h:352
E_type getMaxE() const
Definition SeedConstraint.h:316
const std::string & getExplicitSeeds() const
Definition SeedConstraint.h:424
bool isGUendAllowed() const
Definition SeedConstraint.h:451
size_t getBasePairs() const
Definition SeedConstraint.h:307
E_type getMaxED() const
Definition SeedConstraint.h:325
size_t getMaxUnpaired1() const
Definition SeedConstraint.h:343
Definition SeedHandlerNoBulge.h:21
virtual size_t getSeedLength1(const size_t i1, const size_t i2) const
Definition SeedHandlerNoBulge.h:253
virtual bool updateToNextSeed(size_t &i1, size_t &i2, const size_t i1min=0, const size_t i1max=RnaSequence::lastPos, const size_t i2min=0, const size_t i2max=RnaSequence::lastPos) const
virtual ~SeedHandlerNoBulge()
Definition SeedHandlerNoBulge.h:194
std::vector< E_type > StackingEnergyList
container to store stacking energies of seed base pairs
Definition SeedHandlerNoBulge.h:26
SeedHandlerNoBulge(const InteractionEnergy &energy, const SeedConstraint &seedConstraint)
Definition SeedHandlerNoBulge.h:174
virtual size_t getSeedLength2(const size_t i1, const size_t i2) const
Definition SeedHandlerNoBulge.h:267
boost::unordered_map< Interaction::BasePair, E_type, Interaction::BasePair::Hash > SeedHash
container type for sparse seed information
Definition SeedHandlerNoBulge.h:29
void storeSeed(const size_t j1, const size_t j2, const StackingEnergyList &bpE)
Definition SeedHandlerNoBulge.h:281
virtual size_t fillSeed(const size_t i1, const size_t j1, const size_t i2, const size_t j2)
virtual bool isSeedBound(const size_t i1, const size_t i2) const
Definition SeedHandlerNoBulge.h:242
SeedHash seedForLeftEnd
container to store seeds' hybridization energies
Definition SeedHandlerNoBulge.h:32
virtual void traceBackSeed(Interaction &interaction, const size_t i1, const size_t i2) const
Definition SeedHandlerNoBulge.h:204
virtual E_type getSeedE(const size_t i1, const size_t i2) const
Definition SeedHandlerNoBulge.h:229
Definition SeedHandler.h:17
const SeedConstraint & seedConstraint
the seed constraint to be applied
Definition SeedHandler.h:202
const InteractionEnergy & energy
the used energy function
Definition SeedHandler.h:199
virtual const SeedConstraint & getConstraint() const
Definition SeedHandler.h:237
#define toString(x)
Definition general.h:60
Definition Accessibility.h:13
int E_type
type for energy values (energy + accessibility [ED]) (internally)
Definition general.h:78
const E_type E_INF
Definition general.h:79