Skip to content

Commit

Permalink
#43 More work on gtf/gffs drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Aug 20, 2024
1 parent 6624b0e commit 45f793e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 54 deletions.
42 changes: 18 additions & 24 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,19 +1724,13 @@ namespace Drawing {
uint8_t thickness = trk.drawThickness[i];
if (thickness && s < rgn.end && e > rgn.start) {

// if ((trk.coding_end != -1 && s >= trk.coding_end) ||
// (trk.coding_start != -1 && e <= trk.coding_start)) {
// thickness = 1;
// }

if (s < trk.coding_end && e > trk.coding_end) { //overlaps, split into two blocks!
drawTrackBlock(s, trk.coding_end, trk.name, rgn, rect, path, padX, padY, y, h, stepX, stepY, gap,
gap2, xScaling, opts, canvas, fonts, false, true, add_line, false, labelsEnd, empty_str, 0, text, false, false, faceColour, pointSlop, strand);
drawTrackBlock(trk.coding_end, e, trk.name, rgn, rect, path, padX, padY, y + (h * 0.25), h * 0.5, stepX, stepY, gap,
gap2, xScaling, opts, canvas, fonts, false, true, add_line, true, labelsEnd, empty_str, 0, text, false, false, shadedFaceColour, pointSlop, 0);
}

// else if (thickness == 1) {
if (thickness == 1) {
drawTrackBlock(s, e, trk.name, rgn, rect, path, padX, padY, y + (h * 0.25), h * 0.5, stepX, stepY, gap, gap2, xScaling,
opts, canvas, fonts, false, true, add_line, true, labelsEnd, empty_str, 0, text, false, false, shadedFaceColour, pointSlop, 0);
Expand All @@ -1756,24 +1750,24 @@ namespace Drawing {
path2.moveTo(x, yy);
path2.lineTo(w, yy);
canvas->drawPath(path2, opts.theme.lcLightJoins);
// if (stranded != 0 && w - x > 50) {
// while (x + 50 < w) {
// x += 50;
// path2.reset();
// if (stranded == 1) {
// path2.moveTo(x, yy);
// path2.lineTo(x - 6, yy + 6);
// path2.moveTo(x, yy);
// path2.lineTo(x - 6, yy - 6);
// } else {
// path2.moveTo(x, yy);
// path2.lineTo(x + 6, yy + 6);
// path2.moveTo(x, yy);
// path2.lineTo(x + 6, yy - 6);
// }
// canvas->drawPath(path2, opts.theme.lcJoins);
// }
// }
if (stranded != 0 && w - x > 50) {
while (x + 50 < w) {
x += 50;
path2.reset();
if (stranded == 1) {
path2.moveTo(x, yy);
path2.lineTo(x - 6, yy + 6);
path2.moveTo(x, yy);
path2.lineTo(x - 6, yy - 6);
} else {
path2.moveTo(x, yy);
path2.lineTo(x + 6, yy + 6);
path2.moveTo(x, yy);
path2.lineTo(x + 6, yy - 6);
}
canvas->drawPath(path2, opts.theme.lcJoins);
}
}
}
}
}
Expand Down
43 changes: 13 additions & 30 deletions src/hts_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,41 +1470,39 @@ namespace HGW {
}

for (const auto &item : Utils::split(b.parts[8], ';')) {

if (kind == GFF3_NOI) {
std::vector<std::string> keyval = Utils::split(item, '=');
if (keyval[0] == "Name") {
b.parent = keyval[1];
if (keyval[0] == "Name" || keyval[0] == "gene_name") {
b.name = keyval[1];
break;
if (!b.parent.empty()) {
break;
}
}
else if (keyval[0] == "ID") {
else if (b.name.empty() && keyval[0] == "ID") {
b.name = keyval[1];
}
else if (keyval[0] == "Parent") {
b.parent = keyval[1];
break;
b.name = keyval[1];
}
} else { // GTF_NOI
std::vector<std::string> keyval = Utils::split(item, ' ');

if (keyval[0] == "gene_id") {
b.parent = keyval[1];
b.name = keyval[1];
break;
} else if (keyval[0] == "gene_name") {
b.parent = keyval[1];
b.name = keyval[1];
break;
} else if (b.name.empty() && keyval[0] == "transcript_id") {
b.name = keyval[1];
}
}

}
if (b.name.empty()) {
continue;
}
track_blocks[b.name].push_back(std::move(b));
track_blocks[b.parent].push_back(std::move(b));

}
for (const auto& kv : track_blocks) {
Expand Down Expand Up @@ -1602,11 +1600,7 @@ namespace HGW {
} else {
if (allBlocks.contains(rgn->chrom)) {
std::vector<size_t> a;
if (kind == GFF3_NOI || kind == GTF_NOI) {
allBlocks[rgn->chrom].overlap(std::max(1, rgn->start - 100000), rgn->end + 100000, a);
} else {
allBlocks[rgn->chrom].overlap(rgn->start, rgn->end, a);
}
allBlocks[rgn->chrom].overlap(rgn->start, rgn->end, a);
overlappingBlocks.clear();
if (a.empty()) {
done = true;
Expand Down Expand Up @@ -1736,9 +1730,6 @@ namespace HGW {
vartype = iter_blk->vartype;
strand = iter_blk->strand;
variantString = iter_blk->line;
if (rid == "\"ENST00000367590.9_4\"") {
std::cout << " iter < " << start << " " << vartype << "\n";
}
parts = iter_blk->parts;
++iter_blk;
if (kind == VCF_NOI && (start < fetch_start - *variant_distance && stop > fetch_end + *variant_distance)) {
Expand Down Expand Up @@ -2326,8 +2317,8 @@ namespace HGW {
if (j == 0) {
track.chrom = g->chrom;
track.start = g->start;
track.name = pg.first;
// std::cout << track.name << " ---\n";
track.name = g->name;

if (track.name.front() == '"') {
track.name.erase(0, 1);
}
Expand All @@ -2338,11 +2329,12 @@ namespace HGW {
if (track.parent.front() == '"') {
track.parent.erase(0, 1);
}
if (track.name.back() == '"') {
if (track.parent.back() == '"') {
track.parent.erase(track.parent.size() - 1, 1);
}
track.end = g->end;
track.strand = g->strand;

} else if (g->end > track.end) {
track.end = g->end;
}
Expand All @@ -2351,19 +2343,13 @@ namespace HGW {
track.s.push_back(g->start);
track.e.push_back(g->end);

// if (restAreThin) {
// track.drawThickness.push_back(1);
// } else
if (g->vartype == "exon" || g->vartype == "CDS") {
if (!track.anyToDraw) { track.anyToDraw = true; }
if (between_codons) {
track.drawThickness.push_back(2); // fat line
} else {
track.drawThickness.push_back(1); // thin line
}
// if (g->vartype == "exon" || g->vartype == "CDS") {
// track.drawThickness.push_back(2); // fat line
// if (!track.anyToDraw) { track.anyToDraw = true; }
} else if (g->vartype == "mRNA" || g->vartype == "gene") {
track.drawThickness.push_back(0); // no line
} else if (g->vartype == "start_codon") {
Expand All @@ -2372,15 +2358,12 @@ namespace HGW {
track.drawThickness.push_back(2);
} else if (g->vartype == "stop_codon") {
between_codons = !between_codons;
// std::cout << g->vartype << " " << " " << g->start << " " << between_codons << std::endl;
track.coding_end = g->end;
// restAreThin = true;
track.drawThickness.push_back(2);
} else {
track.drawThickness.push_back(1);
if (!track.anyToDraw) { track.anyToDraw = true; }
}
// std::cout << g->vartype << " " << (int)track.drawThickness.back() << std::endl;
j += 1;
}
i += 1;
Expand Down

0 comments on commit 45f793e

Please sign in to comment.