Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vidjil
vidjil
Commits
809bdc1d
Commit
809bdc1d
authored
Apr 27, 2020
by
Mikaël Salson
Browse files
algo/core/tools.{h,cpp} + tests: Give trimSequence a region that should not be trimmed
parent
95cef044
Changes
3
Hide whitespace changes
Inline
Side-by-side
algo/core/tools.cpp
View file @
809bdc1d
...
...
@@ -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
)
;
}
...
...
algo/core/tools.h
View file @
809bdc1d
...
...
@@ -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"
,
""
);
...
...
algo/tests/unit-tests/testTools.cpp
View file @
809bdc1d
...
...
@@ -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
));
}
}
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment