Commit 54b205b9 authored by Mathieu Giraud's avatar Mathieu Giraud

core/segment.{h,cpp}, vidjil.cpp: use setSeg(), define and use Segmenter.toOutput()

See #3358.
parent 359db425
......@@ -71,10 +71,9 @@ string AlignBox::getSequence(string sequence) {
return sequence.substr(start, end-start+1);
}
void AlignBox::addToJson(json &seg, int alternative_genes) {
void AlignBox::addToOutput(CloneOutput clone, int alternative_genes) {
json j;
j["name"] = ref_label;
if (key != "3") // no end information for J
......@@ -89,14 +88,16 @@ void AlignBox::addToJson(json &seg, int alternative_genes) {
j["delLeft"] = del_left;
}
seg[key] = j ;
clone.setSeg(key, j) ;
/*Export the N best genes if threshold parameter is specified*/
if(rep && !this->score.empty() && rep->size() <= (int)this->score.size() && alternative_genes > 0 && alternative_genes <= (int)this->score.size()){
seg[key + "alt"] = json::array();
json jalt = json::array();
for(int i = 0; i < alternative_genes;++i){
int r = this->score[i].second;
seg[key + "alt"].push_back(json::object({{"name",rep->label(r)}}));
jalt.push_back(json::object({{"name",rep->label(r)}}));
}
clone.setSeg(key + "alt", jalt);
}
}
......@@ -1345,74 +1346,71 @@ void FineSegmenter::checkWarnings(CloneOutput clone)
}
}
json FineSegmenter::toJson(){
void FineSegmenter::toOutput(CloneOutput clone){
json seg;
for (AlignBox *box: boxes)
{
box->addToJson(seg, this->alternative_genes);
box->addToOutput(clone, this->alternative_genes);
}
if (isSegmented()) {
if (isDSegmented()) {
seg["N1"] = seg_N1.size();
seg["N2"] = seg_N2.size();
clone.setSeg("N1", seg_N1.size());
clone.setSeg("N2", seg_N2.size());
}
else {
seg["N"] = seg_N.size();
clone.setSeg("N", seg_N.size());
}
if (CDR3start >= 0) {
seg["cdr3"] = {
clone.setSeg("cdr3", {
{"start", CDR3start},
{"stop", CDR3end},
{"aa", CDR3aa}
};
});
}
if (JUNCTIONstart >= 0) {
seg["junction"] = {
clone.setSeg("junction", {
{"start", JUNCTIONstart},
{"stop", JUNCTIONend},
{"aa", JUNCTIONaa},
{"productive", JUNCTIONproductive}
};
});
}
}
return seg;
}
json toJsonSegVal(string s) {
return {{"val", s}};
}
json KmerSegmenter::toJson() {
void KmerSegmenter::toOutput(CloneOutput clone) {
json seg;
int sequenceSize = sequence.size();
if (evalue > NO_LIMIT_VALUE)
seg["evalue"] = toJsonSegVal(scientific_string_of_double(evalue));
clone.setSeg("evalue", toJsonSegVal(scientific_string_of_double(evalue)));
if (evalue_left > NO_LIMIT_VALUE)
seg["evalue_left"] = toJsonSegVal(scientific_string_of_double(evalue_left));
clone.setSeg("evalue_left", toJsonSegVal(scientific_string_of_double(evalue_left)));
if (evalue_right > NO_LIMIT_VALUE)
seg["evalue_right"] = toJsonSegVal(scientific_string_of_double(evalue_right));
clone.setSeg("evalue_right", toJsonSegVal(scientific_string_of_double(evalue_right)));
if (getKmerAffectAnalyser() != NULL) {
seg["affectValues"] = {
clone.setSeg("affectValues", {
{"start", 1},
{"stop", sequenceSize},
{"seq", getKmerAffectAnalyser()->toStringValues()}
};
});
seg["affectSigns"] = {
clone.setSeg("affectSigns", {
{"start", 1},
{"stop", sequenceSize},
{"seq", getKmerAffectAnalyser()->toStringSigns()}
};
});
}
return seg;
}
......
......@@ -103,7 +103,7 @@ class AlignBox
AlignBox(string key = "", string color="");
string getSequence(string sequence);
void addToJson(json &seg, int alternative_genes=NO_LIMIT_VALUE);
void addToOutput(CloneOutput clone, int alternative_genes);
/**
* Returns 'V', 'D', 'J', or possibly '5', '4', '3', '?', depending on the ref_label and on the key
......@@ -327,7 +327,7 @@ class KmerSegmenter : public Segmenter
KmerAffectAnalyser *getKmerAffectAnalyser() const;
string getInfoLineWithAffects() const;
json toJson();
void toOutput(CloneOutput clone);
private:
void computeSegmentation(int strand, KmerAffect left, KmerAffect right,
......@@ -404,7 +404,7 @@ class FineSegmenter : public Segmenter
void findCDR3();
void checkWarnings(CloneOutput clone);
json toJson();
void toOutput(CloneOutput clone);
};
......
......@@ -1338,7 +1338,7 @@ int main (int argc, char **argv)
clone->set("_average_read_length", { windowsStorage->getAverageLength(it->first) });
clone->set("_coverage_info", {repComp.getCoverageInfo()});
//From KmerMultiSegmenter
clone.add("seg", kseg->toJson());
kseg->toOutput(clone);
if (repComp.getQuality().length())
clone->set("seg", "quality", {
......@@ -1386,11 +1386,10 @@ int main (int argc, char **argv)
// From FineSegmenter
if (seg.code.length() > 0)
clone->set("name", seg.code);
json json_fseg = seg.toJson();
for (json::iterator it = json_fseg.begin(); it != json_fseg.end(); ++it) {
clone->set("seg", it.key(), it.value());
}
seg.toOutput(clone);
if (seg.isSegmented())
{
......@@ -1609,8 +1608,7 @@ int main (int argc, char **argv)
s.findCDR3();
clone->set("name", s.code);
clone->set("seg", s.toJson());
s.toOutput(clone);
g = germline ;
}
else
......
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