Skip to content

Commit

Permalink
Better error messages from vg haplotypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jltsiren committed Oct 17, 2023
1 parent 49cc69c commit dd2fada
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deps/kff-cpp-api
Submodule kff-cpp-api updated 3 files
+1 −0 .gitignore
+2 −2 CMakeLists.txt
+5 −1 kff_io.cpp
2 changes: 1 addition & 1 deletion src/kff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ParallelKFFReader {
typedef gbwtgraph::Key64::value_type kmer_type;

/// Creates a new reader for the given file. Throws `std::runtime_error` if the
/// sanity checks fail.
/// file cannot be opened or the sanity checks fail.
ParallelKFFReader(const std::string& filename);

/// Reads the next `n` kmers and counts from the file. This can be called safely
Expand Down
31 changes: 24 additions & 7 deletions src/subcommand/haplotypes_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ int main_haplotypes(int argc, char** argv) {
if (config.verbosity >= Haplotypes::verbosity_basic) {
std::cerr << "Loading haplotype information from " << config.haplotype_input << std::endl;
}
sdsl::simple_sds::load_from(haplotypes, config.haplotype_input);
try {
sdsl::simple_sds::load_from(haplotypes, config.haplotype_input);
} catch (const std::runtime_error& e) {
std::cerr << "error: [vg haplotypes] " << e.what() << std::endl;
std::exit(EXIT_FAILURE);
}
}

// Save haplotype information if necessary.
Expand Down Expand Up @@ -518,7 +523,7 @@ void preprocess_graph(const gbwtgraph::GBZ& gbz, Haplotypes& haplotypes, Haploty
haplotypes = partitioner.partition_haplotypes(config.partitioner_parameters);
}
catch (const std::runtime_error& e) {
std::cerr << e.what() << std::endl;
std::cerr << "error: [vg haplotypes] " << e.what() << std::endl;
std::exit(EXIT_FAILURE);
}
if (config.verbosity >= Haplotypes::verbosity_basic) {
Expand All @@ -544,7 +549,13 @@ void validate_subgraph(const gbwtgraph::GBWTGraph& graph, const gbwtgraph::GBWTG
void sample_haplotypes(const gbwtgraph::GBZ& gbz, const Haplotypes& haplotypes, const HaplotypesConfig& config) {
omp_set_num_threads(threads_to_jobs(config.threads));
Recombinator recombinator(gbz, config.verbosity);
gbwt::GBWT merged = recombinator.generate_haplotypes(haplotypes, config.kmer_input, config.recombinator_parameters);
gbwt::GBWT merged;
try {
merged = recombinator.generate_haplotypes(haplotypes, config.kmer_input, config.recombinator_parameters);
} catch (const std::runtime_error& e) {
std::cerr << "error: [vg haplotypes] " << e.what() << std::endl;
std::exit(EXIT_FAILURE);
}
omp_set_num_threads(config.threads); // Restore the number of threads.

// Build and serialize GBWTGraph.
Expand Down Expand Up @@ -860,10 +871,16 @@ void extract_haplotypes(const gbwtgraph::GBZ& gbz, const Haplotypes& haplotypes,
}

Recombinator recombinator(gbz, config.verbosity);
auto result = recombinator.extract_sequences(
haplotypes, config.kmer_input,
config.chain_id, config.subchain_id, config.recombinator_parameters
);
std::vector<Recombinator::LocalHaplotype> result;
try {
result = recombinator.extract_sequences(
haplotypes, config.kmer_input,
config.chain_id, config.subchain_id, config.recombinator_parameters
);
} catch (const std::runtime_error& e) {
std::cerr << "error: [vg haplotypes] " << e.what() << std::endl;
std::exit(EXIT_FAILURE);
}
if (config.verbosity >= Haplotypes::verbosity_detailed) {
std::cerr << "Found " << result.size() << " haplotypes" << std::endl;
}
Expand Down

1 comment on commit dd2fada

@adamnovak
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for branch vg-haplotypes-errors. View the full report here.

16 tests passed, 0 tests failed and 0 tests skipped in 17543 seconds

Please sign in to comment.