IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
InteractionEnergy.h
Go to the documentation of this file.
1
2#ifndef INTARNA_INTERACTIONENERGY_H_
3#define INTARNA_INTERACTIONENERGY_H_
4
5
6#include "IntaRNA/general.h"
10
11namespace IntaRNA {
12
21
22public:
23
36
61
62
89 , const size_t maxInternalLoopSize1
90 , const size_t maxInternalLoopSize2
91 , const E_type energyAdd
92 , const bool energyWithDangle
93 , const bool internalLoopGU
94 );
95
99 virtual ~InteractionEnergy();
100
101
118 virtual
119 E_type
120 getE( const size_t i1, const size_t j1
121 , const size_t i2, const size_t j2
122 , const E_type hybridE ) const;
123
132 virtual
133 E_type
134 getE( const Z_type Z ) const;
135
143 virtual
145 getE_contributions( const Interaction & interaction ) const;
146
154 virtual
155 bool
156 areComplementary( const size_t i1, const size_t i2 ) const;
157
164 virtual
165 bool
166 isGU( const size_t i1, const size_t i2 ) const;
167
172 virtual
173 size_t
174 size1() const;
175
180 virtual
181 size_t
182 size2() const;
183
191 virtual
192 E_type
193 getED1( const size_t i1, const size_t j1 ) const;
194
203 virtual
204 E_type
205 getED2( const size_t i2, const size_t j2 ) const;
206
212 virtual
213 bool
214 isAccessible1( const size_t i ) const;
215
221 virtual
222 bool
223 isAccessible2( const size_t i ) const;
224
225
242 virtual
243 E_type
244 getE_multi( const size_t i1, const size_t j1
245 , const size_t i2, const size_t j2
246 , const ES_multi_mode ES_mode ) const;
247
261 virtual
262 E_type
263 getES1( const size_t i1, const size_t j1 ) const = 0;
264
278 virtual
279 E_type
280 getES2( const size_t i2, const size_t j2 ) const = 0;
281
291 virtual
292 E_type
293 getE_multiUnpaired( const size_t numUnpaired ) const = 0;
294
307 virtual
308 E_type
309 getE_multiHelix( const size_t j1, const size_t j2 ) const = 0;
310
318 virtual
319 E_type
320 getE_multiClosing() const = 0;
321
327 virtual
328 E_type
329 getE_init( ) const = 0;
330
348 virtual
349 E_type
350 getE_interLeft( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const = 0;
351
352
363 virtual
364 E_type
365 getE_danglingLeft( const size_t i1, const size_t i2 ) const = 0;
366
367
378 virtual
379 E_type
380 getE_danglingRight( const size_t j1, const size_t j2 ) const = 0;
381
391 virtual
392 E_type
393 getE_endLeft( const size_t i1, const size_t i2 ) const = 0;
394
404 virtual
405 E_type
406 getE_endRight( const size_t j1, const size_t j2 ) const = 0;
407
420 virtual
421 Z_type
422 getPr_danglingLeft( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const;
423
436 virtual
437 Z_type
438 getPr_danglingRight( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const;
439
445 virtual
446 const Accessibility &
447 getAccessibility1() const;
448
454 virtual
456 getAccessibility2() const;
457
463 const size_t getMaxInternalLoopSize1() const {
465 }
466
472 const size_t getMaxInternalLoopSize2() const {
474 }
475
479 virtual
480 Z_type
481 getRT() const = 0;
482
488 virtual
489 Z_type
490 getBoltzmannWeight( const E_type energy ) const ;
491
497 virtual
498 Z_type
499 getBoltzmannWeight( const Z_type energy ) const ;
500
501
508 virtual
510 getBasePair( const size_t i1, const size_t i2 ) const;
511
512
517 virtual
518 size_t
519 getIndex1( const Interaction::BasePair & bp ) const;
520
521
526 virtual
527 size_t
528 getIndex2( const Interaction::BasePair & bp ) const;
529
535 virtual
536 E_type
537 getEnergyAdd() const;
538
555 virtual
556 bool
557 isValidInternalLoop( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const;
558
564 bool
566
572 virtual
573 E_type
574 getEall1() const = 0;
575
581 virtual
582 E_type
583 getEall2() const = 0;
584
585protected:
586
589
592
596
600
603
606
608 const bool internalLoopGU;
609
624 static
625 bool
626 isAllowedLoopRegion( const RnaSequence& seq, const size_t i, const size_t j, const size_t maxInternalLoopSize );
627
628};
629
630
631
632
636
637
638inline
640 , const ReverseAccessibility & accS2
641 , const size_t maxInternalLoopSize1
642 , const size_t maxInternalLoopSize2
643 , const E_type energyAdd
644 , const bool energyWithDangles
645 , const bool internalLoopGU
646 )
647 :
648 accS1(accS1)
649 , accS2(accS2)
650 , maxInternalLoopSize1(maxInternalLoopSize1)
651 , maxInternalLoopSize2(maxInternalLoopSize2)
652 , energyAdd(energyAdd)
653 , energyWithDangles(energyWithDangles)
654 , internalLoopGU(internalLoopGU)
655{
656}
657
659
660inline
664
666
667inline
668bool
670isAllowedLoopRegion( const RnaSequence& seq, const size_t i, const size_t j, const size_t maxInternalLoopSize )
671{
672 // ensure index and loop size validity
673 return i < seq.size()
674 && j < seq.size()
675 && seq.asString().at(i) != 'N'
676 && seq.asString().at(j) != 'N'
677 && i <= j
678 && (j-i) <= (1+maxInternalLoopSize);
679
680}
681
683
684inline
685bool
687areComplementary( const size_t i1, const size_t i2 ) const
688{
690 && isAccessible1(i1)
691 && isAccessible2(i2);
692}
693
695
696inline
697bool
699isGU( const size_t i1, const size_t i2 ) const
700{
702}
703
705
706inline
707size_t
709size1() const
710{
712}
713
715
716inline
717size_t
719size2() const
720{
722}
723
725
726inline
727bool
729isValidInternalLoop( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const
730{
731 return
732 (j1-i1>0 && j2-i2>0)
733 && areComplementary( i1, i2)
734 && areComplementary( j1, j2)
737 && ( internalLoopGU || (i1+1==j1 && i2+1==j2) || (!isGU(i1,i2) && !isGU(j1,j2)) ) // GU-allowed or stacking or no GU
738 ;
739}
740
742
743inline
744bool
750
752
753inline
754const Accessibility &
756getAccessibility1() const
757{
758 return accS1;
759}
760
762
763inline
766getAccessibility2() const
767{
768 return accS2;
769}
770
772
773inline
774E_type
776getEnergyAdd() const
777{
778 return energyAdd;
779}
780
782
783inline
784Z_type
786getBoltzmannWeight( const E_type e ) const
787{
788 // TODO can be optimized when using exp-energies from VRNA
789 return Z_exp( - E_2_Z(e) / getRT() );
790}
791
793
794inline
795Z_type
797getBoltzmannWeight( const Z_type e ) const
798{
799 // TODO can be optimized when using exp-energies from VRNA
800 return Z_exp( - e / getRT() );
801}
802
804
805inline
808getBasePair( const size_t i1, const size_t i2 ) const
809{
810 return Interaction::BasePair( i1, getAccessibility2().getReversedIndex(i2) );
811}
812
814
815inline
816size_t
818getIndex1( const Interaction::BasePair & bp ) const
819{
820 return bp.first;
821}
822
824
825inline
826size_t
832
834
835inline
836E_type
838getED1( const size_t i1, const size_t j1 ) const
839{
840 return getAccessibility1().getED( i1, j1 );
841}
842
844
845inline
846E_type
848getED2( const size_t i2, const size_t j2 ) const
849{
850 return getAccessibility2().getED( i2, j2 );
851}
852
854
855inline
856bool
858isAccessible1( const size_t i ) const
859{
860 return
861 (!getAccessibility1().getSequence().isAmbiguous(i))
863 ;
864}
865
867
868inline
869bool
871isAccessible2( const size_t i ) const
872{
873 return
874 (!getAccessibility2().getSequence().isAmbiguous(i))
876}
877
879
880inline
881Z_type
883getPr_danglingLeft( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const
884{
885 // initial probabilities
886 Z_type probDangle1 = 1.0, probDangle2 = 1.0;
887
888 // if dangle1 possible
889 if (i1>0) {
890 // Pr( i1-1 is unpaired | i1..j1 unpaired )
891 probDangle1 =
892 std::max( (Z_type)0.0
893 , std::min( (Z_type)1.0
894 , getBoltzmannWeight( getED1(i1-1,j1)-getED1(i1,j1) )
895 )
896 )
897 ;
898 }
899 // if dangle2 possible
900 if (i2>0) {
901 // Pr( i2-1 is unpaired | i2..j2 unpaired )
902 probDangle2 =
903 std::max( (Z_type)0.0
904 , std::min( (Z_type)1.0
905 , getBoltzmannWeight( getED2(i2-1,j2)-getED2(i2,j2) )
906 )
907 )
908 ;
909 }
910
911 // get overall probability
912 return probDangle1 * probDangle2;
913}
914
916
917inline
918Z_type
920getPr_danglingRight( const size_t i1, const size_t j1, const size_t i2, const size_t j2 ) const
921{
922 // initial probabilities
923 Z_type probDangle1 = 1.0, probDangle2 = 1.0;
924
925 // if dangle1 possible
926 if (j1+1<size1()) {
927 // Pr( j1+1 is unpaired | i1..j1 unpaired )
928 probDangle1 =
929 std::max( (Z_type)0.0
930 , std::min( (Z_type)1.0
931 , getBoltzmannWeight( getED1(i1,j1+1)-getED1(i1,j1) )
932 )
933 )
934 ;
935 }
936 // if dangle2 possible
937 if (j2+1<size2()) {
938 // Pr( j2+1 is unpaired | i2..j2 unpaired )
939 probDangle2 =
940 std::max( (Z_type)0.0
941 , std::min( (Z_type)1.0
942 , getBoltzmannWeight( getED2(i2,j2+1)-getED2(i2,j2) )
943 )
944 )
945 ;
946 }
947
948 // get overall probability
949 return probDangle1 * probDangle2;
950}
951
953
954inline
955E_type
957getE( const size_t i1, const size_t j1
958 , const size_t i2, const size_t j2
959 , const E_type hybridE ) const
960{
961 // check if hybridization energy and EDs are not infinite
962 if ( E_isNotINF(hybridE)
964 && (getED2( i2, j2 ) < Accessibility::ED_UPPER_BOUND))
965 {
966 // compute overall interaction energy
967 return hybridE
968 // accessibility penalty
969 + getED1( i1, j1 )
970 + getED2( i2, j2 )
971 // dangling end penalty
972 // weighted by the probability that ends are unpaired
973 + (energyWithDangles ? Z_2_E(E_2_Z(getE_danglingLeft( i1, i2 ))*getPr_danglingLeft(i1,j1,i2,j2)) : E_type(0))
975 // helix closure penalty
976 + getE_endLeft( i1, i2 )
977 + getE_endRight( j1, j2 )
978 + getEnergyAdd()
979 ;
980 } else {
981 // hybridE is infinite, thus overall energy is infinity as well
982 return E_INF;
983 }
984}
985
987
988inline
989E_type
991getE( const Z_type Z ) const
992{
993 // convert partition function to ensemble energy
994 // convert to E_type
995 return Z_2_E( - getRT() * Z_log( Z ) );
996}
997
999
1000inline
1001E_type
1003getE_multi( const size_t i1, const size_t j1
1004 , const size_t i2, const size_t j2
1005 , const ES_multi_mode ES_mode ) const
1006{
1007#if INTARNA_IN_DEBUG_MODE
1008 if (i1 >= j1 ) throw std::runtime_error("InteractionEnergy::getE_multi() : i1>=j1 : "+toString(i1)+" "+toString(j1));
1009 if (i2 >= j2 ) throw std::runtime_error("InteractionEnergy::getE_multi() : i2>=j2 : "+toString(i2)+" "+toString(j2));
1010 if (j1 >= size1()) throw std::runtime_error("InteractionEnergy::getE_multi() : j1>=size1() : "+toString(j1)+" "+toString(size1()));
1011 if (j2 >= size2()) throw std::runtime_error("InteractionEnergy::getE_multi() : j2>=size2() : "+toString(j2)+" "+toString(size2()));
1012 if (! areComplementary(i1,i2)) throw std::runtime_error("InteractionEnergy::getE_multi() : not complementary : "+toString(i1)+" "+toString(i2));
1013 if (! areComplementary(j1,j2)) throw std::runtime_error("InteractionEnergy::getE_multi() : not complementary : "+toString(j1)+" "+toString(j2));
1014#endif
1015
1016 return
1017 // intramolecular structure contributions
1018 (ES_mode != ES_multi_2only ? getES1(i1,j1) : 0)
1019 + (ES_mode != ES_multi_1only ? getES2(i2,j2) : 0)
1020 // dangling end treatments of helix ends
1023 // helix closure penalties
1024 + getE_endRight(i1,i2)
1025 + getE_endLeft(j1,j2)
1026 // multiloop unpaired contributions
1028 (ES_mode == ES_multi_2only ? j1-i1-1 : 0 )
1029 + (ES_mode == ES_multi_1only ? j2-i2-1 : 0 )
1030 )
1031 // multiloop helix contribution (right side interaction site)
1032 + getE_multiHelix( j1, j2 )
1033 // multiloop closure
1035 ;
1036}
1037
1038
1040
1041
1042} // namespace
1043
1044
1045#endif /* INTERACTIONENERGY_H_ */
bool isAccessible(const size_t i) const
Definition AccessibilityConstraint.h:379
Definition Accessibility.h:25
static const E_type ED_UPPER_BOUND
upper bound for all ED return values
Definition Accessibility.h:30
virtual const AccessibilityConstraint & getAccConstraint() const
Definition Accessibility.h:279
virtual const RnaSequence & getSequence() const
Definition Accessibility.h:259
virtual E_type getED(const size_t from, const size_t to) const =0
Definition InteractionEnergy.h:20
virtual E_type getE_multiClosing() const =0
const ReverseAccessibility & accS2
accessibility values for sequence S2 (reversed index order)
Definition InteractionEnergy.h:591
virtual E_type getEnergyAdd() const
Definition InteractionEnergy.h:776
virtual E_type getE_endLeft(const size_t i1, const size_t i2) const =0
const E_type energyAdd
user defined shift of the energy spectrum
Definition InteractionEnergy.h:602
virtual EnergyContributions getE_contributions(const Interaction &interaction) const
const size_t maxInternalLoopSize1
Definition InteractionEnergy.h:595
virtual E_type getE_multi(const size_t i1, const size_t j1, const size_t i2, const size_t j2, const ES_multi_mode ES_mode) const
Definition InteractionEnergy.h:1003
virtual size_t getIndex2(const Interaction::BasePair &bp) const
Definition InteractionEnergy.h:828
const Accessibility & accS1
accessibility values for sequence S1
Definition InteractionEnergy.h:588
virtual E_type getE_multiUnpaired(const size_t numUnpaired) const =0
virtual Z_type getRT() const =0
virtual E_type getEall2() const =0
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 Z_type getPr_danglingRight(const size_t i1, const size_t j1, const size_t i2, const size_t j2) const
Definition InteractionEnergy.h:920
virtual size_t getIndex1(const Interaction::BasePair &bp) const
Definition InteractionEnergy.h:818
const size_t getMaxInternalLoopSize2() const
Definition InteractionEnergy.h:472
const bool energyWithDangles
whether or not dangling end energy contributions are to be added
Definition InteractionEnergy.h:605
virtual bool isAccessible2(const size_t i) const
Definition InteractionEnergy.h:871
virtual E_type getE_interLeft(const size_t i1, const size_t j1, const size_t i2, const size_t j2) const =0
virtual bool isAccessible1(const size_t i) const
Definition InteractionEnergy.h:858
virtual E_type getE_danglingLeft(const size_t i1, const size_t i2) const =0
virtual Z_type getBoltzmannWeight(const E_type energy) const
Definition InteractionEnergy.h:786
InteractionEnergy(const Accessibility &accS1, const ReverseAccessibility &accS2, const size_t maxInternalLoopSize1, const size_t maxInternalLoopSize2, const E_type energyAdd, const bool energyWithDangle, const bool internalLoopGU)
Definition InteractionEnergy.h:639
virtual const ReverseAccessibility & getAccessibility2() const
Definition InteractionEnergy.h:766
virtual bool areComplementary(const size_t i1, const size_t i2) const
Definition InteractionEnergy.h:687
virtual E_type getE_endRight(const size_t j1, const size_t j2) const =0
virtual E_type getE_multiHelix(const size_t j1, const size_t j2) const =0
const size_t getMaxInternalLoopSize1() const
Definition InteractionEnergy.h:463
virtual E_type getES2(const size_t i2, const size_t j2) const =0
const bool internalLoopGU
whether or not GU base pairs allowed in internal loops
Definition InteractionEnergy.h:608
virtual const Accessibility & getAccessibility1() const
Definition InteractionEnergy.h:756
static bool isAllowedLoopRegion(const RnaSequence &seq, const size_t i, const size_t j, const size_t maxInternalLoopSize)
Definition InteractionEnergy.h:670
virtual ~InteractionEnergy()
Definition InteractionEnergy.h:661
virtual bool isValidInternalLoop(const size_t i1, const size_t j1, const size_t i2, const size_t j2) const
Definition InteractionEnergy.h:729
virtual size_t size1() const
Definition InteractionEnergy.h:709
virtual E_type getED1(const size_t i1, const size_t j1) const
Definition InteractionEnergy.h:838
bool isInternalLoopGUallowed() const
Definition InteractionEnergy.h:746
virtual E_type getEall1() const =0
virtual Interaction::BasePair getBasePair(const size_t i1, const size_t i2) const
Definition InteractionEnergy.h:808
virtual E_type getES1(const size_t i1, const size_t j1) const =0
const size_t maxInternalLoopSize2
Definition InteractionEnergy.h:599
virtual Z_type getPr_danglingLeft(const size_t i1, const size_t j1, const size_t i2, const size_t j2) const
Definition InteractionEnergy.h:883
virtual size_t size2() const
Definition InteractionEnergy.h:719
virtual bool isGU(const size_t i1, const size_t i2) const
Definition InteractionEnergy.h:699
virtual E_type getE_danglingRight(const size_t j1, const size_t j2) const =0
ES_multi_mode
Definition InteractionEnergy.h:28
@ ES_multi_both
incorporate ES for both sequences
Definition InteractionEnergy.h:34
@ ES_multi_2only
incorporate ES for seq2 only
Definition InteractionEnergy.h:32
@ ES_multi_1only
incorporate ES for seq1 only
Definition InteractionEnergy.h:30
virtual E_type getED2(const size_t i2, const size_t j2) const
Definition InteractionEnergy.h:848
type of a base pair index encoding
Definition Interaction.h:33
size_t first
index in first sequence
Definition Interaction.h:37
size_t second
index in second sequence
Definition Interaction.h:38
Definition Interaction.h:28
Definition ReverseAccessibility.h:13
virtual E_type getED(const size_t from, const size_t to) const
Definition ReverseAccessibility.h:172
virtual const RnaSequence & getSequence() const
Definition ReverseAccessibility.h:147
size_t getReversedIndex(const size_t i) const
Definition ReverseAccessibility.h:195
virtual const AccessibilityConstraint & getAccConstraint() const
Definition ReverseAccessibility.h:159
Definition RnaSequence.h:29
static bool isGU(const RnaSequence &s1, const RnaSequence &s2, const size_t p1, const size_t p2)
Definition RnaSequence.h:610
const String_type & asString() const
Definition RnaSequence.h:442
static bool areComplementary(const RnaSequence &s1, const RnaSequence &s2, const size_t p1, const size_t p2)
Definition RnaSequence.h:587
size_t size() const
Definition RnaSequence.h:366
#define E_isNotINF(e)
check if a given energy is NOT set to E_INF
Definition general.h:137
#define E_2_Z(e)
convert E_type to Z_type
Definition general.h:119
#define toString(x)
Definition general.h:60
#define Z_2_E(e)
convert Z_type to E_type
Definition general.h:125
#define Z_exp
Definition general.h:90
#define Z_log
Definition general.h:89
Definition Accessibility.h:13
int E_type
type for energy values (energy + accessibility [ED]) (internally)
Definition general.h:78
double Z_type
type for probabilities, RT and Boltzmann values
Definition general.h:88
const E_type E_INF
Definition general.h:79
Definition InteractionEnergy.h:40
E_type dangleRight
the energy for the dangling ends at the right end of the interaction
Definition InteractionEnergy.h:53
E_type ED2
the energy penalty for making the interaction site accessible in seq2
Definition InteractionEnergy.h:49
E_type energyAdd
the energy shift requested by the user
Definition InteractionEnergy.h:59
E_type ED1
the energy penalty for making the interaction site accessible in seq1
Definition InteractionEnergy.h:47
E_type endRight
the energy penalty for the right end of the interaction
Definition InteractionEnergy.h:57
E_type loops
the energy for all intermolecular loops
Definition InteractionEnergy.h:43
E_type init
the energy penalty for initiating the interaction
Definition InteractionEnergy.h:45
E_type endLeft
the energy penalty for the left end of the interaction
Definition InteractionEnergy.h:55
E_type dangleLeft
the energy for the dangling ends at the left end of the interaction
Definition InteractionEnergy.h:51