Skip to content

Commit

Permalink
Fixed silent cov overflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Jan 16, 2024
1 parent ac48683 commit 255141f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Drawing {
Segs::findMismatches(opts, cl);
}

float tot, mean, n;
double tot, mean, n;
const std::vector<int> &covArr_r = cl.covArr;
std::vector<float> c;
c.resize(cl.covArr.size());
Expand Down Expand Up @@ -442,16 +442,21 @@ namespace Drawing {
collection_processed = true;
return;
}
size_t mm_array_len = mm_array.size();

uint32_t r_pos = align.pos;
uint32_t cigar_l = align.delegate->core.n_cigar;
uint8_t *ptr_seq = bam_get_seq(align.delegate);
uint32_t *cigar_p = bam_get_cigar(align.delegate);
auto *ptr_qual = bam_get_qual(align.delegate);

if (cigar_l == 0 || ptr_seq == nullptr || cigar_p == nullptr) {
return;
}

if (!region->refSeq) return;
const char *refSeq = region->refSeq;

uint32_t qseq_len = align.delegate->core.l_qseq;
const uint32_t rlen = region->end - region->start;
const uint32_t rbegin = region->start;
const uint32_t rend = region->end;
Expand All @@ -460,6 +465,9 @@ namespace Drawing {
for (uint32_t k = 0; k < cigar_l; k++) {
op = cigar_p[k] & BAM_CIGAR_MASK;
l = cigar_p[k] >> BAM_CIGAR_SHIFT;
if (idx >= qseq_len) { // shouldn't happen
break;
}
switch (op) {
case BAM_CMATCH:
for (uint32_t i = 0; i < l; ++i) {
Expand All @@ -472,6 +480,9 @@ namespace Drawing {
if (r_idx >= (int) rlen) {
break;
}
if (r_pos - rbegin >= mm_array_len) {
break;
}

char ref_base;
char current_base = refSeq[r_idx];
Expand Down Expand Up @@ -539,7 +550,7 @@ namespace Drawing {
break;
case BAM_CDIFF:
for (uint32_t i = 0; i < l; ++i) {
if (r_pos >= rbegin && r_pos < rend) {
if (r_pos >= rbegin && r_pos < rend && r_pos - rbegin < mm_array_len) {
char bam_base = bam_seqi(ptr_seq, idx);
p = (r_pos - rbegin) * xScaling;
uint32_t colorIdx = (l_qseq == 0) ? 10 : (ptr_qual[idx] > 10) ? 10 : ptr_qual[idx];
Expand Down Expand Up @@ -1679,7 +1690,7 @@ namespace Drawing {
trackIdx += 1;
padY += stepY;

if (fonts.overlayHeight * nLevels < stepY) {
if (fonts.overlayHeight * nLevels * 2 < stepY) {
for (const auto&t: text) {
canvas->drawTextBlob(t.text, t.x, t.y, opts.theme.tcDel);
}
Expand All @@ -1697,14 +1708,19 @@ namespace Drawing {
const faidx_t *fai, std::vector<sam_hdr_t *> &headers, size_t nRegions, float fb_width,
float fb_height, float monitorScale) {
SkPaint paint, line;
if (opts.theme_str == "slate") {
paint.setARGB(255, 160, 160, 165);
// paint.setARGB(255, 110, 120, 165);

if (opts.theme_str == "igv") {
paint.setARGB(255, 87, 95, 107);
// paint.setARGB(255, 160, 160, 165);
} else {
paint.setColor(SK_ColorRED);
paint.setARGB(255, 149, 149, 163);
// paint.setColor(SK_ColorRED);
}
paint.setStrokeWidth(3);
paint.setStrokeWidth(2);
paint.setStyle(SkPaint::kStroke_Style);
line.setColor((opts.theme_str == "dark") ? SK_ColorWHITE : SK_ColorBLACK);
// line.setColor((opts.theme_str == "dark") ? SK_ColorGRAY : SK_ColorBLACK);
line.setColor((opts.theme_str == "dark") ? SK_ColorGRAY : SK_ColorBLACK);
line.setStrokeWidth(monitorScale);
line.setStyle(SkPaint::kStroke_Style);
SkRect rect{};
Expand Down

0 comments on commit 255141f

Please sign in to comment.