vg
tools for working with variation graphs
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
vg::VCFOutputCaller Class Reference

#include <graph_caller.hpp>

Inheritance diagram for vg::VCFOutputCaller:
vg::Deconstructor vg::FlowCaller vg::LegacyCaller vg::MCMCCaller vg::NestedFlowCaller vg::VCFGenotyper

Public Member Functions

 VCFOutputCaller (const string &sample_name)
 
virtual ~VCFOutputCaller ()
 
virtual string vcf_header (const PathHandleGraph &graph, const vector< string > &contigs, const vector< size_t > &contig_length_overrides) const
 Write the vcf header (version and contigs and basic info) More...
 
bool add_variant (vcflib::Variant &var) const
 
void write_variants (ostream &out_stream, const SnarlManager *snarl_manager=nullptr)
 
void vcf_fixup (vcflib::Variant &var) const
 Run vcffixup from vcflib. More...
 
void set_translation (const unordered_map< nid_t, pair< string, size_t >> *translation)
 Add a translation map. More...
 
void set_nested (bool nested)
 Assume writing nested snarls is enabled. More...
 
void set_allele_merge (double threshold, int64_t min_len)
 
unordered_set< string > get_output_contigs () const
 
string prune_header_contigs (const string &header, const unordered_set< string > &keep) const
 

Protected Member Functions

void add_allele_path_to_info (const HandleGraph *graph, vcflib::Variant &v, int allele, const Traversal &trav, bool reversed, bool one_based) const
 add a traversal to the VCF info field in the format of a GFA W-line or GAF path More...
 
void add_allele_path_to_info (vcflib::Variant &v, int allele, const SnarlTraversal &trav, bool reversed, bool one_based) const
 legacy version of above More...
 
string trav_string (const HandleGraph &graph, const SnarlTraversal &trav) const
 convert a traversal into an allele string More...
 
bool merge_similar_alleles (const PathPositionHandleGraph &graph, const vector< SnarlTraversal > &site_traversals, vector< int > &site_genotype, const string &sample_name, vcflib::Variant &out_variant) const
 
bool emit_variant (const PathPositionHandleGraph &graph, SnarlCaller &snarl_caller, const Snarl &snarl, const vector< SnarlTraversal > &called_traversals, const vector< int > &genotype, int ref_trav_idx, const unique_ptr< SnarlCaller::CallInfo > &call_info, const string &ref_path_name, int ref_offset, bool genotype_snarls, int ploidy, function< string(const vector< SnarlTraversal > &, const vector< int > &, int, int, int)> trav_to_string=nullptr)
 
tuple< int64_t, int64_t, bool, step_handle_t, step_handle_tget_ref_interval (const PathPositionHandleGraph &graph, const Snarl &snarl, const string &ref_path_name) const
 
pair< string, int64_t > get_ref_position (const PathPositionHandleGraph &graph, const Snarl &snarl, const string &ref_path_name, int64_t ref_path_offset) const
 used for making gaf traversal names More...
 
void flatten_common_allele_ends (vcflib::Variant &variant, bool backward, size_t len_override) const
 
string print_snarl (const HandleGraph *grpah, const handle_t &snarl_start, const handle_t &snarl_end, bool in_brackets=false) const
 
string print_snarl (const Snarl &snarl, bool in_brackets=false) const
 legacy version of above More...
 
string print_flipped_snarl (const Snarl &snarl, bool in_brackets=false) const
 The same as above, but print the snarl as if its orientation has been flipped. More...
 
void scan_snarl (const string &allele_string, function< void(const string &, Snarl &)> callback) const
 
void update_nesting_info_tags (const SnarlManager *snarl_manager)
 

Static Protected Member Functions

static bool snarl_traversal_to_handles (const HandleGraph &graph, const SnarlTraversal &trav, Traversal &out_trav)
 
static int64_t allele_core_length (const vector< string > &alleles)
 

Protected Attributes

vcflib::VariantCallFile output_vcf
 output vcf More...
 
string sample_name
 Sample name. More...
 
vector< vector< pair< pair< string, size_t >, string > > > output_variants
 
size_t max_uncalled_alleles = 5
 print up to this many uncalled alleles when doing ref-genotpes in -a mode More...
 
const unordered_map< nid_t, pair< string, size_t > > * translation
 
bool include_nested
 
double allele_merge_threshold = 1.0
 
int64_t allele_merge_min_len = 0
 

Static Protected Attributes

static const int64_t max_vcf_line_length = 2000000000
 

Detailed Description

Helper class that vcf writers can inherit from to for some common code to output sorted VCF

Constructor & Destructor Documentation

◆ VCFOutputCaller()

vg::VCFOutputCaller::VCFOutputCaller ( const string &  sample_name)

◆ ~VCFOutputCaller()

vg::VCFOutputCaller::~VCFOutputCaller ( )
virtual

Member Function Documentation

◆ add_allele_path_to_info() [1/2]

void vg::VCFOutputCaller::add_allele_path_to_info ( const HandleGraph graph,
vcflib::Variant &  v,
int  allele,
const Traversal trav,
bool  reversed,
bool  one_based 
) const
protected

add a traversal to the VCF info field in the format of a GFA W-line or GAF path

◆ add_allele_path_to_info() [2/2]

void vg::VCFOutputCaller::add_allele_path_to_info ( vcflib::Variant &  v,
int  allele,
const SnarlTraversal trav,
bool  reversed,
bool  one_based 
) const
protected

legacy version of above

◆ add_variant()

bool vg::VCFOutputCaller::add_variant ( vcflib::Variant &  var) const

Add a variant to our buffer Returns false if the variant line length exceeds VCFOutputCaller::max_vcf_line_length

◆ allele_core_length()

int64_t vg::VCFOutputCaller::allele_core_length ( const vector< string > &  alleles)
staticprotected

The CORE LENGTH of a variant: the length of the longest allele after stripping the prefix and the suffix that every non-"*" allele shares. This is the single definition of "how big is this variant" behind –cluster-min-len in BOTH vg call and vg deconstruct. It is invariant to how much shared flanking context a caller keeps in its allele strings, which is the point: vg call flattens down to an anchor base while vg deconstruct emits the whole snarl interior, so a raw string length answers differently for the same variant. Consequences, all intended:

  • the anchor base flatten_common_allele_ends must leave on every indel is a shared prefix, so it is stripped: a 49bp indel measures 49, not 50.
  • REF participates, so a pure deletion measures the deleted length. A maximum over ALTs alone measures 1 for a deletion of any size.
  • "*" is a marker, not sequence, so it is excluded from both the affixes and the maximum. That also neutralizes flatten_common_allele_ends being a no-op whenever a "*" is present – without -a because min_allele_len becomes 1 and max_flatten_len decrements to 0, and with -a because "*" matches no base at the first offset compared. Either way the un-flattened boundary sequence is common to every real allele, so it is stripped here. Note this measures the SPAN of the variant, not the size of any one event inside it: a haplotype differing from the reference at two bases 59bp apart has a core length of 60.

◆ emit_variant()

bool vg::VCFOutputCaller::emit_variant ( const PathPositionHandleGraph graph,
SnarlCaller snarl_caller,
const Snarl snarl,
const vector< SnarlTraversal > &  called_traversals,
const vector< int > &  genotype,
int  ref_trav_idx,
const unique_ptr< SnarlCaller::CallInfo > &  call_info,
const string &  ref_path_name,
int  ref_offset,
bool  genotype_snarls,
int  ploidy,
function< string(const vector< SnarlTraversal > &, const vector< int > &, int, int, int)>  trav_to_string = nullptr 
)
protected

print a vcf variant return value is taken from add_variant (see above)

◆ flatten_common_allele_ends()

void vg::VCFOutputCaller::flatten_common_allele_ends ( vcflib::Variant &  variant,
bool  backward,
size_t  len_override 
) const
protected

clean up the alleles to not share common prefixes / suffixes if len_override given, just do that many bases without thinking

◆ get_output_contigs()

unordered_set< string > vg::VCFOutputCaller::get_output_contigs ( ) const

The set of reference contigs that actually have a record. Reads the sort keys of the output buffer, so it costs nothing (no decompression) and does not need the snarl tree. Only meaningful once calling is finished and before write_variants() drains the buffer.

◆ get_ref_interval()

tuple< int64_t, int64_t, bool, step_handle_t, step_handle_t > vg::VCFOutputCaller::get_ref_interval ( const PathPositionHandleGraph graph,
const Snarl snarl,
const string &  ref_path_name 
) const
protected

get the interval of a snarl from our reference path using the PathPositionHandleGraph interface the bool is true if the snarl's backward on the path first returned value -1 if no traversal found

◆ get_ref_position()

pair< string, int64_t > vg::VCFOutputCaller::get_ref_position ( const PathPositionHandleGraph graph,
const Snarl snarl,
const string &  ref_path_name,
int64_t  ref_path_offset 
) const
protected

used for making gaf traversal names

◆ merge_similar_alleles()

bool vg::VCFOutputCaller::merge_similar_alleles ( const PathPositionHandleGraph graph,
const vector< SnarlTraversal > &  site_traversals,
vector< int > &  site_genotype,
const string &  sample_name,
vcflib::Variant &  out_variant 
) const
protected

Merge near-identical called ALT alleles in an already-populated variant. Must run AFTER SnarlCaller::update_vcf_info and after flatten_common_allele_ends, so that the genotyper and the allele-flattening both see the full pre-merge allele set: merging earlier drops the absorbed allele's reads from AD/DP and from the Poisson caller's total_other_support term. Rewrites the allele-indexed fields (alleles/alt, AT, AD, GL, GT, MAD) and records what was merged in the MAT info field. Returns true if anything merged.

◆ print_flipped_snarl()

string vg::VCFOutputCaller::print_flipped_snarl ( const Snarl snarl,
bool  in_brackets = false 
) const
protected

The same as above, but print the snarl as if its orientation has been flipped.

◆ print_snarl() [1/2]

string vg::VCFOutputCaller::print_snarl ( const HandleGraph grpah,
const handle_t snarl_start,
const handle_t snarl_end,
bool  in_brackets = false 
) const
protected

print a snarl in a consistent form like >3435<12222 if in_brackets set to true, do (>3435<12222) instead (this is only used for nested caller)

◆ print_snarl() [2/2]

string vg::VCFOutputCaller::print_snarl ( const Snarl snarl,
bool  in_brackets = false 
) const
protected

legacy version of above

◆ prune_header_contigs()

string vg::VCFOutputCaller::prune_header_contigs ( const string &  header,
const unordered_set< string > &  keep 
) const

Remove ##contig lines whose ID is not in keep, leaving every other line alone. A reference contig that produced no record is not worth declaring: with a gref cover most contigs are fragments, and on a human chromosome a third of them carry nothing.

◆ scan_snarl()

void vg::VCFOutputCaller::scan_snarl ( const string &  allele_string,
function< void(const string &, Snarl &)>  callback 
) const
protected

do the opposite of above So a string that looks like AACT(>12<17)TTT would invoke the callback three times with ("AACT", Snarl), ("", Snarl(12,-17)), ("TTT", Snarl(12,-17)) The parameters are to be treated as unions: A sequence fragment if non-empty, otherwise a snarl

◆ set_allele_merge()

void vg::VCFOutputCaller::set_allele_merge ( double  threshold,
int64_t  min_len 
)

Enable post-genotyping merging of near-identical called ALT alleles, so that a 1/2 call of two effectively-identical alleles collapses to 1/1 with a single ALT. Uses the same similarity metric and the same core-length gate as "vg deconstruct -L/--cluster-min-len" (a length-weighted Jaccard, except that a pure deletion is scored against the site – see weighted_traversal_similarity). The gate is applied to the alleles each tool emits, and those sets differ, so the two can disagree at a given site: similarity is >= threshold to merge, and min_len > 0 restricts merging to sites whose core length reaches min_len bp (see allele_core_length). A threshold of 1.0 (the default) disables merging entirely.

◆ set_nested()

void vg::VCFOutputCaller::set_nested ( bool  nested)

Assume writing nested snarls is enabled.

◆ set_translation()

void vg::VCFOutputCaller::set_translation ( const unordered_map< nid_t, pair< string, size_t >> *  translation)

Add a translation map.

◆ snarl_traversal_to_handles()

bool vg::VCFOutputCaller::snarl_traversal_to_handles ( const HandleGraph graph,
const SnarlTraversal trav,
Traversal out_trav 
)
staticprotected

Convert a SnarlTraversal to the handle vector the clustering code works on. Returns false (leaving out_trav unspecified) if the traversal cannot be represented: fewer than two visits (the "*" placeholder pushed for a star allele), or a visit carrying a child Snarl rather than a node, which NestedFlowCaller produces via SnarlGraph::embed_snarl. (LegacyCaller expands its children into node visits in top_down_genotype, so it never reaches here.)

◆ trav_string()

string vg::VCFOutputCaller::trav_string ( const HandleGraph graph,
const SnarlTraversal trav 
) const
protected

convert a traversal into an allele string

◆ update_nesting_info_tags()

void vg::VCFOutputCaller::update_nesting_info_tags ( const SnarlManager snarl_manager)
protected

◆ vcf_fixup()

void vg::VCFOutputCaller::vcf_fixup ( vcflib::Variant &  var) const

Run vcffixup from vcflib.

◆ vcf_header()

string vg::VCFOutputCaller::vcf_header ( const PathHandleGraph graph,
const vector< string > &  contigs,
const vector< size_t > &  contig_length_overrides 
) const
virtual

Write the vcf header (version and contigs and basic info)

Reimplemented in vg::NestedFlowCaller, vg::FlowCaller, vg::LegacyCaller, and vg::VCFGenotyper.

◆ write_variants()

void vg::VCFOutputCaller::write_variants ( ostream &  out_stream,
const SnarlManager snarl_manager = nullptr 
)

Sort then write variants in the buffer snarl_manager needed if include_nested is true

Member Data Documentation

◆ allele_merge_min_len

int64_t vg::VCFOutputCaller::allele_merge_min_len = 0
protected

◆ allele_merge_threshold

double vg::VCFOutputCaller::allele_merge_threshold = 1.0
protected

◆ include_nested

bool vg::VCFOutputCaller::include_nested
protected

◆ max_uncalled_alleles

size_t vg::VCFOutputCaller::max_uncalled_alleles = 5
protected

print up to this many uncalled alleles when doing ref-genotpes in -a mode

◆ max_vcf_line_length

const int64_t vg::VCFOutputCaller::max_vcf_line_length = 2000000000
staticprotected

◆ output_variants

vector<vector<pair<pair<string, size_t>, string> > > vg::VCFOutputCaller::output_variants
mutableprotected

output buffers (1/thread) (for sorting) variants stored as strings (and position key pairs) because vcflib::Variant in-memory struct so huge

◆ output_vcf

vcflib::VariantCallFile vg::VCFOutputCaller::output_vcf
mutableprotected

output vcf

◆ sample_name

string vg::VCFOutputCaller::sample_name
protected

Sample name.

◆ translation

const unordered_map<nid_t, pair<string, size_t> >* vg::VCFOutputCaller::translation
protected

The documentation for this class was generated from the following files: