Skip to content

Commit 1a82b34

Browse files
committed
+ support for length-corrected E optimization and output
1 parent f8e7f6e commit 1a82b34

6 files changed

Lines changed: 95 additions & 3 deletions

File tree

src/IntaRNA/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ libIntaRNA_a_HEADERS = \
4242
InteractionEnergyVrna.h \
4343
InteractionRange.h \
4444
NussinovHandler.h \
45+
ObjectiveHandler.h \
4546
OutputConstraint.h \
4647
OutputStreamHandler.h \
4748
OutputStreamHandlerSortedCsv.h \
@@ -107,6 +108,7 @@ libIntaRNA_a_SOURCES = \
107108
InteractionEnergyVrna.cpp \
108109
InteractionRange.cpp \
109110
NussinovHandler.cpp \
111+
ObjectiveHandler.cpp \
110112
OutputConstraint.cpp \
111113
OutputStreamHandlerSortedCsv.cpp \
112114
OutputHandler.cpp \

src/IntaRNA/ObjectiveHandler.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
3+
#include "IntaRNA/ObjectiveHandler.h"
4+
5+
namespace IntaRNA
6+
{
7+
8+
ObjectiveHandler::ObjectiveHandler()
9+
{
10+
}
11+
12+
ObjectiveHandler::~ObjectiveHandler()
13+
{
14+
}
15+
16+
E_type
17+
ObjectiveHandler::
18+
getLcE( const Interaction & i, const InteractionEnergy & energy )
19+
{
20+
const size_t curLength = std::max(
21+
( 1 + i.basePairs.rbegin()->first - i.basePairs.begin()->first )
22+
, ( 1 + i.basePairs.begin()->second - i.basePairs.rbegin()->second )
23+
);
24+
25+
return getLcE( curLength, i.energy, energy);
26+
}
27+
28+
E_type
29+
ObjectiveHandler::
30+
getLcE( const size_t & curLength, const E_type & fullE, const InteractionEnergy & energy )
31+
{
32+
// const size_t maxLength = std::max( std::min(energy.getAccessibility1().getSequence().size(), energy.getAccessibility1().getMaxLength())
33+
// , std::min(energy.getAccessibility2().getSequence().size(), energy.getAccessibility2().getMaxLength()) );
34+
LOG_IF(curLength<1, DEBUG) <<"curLength < 1";
35+
return (E_type)( (double)(fullE) / std::log2(1+(double)curLength) );
36+
// return (E_type)( (double)(fullE) / std::log(5+(double)curLength) );
37+
// return (E_type)( (double)(fullE) / std::log(2.0*(double)curLength) );
38+
// return (fullE) / (E_type)curLength;
39+
// return (fullE * maxLength) / curLength;
40+
}
41+
42+
43+
44+
} /* namespace IntaRNA */

src/IntaRNA/ObjectiveHandler.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef INTARNA_OBJECTIVEHANDLER_H_
2+
#define INTARNA_OBJECTIVEHANDLER_H_
3+
4+
#include "IntaRNA/Interaction.h"
5+
#include "IntaRNA/InteractionEnergy.h"
6+
7+
namespace IntaRNA
8+
{
9+
10+
/**
11+
* Defines the optimization objective of Predictor instances
12+
*/
13+
class ObjectiveHandler
14+
{
15+
public:
16+
ObjectiveHandler();
17+
virtual ~ObjectiveHandler();
18+
19+
20+
static
21+
E_type
22+
getLcE( const Interaction & i, const InteractionEnergy & energy );
23+
24+
static
25+
E_type
26+
getLcE( const size_t & curLength, const E_type & fullE, const InteractionEnergy & energy );
27+
28+
};
29+
30+
} /* namespace IntaRNA */
31+
32+
#endif /* INTARNA_OBJECTIVEHANDLER_H_ */

src/IntaRNA/OutputHandlerCsv.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include "IntaRNA/OutputHandlerCsv.h"
3+
#include "IntaRNA/ObjectiveHandler.h"
34

45
#if INTARNA_MULITHREADING
56
#include <omp.h>
@@ -22,7 +23,7 @@ const std::string OutputHandlerCsv::notAvailable = "NAN";
2223
const OutputHandlerCsv::ColTypeList OutputHandlerCsv::colTypeNumericSort(
2324
OutputHandlerCsv::string2list(
2425
"start1,end1,start2,end2"
25-
",E,ED1,ED2,Pu1,Pu2,E_init,E_loops,E_dangleL,E_dangleR,E_endL,E_endR,E_hybrid,E_norm,E_hybridNorm,E_add"
26+
",E,ED1,ED2,Pu1,Pu2,E_init,E_loops,E_dangleL,E_dangleR,E_endL,E_endR,E_hybrid,E_norm,E_hybridNorm,E_add,lcE"
2627
",seedStart1,seedEnd1,seedStart2,seedEnd2,seedE,seedED1,seedED2,seedPu1,seedPu2"
2728
",Eall,Zall,P_E"
2829
));
@@ -242,6 +243,10 @@ add( const Interaction & i, const OutputConstraint & outConstraint )
242243
outTmp <<E_2_Ekcal(contr.energyAdd);
243244
break;
244245

246+
case lcE:
247+
outTmp <<E_2_Ekcal(ObjectiveHandler::getLcE(i,energy));
248+
break;
249+
245250
case seedStart1:
246251
if (i.seed == NULL) {
247252
outTmp <<notAvailable;

src/IntaRNA/OutputHandlerCsv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class OutputHandlerCsv : public OutputHandler
6161
E_norm, //!< length normalized energy = E/ln(length(seq1)*length(seq2))
6262
E_hybridNorm, //!< length normalized energy of hybridization only = E_hybrid / ln(length(seq1)*length(seq2))
6363
E_add, //!< user provided energy shift
64+
lcE, //!< length normalized interaction energy = E*maxLength/curMaxLength
6465
seedStart1, //!< start index of the seed in seq1
6566
seedEnd1, //!< end index of the seed in seq1
6667
seedStart2, //!< start index of the seed in seq2
@@ -134,6 +135,7 @@ class OutputHandlerCsv : public OutputHandler
134135
colType2string[E_norm] = "E_norm";
135136
colType2string[E_hybridNorm] = "E_hybridNorm";
136137
colType2string[E_add] = "E_add";
138+
colType2string[lcE] = "lcE";
137139
colType2string[seedStart1] = "seedStart1";
138140
colType2string[seedEnd1] = "seedEnd1";
139141
colType2string[seedStart2] = "seedStart2";

src/IntaRNA/PredictorMfe.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include "IntaRNA/PredictorMfe.h"
3+
#include "IntaRNA/ObjectiveHandler.h"
34

45
#include <iostream>
56
#include <algorithm>
@@ -114,7 +115,10 @@ updateOptima( const size_t i1, const size_t j1
114115

115116

116117
// check if we have to care about insertion (curE <= worst E in list)
117-
if (curE > mfeInteractions.rbegin()->energy ) {
118+
// if (curE > mfeInteractions.rbegin()->energy ) {
119+
if (ObjectiveHandler::getLcE( std::max(1+j1-i1,1+j2-i2), curE, energy)
120+
> ObjectiveHandler::getLcE( *(mfeInteractions.rbegin()), energy) )
121+
{
118122
return;
119123
}
120124

@@ -136,7 +140,10 @@ updateOptima( const size_t i1, const size_t j1
136140
} else {
137141

138142
// check for insertion position
139-
InteractionList::iterator insertPos = std::find_if_not( mfeInteractions.begin(), mfeInteractions.end(), [&](Interaction & i){return i < tmp;});
143+
InteractionList::iterator insertPos = std::find_if_not( mfeInteractions.begin(), mfeInteractions.end(), [&](Interaction & i){
144+
return ObjectiveHandler::getLcE(i,energy) < ObjectiveHandler::getLcE(tmp,energy);
145+
// return i < tmp;
146+
});
140147

141148
if ( insertPos != mfeInteractions.end() && !( tmp == *insertPos )) {
142149

0 commit comments

Comments
 (0)