Commit fba24368 authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature-a/4272-double-free' into 'dev'

Correct trimSequence

Closes #4272

See merge request !681
parents f3e5e0ea 52d1bfd8
Pipeline #141787 failed with stages
in 22 minutes and 7 seconds
......@@ -427,7 +427,9 @@ void trimSequence(string &sequence, size_t &start_pos, size_t &length,
}
start_pos = min(required_start, max_start_factor);
length = max(required_length, max_factor_length);
length = max_factor_length;
if (required_start != string::npos && start_pos + length < required_start + required_length)
length = required_start + required_length - start_pos;
}
......
......@@ -493,6 +493,22 @@ void testTrimSequence() {
trimmed = representative.substr(start, length);
TAP_TEST_EQUAL(trimmed, std::get<2>(ex), TEST_TRIM_SEQUENCE, " required_start = " << std::get<0>(ex) << ", required_length = " << std::get<1>(ex));
}
representative = "NNNNNCNGAGGAGGGCGGGAACAGAGTGACCGAGGGGGCAGCCTTGGGCTGACCTAGGACGGTCAGCTTGGTCCCTCNGNNGAATATTCGAGTACCAAAGATGTCNNNTNNTTGNCANTGNNNN";
string window = "GGTCAGCTTGGTCCCTCNGNNGAATATTCGAGTACCAAAGATGTCNNNTN";
start = 5;
length = 115;
trimSequence(representative, start, length, 60, 50);
trimmed = representative.substr(start, length);
TAP_TEST(trimmed.find(window) != string::npos, TEST_TRIM_SEQUENCE, "Trimmed representative is " << trimmed << " start = " << start << ", length = " << length );
representative = ::revcomp(representative);
window = ::revcomp(window);
start = 9;
length = 115;
trimSequence(representative, start, length, 14, 50);
trimmed = representative.substr(start, length);
TAP_TEST(trimmed.find(window) != string::npos, TEST_TRIM_SEQUENCE, "Trimmed representative is " << trimmed << " start = " << start << ", length = " << length );
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment