Skip to content

Commit

Permalink
Work on session files
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Jun 4, 2024
1 parent 357d9b3 commit 356ee51
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .gw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ tabix_track_height=0.3
font=Menlo
font_size=14
sv_arcs=true
session_file=

[view_thresholds]
soft_clip=20000
small_indel=100000
snp=500000
edge_highlights=100000
edge_highlights=1000000
variant_distance=100000
low_memory=1500000

Expand Down
69 changes: 44 additions & 25 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int main(int argc, char *argv[]) {
if (!success) {

}
bool have_session_file = !iopts.session_file.empty();

static const std::vector<std::string> img_fmt = { "png", "pdf", "svg" };
static const std::vector<std::string> img_themes = { "igv", "dark", "slate" };
Expand Down Expand Up @@ -211,6 +212,8 @@ int main(int argc, char *argv[]) {
.default_value(false).implicit_value(true)
.help("Display path of loaded .gw.ini config");

bool show_banner = true;

// check input for errors and merge input options with IniOptions
try {
program.parse_args(argc, argv);
Expand All @@ -225,7 +228,10 @@ int main(int argc, char *argv[]) {
return 0;
}

std::vector<std::string> bam_paths;
std::vector<std::string> tracks;
std::vector<Utils::Region> regions;

if (program.is_used("-r")) {
std::vector<std::string> regions_str;
regions_str = program.get<std::vector<std::string>>("-r");
Expand All @@ -234,8 +240,6 @@ int main(int argc, char *argv[]) {
}
}

std::vector<std::string> bam_paths;

// check if bam/cram file provided as main argument
auto genome = program.get<std::string>("genome");
if (Utils::endsWith(genome, ".bam") || Utils::endsWith(genome, ".cram")) {
Expand All @@ -245,16 +249,15 @@ int main(int argc, char *argv[]) {
}
}

bool show_banner = true;

if (iopts.myIni["genomes"].has(genome)) {
iopts.genome_tag = genome;
genome = iopts.myIni["genomes"][genome];
} else if (genome.empty() && !program.is_used("--images") && !iopts.ini_path.empty() && !program.is_used("--no-show")) {
// prompt for genome
print_banner();
show_banner = false;
std::cout << "\n Reference genomes listed in " << iopts.ini_path << std::endl << std::endl;

std::cout << "\nReference genomes listed in " << iopts.ini_path << std::endl << std::endl;
std::string online = "https://github.com/kcleal/ref_genomes/releases/download/v0.1.0";
#if defined(_WIN32) || defined(_WIN64) || defined(__MSYS__)
const char *block_char = "*";
Expand All @@ -264,7 +267,7 @@ int main(int argc, char *argv[]) {
std::cout << " " << block_char << " " << online << std::endl << std::endl;
int i = 0;
int tag_wd = 11;
std::vector<std::string> vals;
std::vector<std::pair<std::string, std::string>> vals;

#if defined(_WIN32) || defined(_WIN64) || defined(__MSYS__)
std::cout << " Number | Genome-tag | Path \n";
Expand Down Expand Up @@ -297,32 +300,51 @@ int main(int argc, char *argv[]) {
} else {
std::cout << g_path << std::endl;
}
vals.push_back(rg.second);
vals.push_back(rg); //rg.second);
i += 1;
}
if (i == 0) {
if (i == 0 && !have_session_file) {
std::cerr << "No genomes listed, finishing\n";
std::exit(0);
}
std::cout << "\n Enter number: " << std::flush;
int user_i;
std::cin >> user_i;
std::cerr << std::endl;
assert (user_i >= 0 && (int)user_i < vals.size());
try {
genome = vals[user_i];
} catch (...) {
std::cerr << "Something went wrong\n";
std::exit(-1);
user_prompt:
if (have_session_file) {
std::cout << "\nPress ENTER to load previous session or input a genome number: " << std::flush;

} else {
std::cout << "\nEnter genome number: " << std::flush;
}

std::string user_input;
std::getline(std::cin, user_input);
size_t user_i = 0;
if (user_input == "q" || user_input == "quit" || user_input == "exit") {
std::exit(0);
}
if (user_input.empty()) {
if (have_session_file) {
// load_from_session(bam_paths, tracks, regions, iopts, genome);
} else {
goto user_prompt;
}
} else {
try {
user_i = std::stoi(user_input);
genome = vals[user_i].second;
iopts.genome_tag = vals[user_i].first;
std::cout << "Genome: " << iopts.genome_tag << std::endl;
} catch (...) {
goto user_prompt;
}
if (user_i < 0 || user_i > vals.size() -1) {
goto user_prompt;
}
}
assert (Utils::is_file_exist(genome));
iopts.genome_tag = genome;

} else if (!genome.empty() && !Utils::is_file_exist(genome)) {
std::cerr << "Loading remote genome" << std::endl;
}

std::vector<std::string> tracks;
if (program.is_used("--track")) {
tracks = program.get<std::vector<std::string>>("--track");
for (auto &trk: tracks){
Expand Down Expand Up @@ -351,7 +373,7 @@ int main(int argc, char *argv[]) {
}
}
}
if (!program.is_used("genome") && genome.empty() && !bam_paths.empty()) {
if (!have_session_file && !program.is_used("genome") && genome.empty() && !bam_paths.empty()) {
HGW::guessRefGenomeFromBam(genome, iopts, bam_paths, regions);
if (genome.empty()) {
std::exit(0);
Expand Down Expand Up @@ -459,9 +481,6 @@ int main(int argc, char *argv[]) {
if (program.is_used("--no-soft-clips")) {
iopts.soft_clip_threshold = 0;
}
// if (program.is_used("--low-mem")) {
// iopts.low_mem = true;
// }
if (program.is_used("--start-index")) {
iopts.start_index = program.get<int>("--start-index");
}
Expand Down
3 changes: 1 addition & 2 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ namespace Menu {
opts.control_level = "close";
opts.menu_table = Themes::MenuTable::MAIN;
opts.previous_level = opts.menu_level;
mINI::INIFile file(opts.ini_path);
file.write(opts.myIni);
opts.saveIniChanges();
std::cout << "Saved .gw.ini to " << opts.ini_path << std::endl;
return false;
} else if (opts.control_level == "delete") {
Expand Down
27 changes: 12 additions & 15 deletions src/plot_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,18 @@ namespace Commands {
Err link(Plot* p, std::string& command, std::vector<std::string>& parts) {
bool relink = false;
if (command == "link" || command == "link all") {
relink = (p->opts.link_op != 2) ? true : false;
relink = p->opts.link_op != 2;
p->opts.link_op = 2;
p->opts.link = "all";
} else if (parts.size() == 2) {
if (parts[1] == "sv") {
relink = (p->opts.link_op != 1) ? true : false;
relink = p->opts.link_op != 1;
p->opts.link_op = 1;
p->opts.link = "sv";
} else if (parts[1] == "none") {
relink = (p->opts.link_op != 0) ? true : false;
relink = p->opts.link_op != 0;
p->opts.link_op = 0;
p->opts.link = "none";
}
}
if (relink) {
Expand Down Expand Up @@ -509,16 +512,13 @@ namespace Commands {
}

Err setYlim(Plot* p, std::vector<std::string> parts, std::ostream& out) {
int ylim = p->opts.ylim;
int samMaxY = p->opts.ylim;
int max_tlen = p->opts.max_tlen;
try {
if (!p->opts.tlen_yscale) {
ylim = std::stoi(parts.back());
samMaxY = p->opts.ylim;
p->opts.ylim = std::stoi(parts.back());
p->samMaxY = p->opts.ylim;
} else {
max_tlen = std::stoi(parts.back());
samMaxY = p->opts.max_tlen;
p->opts.max_tlen = std::stoi(parts.back());
p->samMaxY = p->opts.max_tlen;
}
} catch (...) {
out << termcolor::red << "Error:" << termcolor::reset << " ylim invalid value\n";
Expand All @@ -528,14 +528,11 @@ namespace Commands {
HGW::refreshLinked(p->collections, p->opts, &p->samMaxY);
p->processed = true;
p->redraw = true;
p->opts.ylim = ylim;
p->samMaxY = samMaxY;
p->opts.max_tlen = max_tlen;
return Err::NONE;
}

Err indelLength(Plot* p, std::vector<std::string> parts, std::ostream& out) {
int indel_length = p->opts.indel_length;
int indel_length;
try {
indel_length = std::stoi(parts.back());
} catch (...) {
Expand Down Expand Up @@ -1039,7 +1036,7 @@ namespace Commands {
if (reason == Err::NONE) {
int res = faidx_has_seq(p->fai, rgn.chrom.c_str());
if (res <= 0) {
reason = Err::CHROM_NOT_IN_REFERENCE;
return Err::OPTION_NOT_UNDERSTOOD;
}
if (p->mode != Manager::Show::SINGLE) { p->mode = Manager::Show::SINGLE; }
if (p->regions.empty()) {
Expand Down
Loading

0 comments on commit 356ee51

Please sign in to comment.