Skip to content

Commit

Permalink
Updated context creation. Work on gff3/gtf drawing. Fixed wrong curso…
Browse files Browse the repository at this point in the history
…r. Paint setting for tracks works for all track types. Mods_qual_threshold added to session.
  • Loading branch information
kcleal committed Aug 13, 2024
1 parent 4118dde commit 5f40746
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:

env:
version: 1.0.1
version: 1.0.2

jobs:
mingw:
Expand Down
2 changes: 1 addition & 1 deletion deps/gw.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.0.1
Version=1.0.2
Type=Application
Terminal=true
Exec=bash -c "/usr/bin/gw"
Expand Down
107 changes: 56 additions & 51 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ namespace Drawing {
SkPath path;
path.moveTo(padX, startY - y_negativeValueOffset);
path.lineTo(padX + stepX - gap2, startY - y_negativeValueOffset);
canvas->drawPath(path, opts.theme.fcBigWig);
canvas->drawPath(path, faceColour);
// }
int step = length / 100000;
step = (step) ? step : 1;
Expand All @@ -1516,7 +1516,7 @@ namespace Drawing {
v = trk.bigWig_intervals->value[i];
x = padX + (((float)trk.bigWig_intervals->start[i] - (float)rgn.start) * xScaling);
rect.setXYWH(x, startY - y_negativeValueOffset, std::fmax(1, xScaling), -v * availableSPace);
canvas->drawRect(rect, opts.theme.fcBigWig);
canvas->drawRect(rect, faceColour);
}
if (availableSPace > 2 * fonts.overlayHeight) {
path.reset();
Expand Down Expand Up @@ -1550,45 +1550,46 @@ namespace Drawing {
float w;

SkPaint arcColour;
// SkPaint faceColour, arcColour;
if (isRoi) {
// faceColour = opts.theme.fcRoi;
} else {
if (shaded) {
faceColour = opts.theme.fcCoverage;
} else {
faceColour = opts.theme.fcTrack;
}
}
SkPaint *faceColour2 = &faceColour;

if (!vartype.empty()) {
if (vartype == "DEL") {
if (addArc) {
arcColour = opts.theme.fcT;
} else {
faceColour = opts.theme.fcT;
faceColour.setAlpha(150);
faceColour2 = &opts.theme.fcT;
faceColour2->setAlpha(150);
}

} else if (vartype == "DUP") {
if (addArc) {
arcColour = opts.theme.fcC;
} else {
faceColour = opts.theme.fcC;
faceColour.setAlpha(150);
faceColour2 = &opts.theme.fcC;
faceColour2->setAlpha(150);
}
} else if (vartype == "INV") {
if (addArc) {
arcColour = opts.theme.fcA;
} else {
faceColour = opts.theme.fcA;
faceColour.setAlpha(150);
faceColour2 = &opts.theme.fcA;
faceColour2->setAlpha(150);
}
} else {
addArc = false;
}
} else {
addArc = false;
// if (isRoi) {
// faceColour = opts.theme.fcRoi;
// } else {
// if (shaded) {
// faceColour2 = //&opts.theme.fcCoverage;
// } else {
faceColour2 = &faceColour;
// faceColour = opts.theme.fcTrack;
// }
// }
}

if (addArc) {
Expand Down Expand Up @@ -1648,7 +1649,7 @@ namespace Drawing {
} else if (strand == 2) { // -
drawLeftPointedRectangleNoEdge(canvas, h, y + padY, x + padX, w, 0, opts.theme.lcBright, path, pointSlop);
}
canvas->drawRect(rect, faceColour);
canvas->drawRect(rect, *faceColour2);

if (shaded) {
canvas->drawRect(rect, opts.theme.lcLightJoins);
Expand Down Expand Up @@ -1684,11 +1685,12 @@ namespace Drawing {
if (rightPoint > padX + stepX - gap2) {
return;
}

*labelsEnd = leftPoint + estimatedTextWidth;
rect.fLeft = leftPoint;
text.emplace_back() = {SkTextBlob::MakeFromString(rid.c_str(), fonts.overlay),
rect.left(),
rect.bottom() + fonts.overlayHeight};
rect.bottom() + fonts.overlayHeight + monitorScale * 2};

}

Expand All @@ -1698,7 +1700,8 @@ namespace Drawing {
float gap, Utils::TrackBlock &trk, bool any_text, const Utils::Region &rgn, SkRect &rect,
SkPath &path, SkPath &path2, float padX, float padY, float stepX, float stepY,
float y, float h, float h2, float h4, float gap2, float xScaling, int nLevels,
float *labelsEnd, std::vector<TextItem> &text, bool vline, SkPaint &faceColour, float pointSlop, int strand) {
float *labelsEnd, std::vector<TextItem> &text, bool vline, SkPaint &faceColour, SkPaint &shadedFaceColour,
float pointSlop, int strand, float monitorScale) {

int target = (int) trk.s.size();
int stranded = trk.strand;
Expand All @@ -1707,7 +1710,7 @@ namespace Drawing {
std::string empty_str;
if (any_text) {
drawTrackBlock(trk.start, trk.end, trk.name, rgn, rect, path, padX, padY, y, h, stepX, stepY, gap, gap2,
xScaling, opts, canvas, fonts, true, false, false, false, labelsEnd, empty_str, 0, text, false, false, faceColour, pointSlop, strand);
xScaling, opts, canvas, fonts, true, false, false, false, labelsEnd, empty_str, monitorScale, text, false, false, faceColour, pointSlop, strand);
}
for (int i = 0; i < target; ++i) {
int s, e;
Expand All @@ -1721,21 +1724,22 @@ 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 ((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, stepX, stepY, gap,
gap2, xScaling, opts, canvas, fonts, false, true, add_line, true, 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) {
drawTrackBlock(s, e, trk.name, rgn, rect, path, padX, padY, y, h, stepX, stepY, gap, gap2, xScaling,
opts, canvas, fonts, false, true, add_line, true, labelsEnd, empty_str, 0, text, false, false, faceColour, pointSlop, strand);
// 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);
} else {
drawTrackBlock(s, e, 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);
Expand All @@ -1752,24 +1756,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 Expand Up @@ -1812,7 +1816,8 @@ namespace Drawing {
rgn.featureLevels.resize(tracks.size());
for (auto &trk: tracks) {

SkPaint faceColour = trk.faceColour;
SkPaint &faceColour = trk.faceColour;
SkPaint &shadedFaceColour = trk.shadedFaceColour;

float right = ((float) (rgn.end - rgn.start) * xScaling) + padX;
canvas->save();
Expand Down Expand Up @@ -1867,7 +1872,7 @@ namespace Drawing {
fonts, gap,
f, any_text, rgn, rect, path, path2, padX, padY_track, stepX, step_track,
y, h, h2, h4, gap2,
xScaling, nLevels, fLevelEnd, text, add_line, faceColour, pointSlop, strand);
xScaling, nLevels, fLevelEnd, text, add_line, faceColour, shadedFaceColour, pointSlop, strand, monitorScale);

} else {
drawTrackBlock(f.start, f.end, f.name, rgn, rect, path, padX, padY_track, y, h, stepX, stepY,
Expand Down
29 changes: 24 additions & 5 deletions src/hts_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,12 @@ namespace HGW {
}
}

void GwTrack::setPaint(SkPaint &faceColour) {
this->faceColour = faceColour;
int c = faceColour.getColor();
this->shadedFaceColour.setARGB(faceColour.getAlpha(), SkColorGetR(c)/2, SkColorGetG(c)/2, SkColorGetB(c)/2);
}

void GwTrack::open(const std::string &p, bool add_to_dict=true) {
fileIndex = 0;
path = p;
Expand Down Expand Up @@ -2310,11 +2316,13 @@ namespace HGW {

track.anyToDraw = false;
bool restAreThin = false;
bool between_codons = false;
for (auto &g: pg.second) {
if (j == 0) {
track.chrom = g->chrom;
track.start = g->start;
track.name = pg.first;
std::cout << track.name << " ---\n";
if (track.name.front() == '"') {
track.name.erase(0, 1);
}
Expand All @@ -2338,25 +2346,36 @@ 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") {
track.drawThickness.push_back(2); // fat line
// 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") {
between_codons = !between_codons;
track.coding_start = g->start;
std::fill(track.drawThickness.begin(), track.drawThickness.end(), 1);
// std::fill(track.drawThickness.begin(), track.drawThickness.end(), 1);
track.drawThickness.push_back(2);
} else if (g->vartype == "stop_codon") {
between_codons = !between_codons;
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
3 changes: 2 additions & 1 deletion src/hts_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ namespace HGW {
bool done;
std::string variantString;

SkPaint faceColour;
SkPaint faceColour, shadedFaceColour;

void setPaint(SkPaint &faceColour);
void open(const std::string &p, bool add_to_dict);
void close();
void clear();
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void print_banner() {
}

// note to developer - update version in workflows/main.yml, menu.cpp, term_out.cpp, and deps/gw.desktop, and installers .md in docs
const char GW_VERSION [7] = "1.0.1";
const char GW_VERSION [7] = "1.0.2";


bool str_is_number(const std::string &s) {
Expand Down
2 changes: 1 addition & 1 deletion src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace Menu {

if (opts.control_level.empty()) {
if (opts.menu_table == Themes::MenuTable::MAIN) {
tip = opts.ini_path + " v1.0.1";
tip = opts.ini_path + " v1.0.2";
}
else if (opts.menu_table == Themes::MenuTable::GENOMES) { tip = "Use ENTER key to select genome, or RIGHT_ARROW key to edit path"; }
else if (opts.menu_table == Themes::MenuTable::SHIFT_KEYMAP) { tip = "Change characters selected when using shift+key"; }
Expand Down
5 changes: 4 additions & 1 deletion src/plot_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,10 @@ namespace Commands {
out << termcolor::red << "Error:" << termcolor::reset << " track index out of range\n";
return Err::SILENT;
}
p->tracks[ind].faceColour.setARGB(alpha, red, green, blue);
SkPaint new_paint;
new_paint.setARGB(alpha, red, green, blue);
p->tracks[ind].setPaint(new_paint);
// p->tracks[ind].faceColour.setARGB(alpha, red, green, blue);
refreshGw(p);
return Err::NONE;
}
Expand Down
11 changes: 6 additions & 5 deletions src/plot_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,12 @@ namespace Manager {
try {
tracks.back().open(path, true);
tracks.back().variant_distance = &opts.variant_distance;
if (tracks.back().kind == HGW::FType::BIGWIG) {
tracks.back().faceColour = opts.theme.fcBigWig;
} else {
tracks.back().faceColour = opts.theme.fcTrack;
}
tracks.back().setPaint((tracks.back().kind == HGW::FType::BIGWIG) ? opts.theme.fcBigWig : opts.theme.fcTrack);
// if (tracks.back().kind == HGW::FType::BIGWIG) {
// tracks.back().faceColour = opts.theme.fcBigWig;
// } else {
// tracks.back().faceColour = opts.theme.fcTrack;
// }

if (print_message) {
out << termcolor::magenta << "\nTrack " << termcolor::reset << path << "\n";
Expand Down
Loading

0 comments on commit 5f40746

Please sign in to comment.