Commit 719c3329 authored by Marc Duez's avatar Marc Duez

windows.cpp : use c++11 json lib

parent 4d0abc1a
......@@ -47,14 +47,14 @@ size_t WindowsStorage::getMaximalNbReadsPerWindow() {
return max_reads_per_window;
}
JsonList WindowsStorage::statusToJson(junction window) {
JsonList result;
json WindowsStorage::statusToJson(junction window) {
json result;
for (unsigned int i=0; i<status_by_window[window].size(); i++){
if (status_by_window[window][i] !=0){
ostringstream oss;
oss << i;
result.add(oss.str(), status_by_window[window][i]);
result[oss.str()] = status_by_window[window][i];
}
}
......@@ -239,8 +239,8 @@ JsonArray WindowsStorage::sortedWindowsToJsonArray(map <junction, JsonList> json
windowsList.add("reads", json_reads);
windowsList.add("top", top++);
//windowsList.add("id", this->getId(it->first));
JsonList seg_stat = this->statusToJson(it->first);
json_seg.add(seg_stat);
//JsonList seg_stat = this->statusToJson(it->first);
//json_seg.add(seg_stat);
windowsList.add("germline", germline_by_window[it->first]->code);
windowsList.add("seg_stat", json_seg);
windowsArray.add(windowsList);
......@@ -249,6 +249,35 @@ JsonArray WindowsStorage::sortedWindowsToJsonArray(map <junction, JsonList> json
return windowsArray;
}
json WindowsStorage::sortedWindowsToJson(map <junction, json> json_data_segment) {
json windowsArray;
int top = 1;
for (list<pair <junction, size_t> >::const_iterator it = sort_all_windows.begin();
it != sort_all_windows.end(); ++it)
{
json windowsList;
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;
windowsList["reads"] = reads;
windowsList["top"] = top++;
windowsList["germline"] = germline_by_window[it->first]->code;
windowsList["seg_stat"] = this->statusToJson(it->first);
windowsArray.push_back(windowsList);
}
return windowsArray;
}
ostream &WindowsStorage::windowToStream(ostream &os, junction window, int num_seq,
size_t size) {
os << ">" << size << "--window--" << num_seq << " " << getLabel(window) << endl ;
......
......@@ -22,11 +22,13 @@
#include "read_score.h"
#include "representative.h"
#include "stats.h"
#include "../lib/json.hpp"
#define NB_BINS 15
#define MAX_VALUE_BINS 500
using namespace std;
using json = nlohmann::json;
typedef string junction ;
......@@ -61,7 +63,7 @@ class WindowsStorage {
map<junction, BinReadStorage>::iterator begin();
map<junction, BinReadStorage>::iterator end();
JsonList statusToJson(junction window);
json statusToJson(junction window);
/**
* @return the average read length of the reads segmented with the given window
......@@ -211,6 +213,8 @@ class WindowsStorage {
ostream &printSortedWindows(ostream &os);
JsonArray sortedWindowsToJsonArray(map<junction, JsonList> json_data_segment);
json sortedWindowsToJson(map<junction, json> json_data_segment);
/**
* Display a window with its in size in a somewhat FASTA format
......
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