Commit d856b56f authored by Mathieu Giraud's avatar Mathieu Giraud

core/windows.{h,cpp], core/output.{h,cpp}: CloneOutput* SampleOutput::getClone(junction junction)

Extracting getClone() to SampleOutput.

See #3358.
parent 3f118111
......@@ -44,3 +44,17 @@ void SampleOutput::addClone(junction junction, CloneOutput *clone)
{
clones[junction] = clone;
}
CloneOutput* SampleOutput::getClone(junction junction)
{
if (clones.find(junction) != clones.end()){
return clones[junction];
}
else
{
CloneOutput *clone = new(CloneOutput);
addClone(junction, clone);
clone -> set("sequence", 0); // TODO need to compute representative sequence for this case
return clone;
}
}
......@@ -45,6 +45,9 @@ public:
void addClone(junction junction, CloneOutput *clone);
// get a clone, or create a new one if needed
CloneOutput* getClone(junction junction);
json toJson();
};
......
......@@ -266,35 +266,25 @@ void WindowsStorage::clearSequences(){
seqs_by_window.clear();
}
json WindowsStorage::sortedWindowsToJson(map <junction, json> json_data_segment, int max_json_output, bool delete_all) {
json windowsArray;
void WindowsStorage::sortedWindowsToOutput(SampleOutput *output, int max_output, bool delete_all) {
int top = 1;
for (list<pair <junction, size_t> >::iterator it = sort_all_windows.begin();
it != sort_all_windows.end(); )
{
json windowsList;
CloneOutput *clone = output->getClone(it->first);
if (json_data_segment.find(it->first) != json_data_segment.end()){
windowsList = json_data_segment[it->first];
}else{
windowsList["sequence"] = 0; //TODO need to compute representative sequence for this case
}
json reads = {it->second};
windowsList["id"] = it->first;
if (status_by_window[it->first][SEG_CHANGED_WINDOW])
json_add_warning(windowsList, "W50", "Short or shifted window");
clone->add_warning("W50", "Short or shifted window", LEVEL_WARN);
windowsList["reads"] = reads;
windowsList["top"] = top++;
windowsList["germline"] = germline_by_window[it->first]->code;
windowsList["seg_stat"] = this->statusToJson(it->first);
clone->set("id", it->first);
clone->set("reads", {it->second});
clone->set("top", top++);
clone->set("germline", germline_by_window[it->first]->code);
clone->set("seg_stat", this->statusToJson(it->first));
windowsArray.push_back(windowsList);
if (delete_all) {
germline_by_window.erase(it->first);
status_by_window.erase(it->first);
......@@ -302,11 +292,9 @@ json WindowsStorage::sortedWindowsToJson(map <junction, json> json_data_segment,
} else {
it++;
}
if (top == max_json_output + 1)
if (top == max_output + 1)
break ;
}
return windowsArray;
}
ostream &WindowsStorage::windowToStream(ostream &os, junction window, int num_seq,
......
......@@ -19,6 +19,7 @@
#include "read_score.h"
#include "representative.h"
#include "stats.h"
#include "output.h"
#include "../lib/json_fwd.hpp"
#define NB_BINS 30
......@@ -222,9 +223,9 @@ class WindowsStorage {
/**
* @param delete_all: Delete the objects while they are inserted into the JSON. This prevents the memory
* from continously increasing (see #2120, #3387)
* @return a JSON object containing all the information
* @post insert the information into the SampleOutput clones
*/
json sortedWindowsToJson(map<junction, json> json_data_segment, int max_json_output, bool delete_all=false);
void sortedWindowsToOutput(SampleOutput *output, int max_output, bool delete_all=false);
/**
* Clear the seqs_by_window map.
......
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