Skip to content

Commit d8979a6

Browse files
committed
BUGFIX : dangling-end probability computation using maxLength+1 ED values
1 parent d9db6ca commit d8979a6

12 files changed

Lines changed: 39 additions & 18 deletions

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- BUGFIX : target accessibility limits and seed-free outMinPu filtering
2323
- BUGFIX : accessibility range splitting and intramolecular ensemble energies
2424
- BUGFIX : interaction assignment, seed comparison and output handling
25+
- BUGFIX : dangling-end probability computation using maxLength+1 ED values
2526
- add exhaustive interaction and seed oracles for short-sequence tests
2627

2728
- reduced memory use for exact non-seed ensemble prediction without trackers
@@ -44,6 +45,12 @@
4445
* src/IntaRNA/Makefile.am :
4546
* src/bin/Makefile.am :
4647
* undo some diagnostic flags to allow compilation on test system
48+
* IntaRNA/Accessibility* :
49+
* constructors: generate/read/keep data for maxLength+1 to allow for
50+
dangling-end probability computation
51+
* tests/AccessibilityFromStream_test.cpp :
52+
* tests/AccessibilityVrna_test.cpp :
53+
+ check for maxLength+1 ED values
4754

4855
260919 Alexander Mitrofanov
4956
* IntaRNA/PredictorMfe2d* :

src/IntaRNA/Accessibility.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ operator<<(std::ostream& out, const Accessibility& acc)
3030
// print first (without delimiter)
3131
out <<acc.getED(i, i);
3232
// print remaining with delimiter
33-
for (size_t j=i+1; j<std::min(acc.getMaxLength()+i,acc.getSequence().size());j++) {
33+
for (size_t j=i+1; j<std::min(acc.getMaxLength()+1+i,acc.getSequence().size());j++) { // "getMaxLength()+1" to allow for dangling-end probability computation
3434
out <<delimiter <<(acc.getED(i, j)>=0?" ":"") <<acc.getED(i, j);
3535
}
3636
out <<"\n";
@@ -67,7 +67,7 @@ writeRNAplfold_text( std::ostream& out, const Z_type RT, const bool writeProbs )
6767

6868
// length information
6969
out <<" #i$ l=";
70-
for (size_t l=1; l<=std::min(getSequence().size(),getMaxLength()); l++) {
70+
for (size_t l=1; l<=std::min(getSequence().size(),getMaxLength()+1); l++) { // "getMaxLength()+1" to allow for dangling-end probability computation
7171
out <<l <<'\t';
7272
}
7373
out <<'\n';
@@ -76,7 +76,7 @@ writeRNAplfold_text( std::ostream& out, const Z_type RT, const bool writeProbs )
7676
for (size_t j=0; j<getSequence().size(); j++) {
7777
// print end of window = j
7878
out <<(j+1) <<'\t';
79-
size_t maxL = std::min(j+1,getMaxLength());
79+
size_t maxL = std::min(j+1,std::min(getSequence().size(),getMaxLength()+1)); // "getMaxLength()+1" to allow for dangling-end probability computation
8080
// for each (increasing) window length, print value
8181
for ( size_t l = 1; l <= maxL; l++ ) {
8282
if (writeProbs) {
@@ -100,7 +100,7 @@ writeRNAplfold_text( std::ostream& out, const Z_type RT, const bool writeProbs )
100100
}
101101
}
102102
// print NA for remaining entries
103-
for ( size_t l = maxL+1; l<=getMaxLength(); l++ ) {
103+
for ( size_t l = maxL+1; l<=std::min(getSequence().size(),getMaxLength()+1); l++ ) { // "getMaxLength()+1" to allow for dangling-end probability computation
104104
out <<"NA\t";
105105
}
106106
// line break

src/IntaRNA/AccessibilityBasePair.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ AccessibilityBasePair::~AccessibilityBasePair()
7070
E_type
7171
AccessibilityBasePair::getED( const size_t from, const size_t to ) const
7272
{
73-
if (from > to || to < 0 || from >= seq.size()) {
74-
throw std::runtime_error( "AccessibilityBasePair::getED("+toString(from)+","+toString(to)
75-
+") : Arguments must satisfy 0 <= from <= to < seq.length" );
76-
}
73+
checkIndices(from,to);
7774
return logPu(from, to);
7875
};
7976

src/IntaRNA/AccessibilityDisabled.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AccessibilityDisabled: public Accessibility {
4646
* @param from the start index of the regions (from <= to)
4747
* @param to the end index of the regions (to <= seq.length())
4848
*
49-
* @return 0 if (j-1+1) <= maxLength or ED_UPPER_BOUND otherwise
49+
* @return 0 if (j-i+1) <= maxLength or ED_UPPER_BOUND otherwise
5050
*/
5151
virtual
5252
E_type
@@ -88,7 +88,7 @@ getED( const size_t from, const size_t to ) const
8888
// input check
8989
checkIndices(from,to);
9090

91-
if ((to-from+1) <= getMaxLength()) {
91+
if ((to-from+1) <= getMaxLength()+1) { // "getMaxLength()+1" to allow for dangling-end probability computation
9292
// check for constrained end positions
9393
if (!getAccConstraint().isAccessible(from) || !getAccConstraint().isAccessible(to)) {
9494
// end position blocked --> omit accessibility

src/IntaRNA/AccessibilityFromStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ getED( const size_t from, const size_t to ) const
139139
// input range check
140140
checkIndices(from,to);
141141

142-
if ((to-from+1) <= getMaxLength()) {
142+
if ((to-from+1) <= getMaxLength()+1) { // "getMaxLength()+1" to allow for dangling-end probability computation
143143
// check for constrained end positions
144144
if (!getAccConstraint().isAccessible(from) || !getAccConstraint().isAccessible(to)) {
145145
// end position blocked --> omit accessibility

src/IntaRNA/AccessibilityVrna.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ AccessibilityVrna::AccessibilityVrna(
8383
)
8484
:
8585
Accessibility( seq, maxLength, accConstraint ),
86-
edValues( getSequence().size(), getSequence().size(), 0, getMaxLength() )
86+
edValues( getSequence().size(), getSequence().size(),
87+
0, std::min(getSequence().size(),getMaxLength()+1) ) // +1 to allow for dangling-end probability computation
8788
{
8889
// if sequence shows minimal length
8990
if (seq.size() > 4) {
@@ -134,7 +135,7 @@ callbackForStorage(FLT_OR_DBL *pr,
134135
// copy unpaired data for all available interval lengths
135136
// but ensure interval does not contain blocked positions
136137
const bool rightEndBlocked = accConstr.isMarkedBlocked(j-1);
137-
for (int l = std::min(j,std::min(pr_size,std::min(max,(int)storageRT.first->getMaxLength()))); l>=1; l--) {
138+
for (int l = std::min(j,std::min(pr_size,std::min(max,(int)storageRT.first->getMaxLength()+1))); l>=1; l--) { // "getMaxLength()+1" to allow for dangling-end probability computation
138139
// get unpaired probability
139140
FLT_OR_DBL prob_unpaired = pr[l];
140141
// TODO: check for [0,1] range and correct if needed (print WARNING)

src/IntaRNA/AccessibilityVrna.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ getED( const size_t from, const size_t to ) const
149149
// input range check
150150
checkIndices(from,to);
151151

152-
if ((to-from+1) <= getMaxLength()) {
152+
if ((to-from+1) <= getMaxLength() +1 ) { // "getMaxLength()+1" to allow for dangling-end probability computation
153153
// check for constrained end positions
154154
if (!getAccConstraint().isAccessible(from) || !getAccConstraint().isAccessible(to)) {
155155
// end position blocked --> omit accessibility

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/*.log
22
/*.trs
3+
runApiTests

tests/AccessibilityFromStream_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ TEST_CASE( "AccessibilityFromStream", "[AccessibilityFromStream]" ) {
6767
// std::cerr <<"orig data:\n" <<accString;
6868
// std::cerr <<"ED data:\n" <<acc;
6969

70+
// check max length
71+
REQUIRE( acc.getMaxLength() == 9 );
72+
7073
// check elements
71-
REQUIRE( acc.getED(29, 29) == 0 );
72-
REQUIRE( acc.getED(21, 29) == 690 );
74+
REQUIRE( acc.getED(29, 29) == 0 ); // length 1 (0.9980056 -> -log(0.9980056)*100 = 0.19944 -> 0)
75+
REQUIRE( acc.getED(21, 29) == 690 ); // length 9 (0.001002708 -> -log(0.001002708)*100 = 690.03 -> 690)
76+
REQUIRE( acc.getED(20, 29) == 732 ); // check for length exceeding maxLength+1 used in dangling-end probability computation
7377
// // old checks not working for integer-based ED type
7478
// REQUIRE( std::exp( - acc.getED(29, 29) ) > 0.998 );
7579
// REQUIRE( std::exp( - acc.getED(29, 29) ) < 0.999 );

tests/AccessibilityVrna_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ TEST_CASE("AccessibilityVrna", "[AccessibilityVrna]") {
4343
// 'x' is passed at both C-string boundaries and forces unpaired bases.
4444
REQUIRE( E_equal(acc.getED(0, 0), 0) );
4545
REQUIRE( E_equal(acc.getED(rna.size()-1, rna.size()-1), 0) );
46+
// 'p' is passed at both C-string boundaries and forces paired bases.
47+
REQUIRE( E_equal(acc.getED(1, 1), Accessibility::ED_UPPER_BOUND) );
48+
REQUIRE( E_equal(acc.getED(rna.size()-2, rna.size()-2), Accessibility::ED_UPPER_BOUND) );
49+
50+
// check maximal length
51+
REQUIRE( acc.getMaxLength() == 1 );
52+
// check for ED values of length+1 regions required for dangling-end probability computation
53+
REQUIRE( E_equal(acc.getED(0, 1), Accessibility::ED_UPPER_BOUND) ); // not accessible due to 'p' at position 1
54+
//std::cerr << "acc.getED(2,3) = " << acc.getED(2,3) << std::endl;
55+
REQUIRE( E_equal(acc.getED(2,3), 610) ); // should be accessible for dangling-end probability computation of position 2 or 3
4656

4757
// Exercise the same x|........|x bytes through computeES() and
4858
// computeIntraEall(), including the reversed accessibility path.

0 commit comments

Comments
 (0)