Commit b13436cd authored by Mikael Salson's avatar Mikael Salson

WindowsStorage: add a getNbReads() method.

Returns the number of reads for a window.
Previously it could be obtained through getReads().size() but in the future we may not always
store all the reads in memory but just the most abundants.
parent 684d2a66
......@@ -43,6 +43,11 @@ JsonList WindowsStorage::statusToJson(junction window) {
return result;
}
size_t WindowsStorage::getNbReads(junction window) {
assert(hasWindow(window));
return reads_by_window[window];
}
list<Sequence> &WindowsStorage::getReads(junction window) {
return seqs_by_window[window];
}
......@@ -111,10 +116,13 @@ void WindowsStorage::setIdToAll() {
}
void WindowsStorage::add(junction window, Sequence sequence, int status, Germline *germline) {
seqs_by_window[window].push_back(sequence);
if (status_by_window.find(window) == status_by_window.end() ) {
status_by_window[window].resize(STATS_SIZE);
if (! hasWindow(window)) {
reads_by_window[window] = 1;
status_by_window[window].resize(STATS_SIZE);
} else {
reads_by_window[window]++;
}
seqs_by_window[window].push_back(sequence);
status_by_window[window][status]++;
germline_by_window[window] = germline;
......@@ -142,9 +150,9 @@ pair <int, int> WindowsStorage::keepInterestingWindows(size_t min_reads_window)
it != seqs_by_window.end(); ) // We do not advance the iterator here because of the deletion
{
junction junc = it->first;
size_t nb_reads_this_window = getNbReads(junc);
// Is it not supported by enough reads?
if (!(seqs_by_window[junc].size() >= min_reads_window)
if (!(nb_reads_this_window >= min_reads_window)
// Is it not a labelled junction?
&& (windows_labels.find(junc) == windows_labels.end()))
{
......@@ -154,7 +162,7 @@ pair <int, int> WindowsStorage::keepInterestingWindows(size_t min_reads_window)
removes++ ;
}
else {
nb_reads += seqs_by_window[junc].size();
nb_reads += nb_reads_this_window;
it++;
}
}
......
......@@ -28,6 +28,7 @@ class WindowsStorage {
map<junction, list<Sequence> > seqs_by_window;
map<junction, vector<int> > status_by_window;
map<junction, Germline* > germline_by_window;
map<junction, size_t> reads_by_window;
map<string, string> windows_labels;
list<pair <junction, int> > sort_all_windows;
map<junction, int> id_by_window;
......@@ -46,6 +47,12 @@ class WindowsStorage {
Germline *getGermline(junction window);
JsonList statusToJson(junction window);
/**
* @pre hasWindow(window)
* @return the total number of reads supporting a window.
*/
size_t getNbReads(junction window);
/**
* @return the list of reads supporting a given window
......
......@@ -18,6 +18,7 @@ void testWSAdd() {
TAP_TEST(ws.hasWindow("ATTAG") == true, TEST_WS_HAS_WINDOW, "");
TAP_TEST(ws.hasWindow("A") == false, TEST_WS_HAS_WINDOW, "");
TAP_TEST(ws.size() == 1, TEST_WS_SIZE, "");
TAP_TEST(ws.getNbReads("ATTAG") == 1, TEST_WS_GET_NB_READS, "");
TAP_TEST(ws.getLabel("ATTAG") == "", TEST_WS_GET_LABEL_NONE, "");
list<Sequence> sequences = ws.getReads("ATTAG");
......@@ -34,6 +35,7 @@ void testWSAdd() {
ws.add("ATTAG", seq, SEG_PLUS, &germline);
TAP_TEST(ws.size() == 1, TEST_WS_SIZE, "");
TAP_TEST(ws.getNbReads("ATTAG") == 11, TEST_WS_GET_NB_READS, "");
sequences = ws.getReads("ATTAG");
TAP_TEST(sequences.size() == 11, TEST_WS_GET_READS, "");
......
......@@ -114,6 +114,7 @@ enum {
/* WindowsStorage */
TEST_WS_GET_GERMLINE,
TEST_WS_GET_GERMLINE_NONE,
TEST_WS_GET_NB_READS,
TEST_WS_HAS_WINDOW,
TEST_WS_SIZE,
TEST_WS_SIZE_NONE,
......@@ -237,6 +238,7 @@ inline void declare_tests() {
RECORD_TAP_TEST(TEST_WS_GET_GERMLINE, "Test WindowsStorage::getGermline");
RECORD_TAP_TEST(TEST_WS_HAS_WINDOW, "Test WindowsStorage::hasWindow");
RECORD_TAP_TEST(TEST_WS_GET_GERMLINE_NONE, "Test WindowsStorage::getGermline() with undefined window");
RECORD_TAP_TEST(TEST_WS_GET_NB_READS, "Test WindowsStorage::getNbReads");
RECORD_TAP_TEST(TEST_WS_SIZE, "Test WindowsStorage::size()");
RECORD_TAP_TEST(TEST_WS_SIZE_NONE, "Test WindowsStorage::size() when empty");
RECORD_TAP_TEST(TEST_WS_GET_LABEL_NONE, "Test WindowsStorage::getLabel() with no label");
......
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