Commit 2315f305 authored by Mathieu Giraud's avatar Mathieu Giraud

core/segment.{cpp,h}, vidjil.cpp: refactor ::toJsonList(), extract KmerSegmenter::toJsonList()

Each segmenter has now its own toJsonList() method.
This is more flexible and allows to output the KmerSegmenter even when the FineSegmenter failed.
parent 83b952c2
......@@ -868,34 +868,21 @@ void FineSegmenter::findCDR3(){
}
JsonList FineSegmenter::toJsonList(Germline *germline){
JsonList result;
//string str = getSequence().sequence;
// KmerMultiSegmenter kmseg(getSequence(), multigermline, 0);
// KmerSegmenter *kseg = kmseg.the_kseg ;
KmerSegmenter *kseg = new KmerSegmenter(getSequence(), germline);
result.add("sequence", revcomp(sequence, reversed) );
void FineSegmenter::toJsonList(JsonList *seg){
if (isSegmented()) {
result.add("name", code_short);
JsonList seg;
seg.add("5", germline->rep_5.label(best_V));
seg.add("5start", 0);
seg.add("5end", Vend);
seg->add("5", segmented_germline->rep_5.label(best_V));
seg->add("5start", 0);
seg->add("5end", Vend);
if (score_D.size()>0){
seg.add("4", germline->rep_4.label(best_D));
seg.add("4start", Dstart);
seg.add("4end", Dend);
seg->add("4", segmented_germline->rep_4.label(best_D));
seg->add("4start", Dstart);
seg->add("4end", Dend);
}
seg.add("3", germline->rep_3.label(best_J));
seg.add("3start", Jstart);
seg->add("3", segmented_germline->rep_3.label(best_J));
seg->add("3start", Jstart);
if (CDR3start >= 0)
{
......@@ -903,32 +890,30 @@ JsonList FineSegmenter::toJsonList(Germline *germline){
json_cdr=new JsonList();
json_cdr->add("start", CDR3start);
json_cdr->add("stop", CDR3end);
seg.add("cdr3", *json_cdr);
seg->add("cdr3", *json_cdr);
}
}
}
void KmerSegmenter::toJsonList(JsonList *seg)
{
int sequenceSize = sequence.size();
JsonList *json_affectValues;
json_affectValues=new JsonList();
json_affectValues->add("start", 0);
json_affectValues->add("stop", sequenceSize);
json_affectValues->add("seq", kseg->getKmerAffectAnalyser()->toStringValues());
seg.add("affectValues", *json_affectValues);
json_affectValues->add("seq", getKmerAffectAnalyser()->toStringValues());
seg->add("affectValues", *json_affectValues);
JsonList *json_affectSigns;
JsonList *json_affectSigns;
json_affectSigns=new JsonList();
json_affectSigns->add("start", 0);
json_affectSigns->add("stop", sequenceSize);
json_affectSigns->add("seq", kseg->getKmerAffectAnalyser()->toStringSigns());
seg.add("affectSigns", *json_affectSigns);
result.add("seg", seg);
delete kseg ;
}
return result;
json_affectSigns->add("seq", getKmerAffectAnalyser()->toStringSigns());
seg->add("affectSigns", *json_affectSigns);
}
......@@ -174,6 +174,8 @@ class KmerSegmenter : public Segmenter
*/
KmerAffectAnalyser *getKmerAffectAnalyser() const;
void toJsonList(JsonList *seg);
private:
void computeSegmentation(int strand, KmerAffect left, KmerAffect right);
};
......@@ -214,7 +216,7 @@ class FineSegmenter : public Segmenter
void FineSegmentD(Germline *germline);
void findCDR3();
JsonList toJsonList(Germline *germline);
void toJsonList(JsonList *seg);
};
......
......@@ -1178,9 +1178,29 @@ int main (int argc, char **argv)
out_clone << seg << endl ;
out_clones << seg << endl ;
// Output segmentation to .json
json_data_segment[it->first]=seg.toJsonList(segmented_germline);
// Prepare .json data segment
JsonList json_clone;
JsonList json_seg;
// From FineSegmenter
json_clone.add("sequence", seg.getSequence().sequence);
if (seg.isSegmented())
json_clone.add("name", seg.code_short);
seg.toJsonList(&json_seg);
// Re-launch also a KmerMultiSegmenter, for debug purposes
KmerMultiSegmenter kmseg(seg.getSequence(), multigermline, 0);
KmerSegmenter *kseg = kmseg.the_kseg ;
kseg->toJsonList(&json_seg);
// Save .json data segment
json_clone.add("seg", json_seg);
json_data_segment[it->first] = json_clone;
if (seg.isSegmented())
{
// Check for identical code, outputs to out_edge
......
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