Skip to content

Commit

Permalink
Merge pull request #28 from kcleal/gw_dev
Browse files Browse the repository at this point in the history
Gw v0.10.1
  • Loading branch information
kcleal authored Jul 12, 2024
2 parents b4f4706 + 1642994 commit 24e7997
Show file tree
Hide file tree
Showing 21 changed files with 801 additions and 231 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: 0.10.0
version: 0.10.1

jobs:
mingw:
Expand Down
1 change: 1 addition & 0 deletions .gw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ print_screen=PRINT_SCREEN
find_alignments=F
repeat_command=R
vcf_as_tracks=false
bed_as_tracks=true

[labelling]
number=3x3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ifneq ($(PLATFORM), "Windows")
else # Darwin / Linux
CPPFLAGS += -I./lib/skia
SKIA_PATH = ./lib/skia/out/Release-x64
LDFLAGS=

endif
endif

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=0.10.0
Version=0.10.1
Type=Application
Terminal=true
Exec=bash -c "/usr/bin/gw"
Expand Down
31 changes: 21 additions & 10 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ namespace Drawing {
float yOffsetAll = refSpace;

for (auto &cl: collections) {
if (cl.skipDrawingReads && cl.skipDrawingCoverage) {
continue;
}
cl.skipDrawingCoverage = true;
if (cl.region->markerPos != -1) {
float rp = refSpace + 6 + (cl.bamIdx * cl.yPixels);
Expand Down Expand Up @@ -215,6 +212,7 @@ namespace Drawing {
}

int i = 0;
int refSeqLen = cl.region->refSeqLen;
for (const auto &mm: mmVector) {
float cum_h = 0;
float mm_h;
Expand Down Expand Up @@ -254,6 +252,9 @@ namespace Drawing {
continue;
}
const SkPaint *paint_ref;
if (i >= refSeqLen) {
break;
}
switch (refSeq[i]) {
case 'A':
paint_ref = &theme.fcA;
Expand Down Expand Up @@ -504,6 +505,7 @@ namespace Drawing {
uint8_t *ptr_qual = bam_get_qual(align.delegate);

const char *refSeq = region->refSeq;
int refSeqLen = region->refSeqLen;

float precalculated_xOffset_mmPosOffset = xOffset + mmPosOffset;

Expand All @@ -530,6 +532,9 @@ namespace Drawing {
size_t ref_idx = pos_start - region->start;

for (size_t i=idx_start; i < (size_t)idx_end; ++i) {
if ((int)i >= refSeqLen) {
break;
}
char ref_base = lookup_ref_base[(unsigned char)refSeq[ref_idx]];
char bam_base = bam_seqi(ptr_seq, i);
if (bam_base != ref_base) {
Expand Down Expand Up @@ -936,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 Expand Up @@ -1195,8 +1202,6 @@ namespace Drawing {
float textW = fonts.overlayWidth;
float minLetterSize = (textW > 0) ? ((float) fb_width / (float) regions.size()) / textW : 0;
int index = 0;
//h *= 0.7;
// h = (h - 6 < 4) ? 4 : h - 6;
float yp = h + 2;
for (auto &rgn: regions) {
int size = rgn.end - rgn.start;
Expand Down Expand Up @@ -1403,8 +1408,14 @@ namespace Drawing {
}

if (label.i != label.ori_i) {

canvas->drawRect(rect, opts.theme.lcJoins);
}
if (!label.comment.empty()) {
bg.setXYWH(rect.right() - fonts.overlayHeight - (4*pad), rect.bottom() - fonts.overlayHeight - pad - pad - pad - pad, fonts.overlayHeight,
fonts.overlayHeight);
canvas->drawRoundRect(bg, fonts.overlayHeight, fonts.overlayHeight, opts.theme.fcG);
}
}

void drawTrackBigWig(HGW::GwTrack &trk, const Utils::Region &rgn, SkRect &rect, float padX, float padY,
Expand Down Expand Up @@ -1868,8 +1879,8 @@ namespace Drawing {
float regionIdx = 0;
for (const auto& region: regions) {

float s = (float)region.start / (float)region.chromLength;
float e = (float)region.end / (float)region.chromLength;
float s = (float)region.start / (float)region.chromLen;
float e = (float)region.end / (float)region.chromLen;
float w = (e - s) * drawWidth;
if (w < 3) {
w = 3;
Expand All @@ -1885,8 +1896,8 @@ namespace Drawing {
if (it != ideogram.end()) {
const std::vector<Themes::Band>& bands = it->second;
for (const auto& b : bands) {
float sb = (float) b.start / (float)region.chromLength;
float eb = (float) b.end / (float)region.chromLength;
float sb = (float) b.start / (float)region.chromLen;
float eb = (float) b.end / (float)region.chromLen;
float wb = (eb - sb) * drawWidth;
rect.setXYWH(xp + (sb * drawWidth),
top + yh_one_third,
Expand Down
6 changes: 4 additions & 2 deletions src/hts_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ namespace HGW {
// variant id is either recorded in the filename, or else is the whole filename
void GwVariantTrack::appendImageLabels(int startIdx, int number) {
// rid is the file name for an image
std::string empty_comment;
for (int i=startIdx; i < startIdx + number; ++i) {
if (i < (int)multiLabels.size()) {
continue;
Expand All @@ -2057,7 +2058,7 @@ namespace HGW {
if (inputLabels->contains(key)) {
multiLabels.push_back((*inputLabels)[key]);
} else {
multiLabels.push_back(Utils::makeLabel(info.chrom, info.pos, label, labelChoices, key, info.varType, "", false, false));
multiLabels.push_back(Utils::makeLabel(info.chrom, info.pos, label, labelChoices, key, info.varType, "", false, false, empty_comment));
}
}
}
Expand All @@ -2067,6 +2068,7 @@ namespace HGW {
std::vector<Utils::Region> v;
bool isTrans = chrom != chrom2;
Utils::Region* r1; Utils::Region* r2;
std::string empty_comment;
if (!isTrans && rlen <= m_opts->split_view_size) {
v.resize(1);
r1 = & v[0];
Expand Down Expand Up @@ -2094,7 +2096,7 @@ namespace HGW {
if (inputLabels->contains(rid)) {
multiLabels.push_back((*inputLabels)[rid]);
} else {
multiLabels.push_back(Utils::makeLabel(chrom, start, label, labelChoices, rid, vartype, "", false, false));
multiLabels.push_back(Utils::makeLabel(chrom, start, label, labelChoices, rid, vartype, "", false, false, empty_comment));
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void print_banner() {
#endif
}

// 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] = "0.10.1";


int main(int argc, char *argv[]) {

Expand All @@ -83,8 +86,7 @@ int main(int argc, char *argv[]) {
static const std::vector<std::string> img_themes = { "igv", "dark", "slate" };
static const std::vector<std::string> links = { "none", "sv", "all" };

// note to developer - update version in workflows/main.yml, menu.cpp and deps/gw.desktop, and installers .md in docs
argparse::ArgumentParser program("gw", "0.10.0");
argparse::ArgumentParser program("gw", std::string(GW_VERSION));

program.add_argument("genome")
.default_value(std::string{""}).append()
Expand Down Expand Up @@ -376,6 +378,8 @@ int main(int argc, char *argv[]) {
if (program.is_used("-b")) {
auto bam_paths_temp = program.get<std::vector<std::string>>("-b");
for (auto &item : bam_paths_temp) {
bam_paths.push_back(item);
continue;
if (std::filesystem::exists(item)) {
bam_paths.push_back(item);
std::cerr << item << std::endl;
Expand Down Expand Up @@ -529,6 +533,8 @@ int main(int argc, char *argv[]) {
std::exit(-1);
}
iopts.getOptionsFromSessionIni(iopts.seshIni);
} else {
iopts.session_file = "";
}
/*
* / Gw start
Expand Down Expand Up @@ -659,7 +665,6 @@ int main(int argc, char *argv[]) {
if (program.is_used("--out-labels")) {
plotter.setOutLabelFile(program.get<std::string>("--out-labels"));
}

plotter.addVariantTrack(img, iopts.start_index, false, true);
if (plotter.variantTracks.back().image_glob.size() == 1) {
plotter.opts.number.x = 1; plotter.opts.number.y = 1;
Expand Down Expand Up @@ -933,6 +938,7 @@ int main(int argc, char *argv[]) {
std::string dateStr;

std::string fileName;
std::string empty_comment;
std::filesystem::path fsp(vcf.path);
#if defined(_WIN32) || defined(_WIN64)
const wchar_t* pc = fsp.filename().c_str();
Expand All @@ -956,7 +962,7 @@ int main(int argc, char *argv[]) {
job.rid = vcf.rid;
jobs.push_back(job);
if (writeLabel) {
Utils::Label l = Utils::makeLabel(vcf.chrom, vcf.start, vcf.label, empty_labels, vcf.rid, vcf.vartype, "", false, false);
Utils::Label l = Utils::makeLabel(vcf.chrom, vcf.start, vcf.label, empty_labels, vcf.rid, vcf.vartype, "", false, false, empty_comment);
Utils::labelToFile(fLabels, l, dateStr, fileName);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ namespace Menu {
}
// write tool tip
std::string tip;

if (opts.control_level.empty()) {
if (opts.menu_table == Themes::MenuTable::MAIN) {
tip = opts.ini_path + " v0.10.0";
tip = opts.ini_path + " v0.10.1";
}
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 All @@ -294,7 +295,8 @@ namespace Menu {
else if (opts.menu_level == "coverage") { tip = "Turn coverage on or off [true, false]"; }
else if (opts.menu_level == "log2_cov") { tip = "Change the y-scale of the coverage track to log2 [true, false]"; }
else if (opts.menu_level == "expand_tracks") { tip = "Expand overlapping track features [true, false]"; }
else if (opts.menu_level == "vcf_as_tracks") { tip = "Drag-and-dropped vcf/bcf files will be added as track features [true, false]"; }
else if (opts.menu_level == "vcf_as_tracks") { tip = "Drag-and-dropped vcf/bcf files will be added as a track if true, or image-tiles otherwise [true, false]"; }
else if (opts.menu_level == "bed_as_tracks") { tip = "Drag-and-dropped bed files will be added as a track if true, or image-tiles otherwise [true, false]"; }
else if (opts.menu_level == "link") { tip = "Change which reads are linked [none, sv, all]"; }
else if (opts.menu_level == "split_view_size") { tip = "Structural variants greater than this size will be drawn as two regions"; }
else if (opts.menu_level == "threads") { tip = "The number of threads to use for file readings"; }
Expand Down Expand Up @@ -682,7 +684,7 @@ namespace Menu {
for (const auto& v : {"scroll_speed", "tabix_track_height"}) {
option_map[v] = Float;
}
for (const auto& v : {"coverage", "log2_cov", "expand_tracks", "vcf_as_tracks", "sv_arcs", "mods"}) {
for (const auto& v : {"coverage", "log2_cov", "expand_tracks", "vcf_as_tracks", "bed_as_tracks", "sv_arcs", "mods"}) {
option_map[v] = Bool;
}
for (const auto& v : {"scroll_right", "scroll_left", "zoom_out", "zoom_in", "scroll_down", "scroll_up", "cycle_link_mode", "print_screen", "find_alignments", "delete_labels", "enter_interactive_mode"}) {
Expand Down Expand Up @@ -755,6 +757,7 @@ namespace Menu {
else if (new_opt.name == "log2_cov") { opts.log2_cov = v; }
else if (new_opt.name == "expand_tracks") { opts.expand_tracks = v; }
else if (new_opt.name == "vcf_as_tracks") { opts.vcf_as_tracks = v; }
else if (new_opt.name == "bed_as_tracks") { opts.bed_as_tracks = v; }
else if (new_opt.name == "coverage") { opts.max_coverage = (v) ? 1410065408 : 0; }
else if (new_opt.name == "sv_arcs") { opts.sv_arcs = v; }
else if (new_opt.name == "mods") { opts.parse_mods = v; }
Expand Down
4 changes: 2 additions & 2 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace Menu {

std::vector<std::string> getCommandTip();

constexpr std::array<const char*, 27> commandToolTip = {"ylim", "var", "tlen-y", "tags", "soft-clips", "snapshot", "sam", "remove",
"refresh", "online", "mods", "mismatches", "mate", "mate add", "log2-cov", "link", "line", "insertions", "indel-length",
constexpr std::array<const char*, 28> commandToolTip = {"ylim", "var", "tlen-y", "tags", "soft-clips", "save", "sam", "remove",
"refresh", "online", "mods", "mismatches", "mate", "mate add", "log2-cov", "load", "link", "line", "insertions", "indel-length",
"grid", "find", "filter", "expand-tracks", "edges", "cov", "count", "add"};

constexpr std::array<const char*, 16> exec = {"cov", "count", "edges", "expand-tracks", "insertions", "line", "log2-cov", "mate", "mate add", "mismatches", "mods", "tags", "soft-clips", "sam", "refresh", "tlen-y"};
Expand Down
22 changes: 17 additions & 5 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace Parse {

constexpr std::string_view numeric_like = "eq ne gt lt ge le == != > < >= <=";
constexpr std::string_view string_like = "eq ne contains == != omit";
constexpr std::string_view numeric_like = "eq ne gt lt ge le = == != > < >= <=";
constexpr std::string_view string_like = "eq ne contains = == != omit";

Parser::Parser(std::ostream& errOutput) : out(errOutput) {
opMap["mapq"] = MAPQ;
Expand Down Expand Up @@ -66,6 +66,7 @@ namespace Parse {
opMap["ge"] = GE;
opMap["le"] = LE;
opMap["=="] = EQ;
opMap["="] = EQ;
opMap["!="] = NE;
opMap[">"] = GT;
opMap["<"] = LT;
Expand Down Expand Up @@ -976,6 +977,14 @@ namespace Parse {

void tryTabCompletion(std::string &inputText, std::ostream& out, int& charIndex) {
std::vector<std::string> parts = Utils::split(inputText, ' ');
if (parts.size() == 3) { // chunk first two options
std::string tmp = parts[0];
std::string tmp2 = parts[1];
std::string tmp3 = parts[2];
parts[0] = tmp + " " + tmp2;
parts[1] = tmp3;
parts.resize(2);
}
std::string globstr;
if (parts.back() == "./") {
globstr = "./*";
Expand All @@ -986,6 +995,9 @@ namespace Parse {
std::vector<std::filesystem::path> glob_paths = glob_cpp::glob(globstr);
if (glob_paths.size() == 1) {
inputText = parts[0] + " " + glob_paths[0].generic_string();
if (std::filesystem::is_directory(glob_paths[0])) {
inputText += std::filesystem::path::preferred_separator;
}
charIndex = inputText.size();
return;
}
Expand All @@ -998,6 +1010,7 @@ namespace Parse {
return;
}
inputText = parts[0] + " " + lcp;

charIndex = inputText.size();
size_t width = (size_t)Utils::get_terminal_width() - 1;
size_t i = 0;
Expand All @@ -1009,18 +1022,17 @@ namespace Parse {
} else {
if (width > 6 && s.size() > 6) {
s.erase(s.begin() + width - 4, s.end());
out << s << " ...";
out << s << " ..."; out.flush();
}
break;
}
if (i < glob_paths.size() - 2 && width > 2) {
out << " ";
out << " "; out.flush();
width -= 2;
} else {
break;
}
}
out.flush();
return;
}
}
Loading

0 comments on commit 24e7997

Please sign in to comment.