Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giraffe integration for haplotype sampling #4053

Merged
merged 5 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/recombinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,15 +1033,46 @@ double get_or_estimate_coverage(
count_to_frequency[iter->second]++;
}
}

// Use mode as the initial estimate for coverage.
auto statistics = summary_statistics(count_to_frequency);
double coverage = std::max(statistics.median, statistics.mode);
double coverage = statistics.mode;
bool reliable = true;
if (verbosity >= Haplotypes::verbosity_detailed) {
std::cerr << "Coverage: median " << statistics.median
<< ", mean " << statistics.mean
<< ", stdev " << statistics.stdev
<< ", mode " << statistics.mode
<< "; using " << coverage << std::endl;
<< ", mode " << statistics.mode;
}

// If mode < median, try to find a secondary peak at ~2x mode and use
// it if it is good enough.
if (statistics.mode < statistics.median) {
size_t low = 1.7 * statistics.mode, high = 2.3 * statistics.mode;
size_t peak = count_to_frequency[coverage];
size_t best = low, secondary = count_to_frequency[low];
for (size_t i = low + 1; i <= high; i++) {
if (count_to_frequency[i] > secondary) {
best = i; secondary = count_to_frequency[i];
}
}
if (verbosity >= Haplotypes::verbosity_detailed) {
std::cerr << "; secondary peak at " << best;
}
if (best >= size_t(statistics.median) && secondary >= peak / 2) {
coverage = best;
} else {
reliable = false;
}
}

if (verbosity >= Haplotypes::verbosity_detailed) {
std::cerr << "; using " << coverage << std::endl;
}
if (!reliable) {
std::cerr << "warning: Kmer coverage estimate is unreliable" << std::endl;
}

if (verbosity >= Haplotypes::verbosity_basic) {
double seconds = gbwt::readTimer() - start;
std::cerr << "Estimated kmer coverage in " << seconds << " seconds" << std::endl;
Expand Down
255 changes: 205 additions & 50 deletions src/subcommand/giraffe_main.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/subcommand/haplotypes_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ HaplotypesConfig::HaplotypesConfig(int argc, char** argv, size_t max_threads) {
{
std::string arg = optarg;
size_t offset = arg.find(':');
if (offset == 0 || offset + 1 >= arg.length()) {
if (offset == 0 || offset == std::string::npos || offset + 1 >= arg.length()) {
std::cerr << "error: [vg haplotypes] cannot parse chain:subchain from " << arg << std::endl;
std::exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -519,6 +519,7 @@ void preprocess_graph(const gbwtgraph::GBZ& gbz, Haplotypes& haplotypes, Haploty
validate_haplotypes(haplotypes, gbz.graph, r_index, minimizer_index, expected_chains, config.verbosity);
}
}

//----------------------------------------------------------------------------

size_t threads_to_jobs(size_t threads) {
Expand Down
9 changes: 9 additions & 0 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,15 @@ pair<string, string> split_ext(const string& filename) {
return parts;
}

string file_base_name(const string& filename) {
size_t slash = filename.rfind('/');
if (slash == string::npos) {
return split_ext(filename).first;
} else {
return split_ext(filename.substr(slash + 1)).first;
}
}

bool file_exists(const string& filename) {
// TODO: use C++17 features to actually poll existence.
// For now we see if we can open it.
Expand Down
3 changes: 3 additions & 0 deletions src/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ void get_input_file(const string& file_name, function<void(istream&)> callback);
/// Split off the extension from a filename and return both parts.
pair<string, string> split_ext(const string& filename);

/// Get the base name of a filename (without the directory and the extension).
string file_base_name(const string& filename);

/// Determine if a file exists.
/// Only works for files readable by the current user.
bool file_exists(const string& filename);
Expand Down
Binary file added test/haplotype-sampling/HG003.fq.gz
Binary file not shown.
Binary file added test/haplotype-sampling/HG003.kff
Binary file not shown.
Loading
Loading