Skip to content

Commit

Permalink
Work on print function. Nicer ins drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Jul 8, 2024
1 parent f69f05b commit 9a3c3e0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ namespace Drawing {
mmPosOffset = 0.05;
mmScaling = 0.9;
} else {


mmPosOffset = 0;
mmScaling = 1;
}
Expand Down
107 changes: 76 additions & 31 deletions src/term_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ namespace Term {
int i = 0;
int p = r->pos;
bool started = false;
bool done_final_op = false;
int printed = 0;
for (k = 0; k < cigar_l; k++) {
op = cigar_p[k] & BAM_CIGAR_MASK;
Expand Down Expand Up @@ -396,8 +397,12 @@ namespace Term {
}
p += l;
if (printed > max) {
out << "...";
break;
if (done_final_op) {
out << "...";
break;
} else {
done_final_op = true;
}
}

} else if (op == BAM_CMATCH) {
Expand Down Expand Up @@ -460,15 +465,20 @@ namespace Term {
}
} else {
if (mod_it != mod_end && i == mod_it->index) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;
for (int j=0; j < mod_it->n_mods; ++j) {
if (mod_it->mods[j] == *target_mod) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;
}
out << "M" << termcolor::reset;
}
}
out << "M" << termcolor::reset;

++mod_it;
} else {
out << ".";
out << "_";
}
}

Expand All @@ -479,9 +489,13 @@ namespace Term {
p += 1;

}
if (printed > max) {
out << "...";
break;
if (printed > max*2) {
if (done_final_op) {
out << "...";
break;
} else {
done_final_op = true;
}
}

} else if (op == BAM_CEQUAL) {
Expand Down Expand Up @@ -518,15 +532,21 @@ namespace Term {
}
} else {
if (mod_it != mod_end && i == mod_it->index) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;

for (int j=0; j < mod_it->n_mods; ++j) {
if (mod_it->mods[j] == *target_mod) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;
}
out << "=" << termcolor::reset;
}
}
out << "=" << termcolor::reset;

++mod_it;
} else {
out << ".";
out << "_";
}
}
i += 1;
Expand All @@ -535,11 +555,16 @@ namespace Term {
}
// p += l;
if (printed > max / 2) {
out << "...";
break;
if (done_final_op) {
out << "...";
break;
} else {
done_final_op = true;
}
}

} else if (op == BAM_CDIFF || op == BAM_CINS) {

if (started || std::abs(pos - p) < max / 2 || std::abs(pos - block_end) < max / 2 || overlaps) {
started = true;
} else {
Expand All @@ -549,7 +574,7 @@ namespace Term {
i += l;
continue;
}
printed += l;

if (op == BAM_CINS && l > indel_length) {
out << termcolor::magenta << "[" << std::to_string(l) << "]" << termcolor::reset;
}
Expand Down Expand Up @@ -577,25 +602,36 @@ namespace Term {
} else {
if (mod_it != mod_end && i == mod_it->index) {
char o = (op == BAM_CINS) ? 'I' : 'X';
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;

for (int j=0; j < mod_it->n_mods; ++j) {
if (mod_it->mods[j] == *target_mod) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;
}
out << o << termcolor::reset;
}
}
out << o << termcolor::reset;

++mod_it;
} else {
out << ".";
out << "_";
}
}
i += 1;
}
if (op == BAM_CDIFF) {
p += l;
printed += l;
}
if (printed > max) {
out << "...";
break;
if (done_final_op) {
out << "...";
break;
} else {
done_final_op = true;
}
}

} else { // soft-clips
Expand Down Expand Up @@ -640,10 +676,19 @@ namespace Term {
}
} else {
if (mod_it != mod_end && i == mod_it->index) {
out << "S";
for (int j=0; j < mod_it->n_mods; ++j) {
if (mod_it->mods[j] == *target_mod) {
if (*target_mod == 'm') {
out << termcolor::on_yellow << termcolor::grey;
} else if (*target_mod == 'h') {
out << termcolor::on_green << termcolor::grey;
}
out << "S" << termcolor::reset;
}
}
++mod_it;
} else {
out << ".";
out << "_";
}
}
i += 1;
Expand All @@ -670,7 +715,7 @@ namespace Term {
const char *rname = sam_hdr_tid2name(hdr, r->delegate->core.tid);
const char *rnext = sam_hdr_tid2name(hdr, r->delegate->core.mtid);

int term_width = std::max(Utils::get_terminal_width() * 2 - 9, 50);
int term_width = std::max(Utils::get_terminal_width() - 9, 50);

out << std::endl << std::endl;
out << termcolor::bold << "qname " << termcolor::reset << bam_get_qname(r->delegate) << std::endl;
Expand Down
9 changes: 6 additions & 3 deletions src/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ namespace Themes {
fcIns.setARGB(255, 158, 112, 250);

fc5mc.setARGB(127, 194, 151, 58);
fc5hmc.setARGB(127, 52, 255, 96);
// fc5hmc.setARGB(127, 52, 255, 96);
fc5hmc.setARGB(127, 189, 78, 23);
lcJoins.setARGB(255, 80, 80, 80);
lcLightJoins.setARGB(255, 140, 140, 140);
lcLabel.setARGB(255, 80, 80, 80);
Expand Down Expand Up @@ -292,7 +293,8 @@ namespace Themes {
fcIns.setARGB(255, 158, 112, 250);
// fc5mc.setARGB(127, 252, 186, 3);
fc5mc.setARGB(127, 30, 176, 230);
fc5hmc.setARGB(127, 52, 255, 96);
// fc5hmc.setARGB(127, 52, 255, 96);
fc5hmc.setARGB(127, 215, 85, 23);
lcJoins.setARGB(255, 142, 142, 142);
lcLightJoins.setARGB(255, 82, 82, 82);
lcLabel.setARGB(255, 182, 182, 182);
Expand Down Expand Up @@ -331,7 +333,8 @@ namespace Themes {
fcN.setARGB(255, 128, 128, 128);
// fc5mc.setARGB(127, 252, 186, 3);
fc5mc.setARGB(127, 30, 176, 230);
fc5hmc.setARGB(127, 52, 255, 96);
// fc5hmc.setARGB(127, 52, 255, 96);
fc5hmc.setARGB(127, 215, 85, 23);
lcJoins.setARGB(255, 142, 142, 142);
lcLightJoins.setARGB(255, 82, 82, 82);
lcLabel.setARGB(255, 182, 182, 182);
Expand Down

0 comments on commit 9a3c3e0

Please sign in to comment.