Commit 5c8bbcd1 authored by Mathieu Giraud's avatar Mathieu Giraud

core/segment.{h,cpp}: AlignBox::refToString()

Preliminary implementation, for vdj_assign
parent a0ffc2b0
......@@ -70,6 +70,61 @@ void AlignBox::addToJson(json &seg) {
seg[key] = j ;
}
#define NO_COLOR "\033[0m"
int AlignBox::posInRef(int i) {
// Works now only for V/J boxes
if (del_left >= 0) // J
return i - start + del_left + 1; // Why +1 ?
if (del_right >= 0) // V
return i + (ref.size() - del_right) - end ;
return -99;
}
string AlignBox::refToString(int from, int to) {
stringstream s;
s << ref_label << " \t" ;
int j = posInRef(from);
s << j << "\t" ;
if (from > start)
s << color;
for (int i=from; i<=to; i++) {
if (i == start)
s << color;
if (j > 0 && j <= ref.size())
s << ref[j-1] ;
else
s << ".";
if (i == end)
s << NO_COLOR;
// Related position. To improve
j++ ;
}
if (to < end)
s << NO_COLOR;
s << "\t" << j ;
return s.str();
}
ostream &operator<<(ostream &out, const AlignBox &box)
{
out << "[/" << box.del_left << " " ;
......
......@@ -87,6 +87,18 @@ class AlignBox
string getSequence(string sequence);
void addToJson(json &seg);
/**
* Returns the position in the reference string corresponding to the position in the read
* Preliminary implementation, only works for the start of V and J boxes
*/
int posInRef(int i);
/**
* Format the reference string in a given range position, possibly adding the ANSI colors
* where there is the alignment
*/
string refToString(int from, int to);
/* Identifier, label and sequence of the reference sequence (the best one) */
int ref_nb;
string ref_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