Commit 809bdc1d authored by Mikaël Salson's avatar Mikaël Salson

algo/core/tools.{h,cpp} + tests: Give trimSequence a region that should not be trimmed

parent 95cef044
......@@ -372,7 +372,8 @@ double nChoosek(unsigned n, unsigned k)
return nChoosek_stored[n][k];
}
void trimSequence(string &sequence, size_t &start_pos, size_t &length) {
void trimSequence(string &sequence, size_t &start_pos, size_t &length,
size_t required_start, size_t required_length) {
float prefix_score = 0;
float suffix_score = 0;
size_t start_bad_suffix = 0;
......@@ -425,8 +426,8 @@ void trimSequence(string &sequence, size_t &start_pos, size_t &length) {
}
}
start_pos = max_start_factor;
length = max_factor_length;
start_pos = min(required_start, max_start_factor);
length = max(required_length, max_factor_length);
}
......
......@@ -259,9 +259,13 @@ double nChoosek(unsigned n, unsigned k);
* More precisely, the purpose of the function is to find the longest
* substring whose prefixes and suffixes all have a ratio of N that
* is less than or equal to RATIO_TOO_MANY_N
*
* The parameters required_start and required_end give the positions
* of the required sequence that must not be cut out.
* @post start_pos <= required_start && length >= required_length
*/
void trimSequence(string &sequence, size_t &start_pos, size_t &length);
void trimSequence(string &sequence, size_t &start_pos, size_t &length,
size_t required_start=string::npos, size_t required_length=0);
const Sequence NULL_SEQUENCE = create_sequence("", "", "NULL", "");
......
......@@ -3,6 +3,7 @@
#include "tests.h"
#include <stdexcept>
#include <vector>
#include <tuple>
void testOnlineBioReader1() {
OnlineBioReader *fa = OnlineBioReaderFactory::create("data/test1.fa");
......@@ -470,6 +471,28 @@ void testTrimSequence() {
"got " << trimmed << " instead of " << seq_pair.second << " (original sequence: " << seq_pair.first
<< ")");
}
// Test the last parameters
// 0 0 1 2 2
// 0 9 2 3 6
string representative = "TTTTTTTTTNNNNCCCCCCCCCCNNNNAAAAAAAAA";
list <std::tuple<size_t, size_t, string> > required_params =
{ std::make_tuple(13, 10, "CCCCCCCCCC"),
std::make_tuple(13, 11, "CCCCCCCCCCN"),
std::make_tuple(12, 10, "NCCCCCCCCC"),
std::make_tuple(12, 11, "NCCCCCCCCCC"),
std::make_tuple(12, 12, "NCCCCCCCCCCN"),
std::make_tuple(11, 14, "NNCCCCCCCCCCNN")};
for (auto ex: required_params) {
start = 0;
length = representative.length();
trimSequence(representative, start, length, std::get<0>(ex), std::get<1>(ex));
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));
}
}
/*
......
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