Skip to content

Commit

Permalink
Variant track comments in SINGLE mode also. More bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Jul 12, 2024
1 parent 5554fca commit 1642994
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ namespace Drawing {
size_t ref_idx = pos_start - region->start;

for (size_t i=idx_start; i < (size_t)idx_end; ++i) {
if (i >= refSeqLen) {
if ((int)i >= refSeqLen) {
break;
}
char ref_base = lookup_ref_base[(unsigned char)refSeq[ref_idx]];
Expand Down Expand Up @@ -941,13 +941,15 @@ namespace Drawing {
}
}

} else {
} else if (nBlocks == 1) {
s = (double)a.blocks[0].start - regionBegin;
e = (double)a.blocks[0].end - regionBegin;
width = (e - s) * xScaling;
drawBlock(plotPointedPolygons, pointLeft, edged, (float) s * xScaling, (float) e, (float) width,
pointSlop, pH, yScaledOffset, xOffset, regionPixels, nBlocks, regionLen,
a, canvas, path, rect, faceColor, edgeColor);
} else {
continue;
}

// add soft-clip blocks
Expand Down
2 changes: 1 addition & 1 deletion src/plot_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ namespace Commands {
if (Utils::startsWith(command, "'") || Utils::startsWith(command, "\"")) {
command.erase(command.begin(), command.begin() + 1);
out << command << std::endl;
if (p->mode == Manager::Show::TILED && !p->variantTracks.empty() && p->currentVarTrack != nullptr) {
if (!p->variantTracks.empty() && p->currentVarTrack != nullptr) {
int i = p->mouseOverTileIndex + p->currentVarTrack->blockStart;
if (i < (int)p->currentVarTrack->multiLabels.size()) {
p->currentVarTrack->multiLabels[i].comment = command;
Expand Down
18 changes: 15 additions & 3 deletions src/plot_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace Manager {
if (variantTracks.empty()) {
return GLFW_KEY_UNKNOWN;
}

assert (variantFileSelection < variantTracks.size());
currentVarTrack = &variantTracks[variantFileSelection];
if (currentVarTrack == nullptr) {
return key;
Expand All @@ -123,6 +123,7 @@ namespace Manager {
processed = false;
imageCacheQueue.clear();
if (currentVarTrack->blockStart < (int)currentVarTrack->multiRegions.size()) {
assert (!currentVarTrack->multiRegions[currentVarTrack->blockStart].empty());
if (currentVarTrack->multiRegions[currentVarTrack->blockStart][0].chrom.empty()) {
return key; // check for "" no chrom set
} else {
Expand Down Expand Up @@ -1787,7 +1788,7 @@ namespace Manager {
commandToolTipIndex = -1;
}

float trackBoundary = totalCovY + refSpace + (trackY*(float)headers.size());
float trackBoundary = totalCovY + refSpace + (trackY*(float)headers.size()) + (gap * 0.5);
if (!tracks.empty()) {
if (std::fabs(yPos_fb - trackBoundary) < 5 * monitorScale) {
glfwSetCursor(window, vCursor);
Expand Down Expand Up @@ -1939,15 +1940,24 @@ namespace Manager {
return;
}
int targetIndex = (rs * -1) -3;
if (targetIndex >= (int)tracks.size()) {
return;
}
HGW::GwTrack &targetTrack = tracks[targetIndex];
float stepY = (totalTabixY) / (float)tracks.size();
if (regionSelection >= (int)regions.size() || targetIndex >= (int)regions[regionSelection].featureLevels.size()) {
return;
}
float step_track = (stepY) / ((float)regions[regionSelection].featureLevels[targetIndex]);
float y = fb_height - totalTabixY - refSpace; // start of tracks on canvas
int featureLevel = (int)(yPos_fb - y - (targetIndex * stepY)) / step_track;
Term::printTrack(relX, targetTrack, &regions[tIdx], true, featureLevel, targetIndex, target_qname, &target_pos, out);
}
}
if (rs < 0) { // print reference info
if (regionSelection >= (int)regions.size()) {
return;
}
float xScaling = (float)((regionWidth - gap - gap) / ((double)(regions[regionSelection].end -regions[regionSelection].start)));
float xOffset = (regionWidth * (float)regionSelection) + gap;
if (rs == REFERENCE_TRACK) {
Expand All @@ -1968,7 +1978,7 @@ namespace Manager {
}
return;
}

assert (rs < collections.size());
Segs::ReadCollection &cl = collections[rs];
regionSelection = cl.regionIdx;
int pos = (int) ((((double)xPos_fb - (double)cl.xOffset) / (double)cl.xScaling) + (double)cl.region->start);
Expand All @@ -1981,7 +1991,9 @@ namespace Manager {
}
updateCursorGenomePos(cl.xOffset, cl.xScaling, (float)xPos_fb, cl.region, cl.bamIdx);
} else if (mode == TILED) {
assert (variantFileSelection < variantTracks.size());
currentVarTrack = &variantTracks[variantFileSelection];
assert (currentVarTrack != nullptr);
int i = 0;
for (auto &b: bboxes) {
if (xPos_fb > b.xStart && xPos_fb < b.xEnd && yPos_fb > b.yStart && yPos_fb < b.yEnd) {
Expand Down
9 changes: 5 additions & 4 deletions src/plot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ namespace Manager {
void GwPlot::setScaling() { // sets z_scaling, y_scaling trackY and regionWidth
fonts.setOverlayHeight(monitorScale);
refSpace = fonts.overlayHeight * 1.25;
sliderSpace = std::fmax((float)(fb_height * 0.0175), 10*monitorScale);
sliderSpace = std::fmax((float)(fb_height * 0.0175), 10*monitorScale) + (gap * 0.5);
auto fbh = (float) fb_height;
auto fbw = (float) fb_width;
if (bams.empty()) {
Expand All @@ -839,11 +839,11 @@ namespace Manager {
}
if (nbams > 0 && samMaxY > 0) {
trackY = (fbh - totalCovY - totalTabixY - refSpace - sliderSpace) / nbams;

yScaling = ( (fbh - totalCovY - totalTabixY - refSpace - sliderSpace - (gap * nbams)) / (double)samMaxY) / nbams;
yScaling = (trackY - (gap * nbams)) / (double)samMaxY;
if (yScaling > 3 * monitorScale) {
yScaling = (int)yScaling;
}

} else {
trackY = 0;
yScaling = 0;
Expand Down Expand Up @@ -1384,7 +1384,7 @@ namespace Manager {
setGlfwFrameBufferSize();
setScaling();
float y_gap = (variantTracks.size() <= 1) ? 0 : (10 * monitorScale);
bboxes = Utils::imageBoundingBoxes(opts.number, fb_width, fb_height, 15, 15, y_gap);
bboxes = Utils::imageBoundingBoxes(opts.number, fb_width, fb_height, 6 * monitorScale, 6 * monitorScale, y_gap);
if (currentVarTrack->image_glob.empty()) {
tileDrawingThread(canvas, sContext, sSurface); // draws images from variant file
} else {
Expand Down Expand Up @@ -1515,6 +1515,7 @@ namespace Manager {
Drawing::drawRef(opts, regions, fb_width, canvas, fonts, refSpace, (float)regions.size(), gap);
Drawing::drawBorders(opts, fb_width, fb_height, canvas, regions.size(), bams.size(), trackY, covY, (int)tracks.size(), totalTabixY, refSpace, gap);
Drawing::drawTracks(opts, fb_width, fb_height, canvas, totalTabixY, tabixY, tracks, regions, fonts, gap, monitorScale);
Drawing::drawChromLocation(opts, regions, ideogram, canvas, fai, fb_width, fb_height, monitorScale);
}

void GwPlot::runDraw() {
Expand Down

0 comments on commit 1642994

Please sign in to comment.