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

#include <haplotype_indexer.hpp>

Inheritance diagram for vg::HaplotypeIndexer:
vg::Progressive

Public Member Functions

 HaplotypeIndexer ()
 Perform initialization of backing libraries. More...
 
size_t parse_vcf (PathHandleGraph *graph, const std::vector< path_handle_t > &contigs, vcflib::VariantCallFile &variant_file, std::vector< std::string > &sample_names, const function< void(size_t, const gbwt::VariantPaths &, gbwt::PhasingInformation &)> &handle_contig_haplotype_batch, bool delete_graph) const
 
std::unique_ptr< gbwt::DynamicGBWT > build_gbwt (PathHandleGraph *graph, std::string vcf_filename, bool delete_graph) const
 
std::unique_ptr< gbwt::DynamicGBWT > build_gbwt (const PathHandleGraph *graph) const
 
std::unique_ptr< gbwt::DynamicGBWT > build_gbwt (const PathHandleGraph *graph, const std::vector< std::string > &aln_filenames, const std::string &aln_format) const
 
- Public Member Functions inherited from vg::Progressive
void preload_progress (const string &message)
 
void create_progress (const string &message, long count)
 
void create_progress (long count)
 
void update_progress (long i)
 
void increment_progress ()
 
void destroy_progress (void)
 

Public Attributes

bool paths_as_samples = false
 
bool warn_on_missing_variants = true
 Print a warning if variants in the VCF can't be found in the graph. More...
 
size_t max_missing_variant_warnings = 10
 Only report up to this many of them. More...
 
std::map< std::string, std::string > path_to_vcf
 
bool rename_variants = true
 
std::string batch_file_prefix = ""
 
bool phase_homozygous = true
 Phase homozygous unphased variants. More...
 
bool force_phasing = false
 Arbitrarily phase all unphased variants. More...
 
bool discard_overlaps = false
 Join together overlapping haplotypes. More...
 
size_t samples_in_batch = 200
 Number of samples to process together in a haplotype batch. More...
 
size_t gbwt_buffer_size = gbwt::DynamicGBWT::INSERT_BATCH_SIZE / gbwt::MILLION
 Size of the GBWT buffer in millions of nodes. More...
 
size_t id_interval = gbwt::DynamicGBWT::SAMPLE_INTERVAL
 Interval at which to sample for GBWT locate. More...
 
std::pair< size_t, size_t > sample_range = std::pair<size_t, size_t>(0, std::numeric_limits<size_t>::max())
 Range of VCF samples to process (first to past-last). More...
 
std::map< std::string, std::pair< size_t, size_t > > regions
 
std::unordered_set< std::string > excluded_samples
 
- Public Attributes inherited from vg::Progressive
bool show_progress = false
 

Detailed Description

Allows indexing haplotypes, either to pre-parsed haplotype files or to a GBWT.

Constructor & Destructor Documentation

◆ HaplotypeIndexer()

vg::HaplotypeIndexer::HaplotypeIndexer ( )

Perform initialization of backing libraries.

Member Function Documentation

◆ build_gbwt() [1/3]

std::unique_ptr< gbwt::DynamicGBWT > vg::HaplotypeIndexer::build_gbwt ( const PathHandleGraph graph) const

Build a GBWT from the embedded non-alt paths in the graph. Use paths_as_samples to choose whether we treat the paths as contigs or samples.

◆ build_gbwt() [2/3]

std::unique_ptr< gbwt::DynamicGBWT > vg::HaplotypeIndexer::build_gbwt ( const PathHandleGraph graph,
const std::vector< std::string > &  aln_filenames,
const std::string &  aln_format 
) const

Build a GBWT from the alignments. Each distinct alignment name becomes a sample in the GBWT metadata. If there are multiple alignments with the same name, the corresponding GBWT path names will have the same sample identifier but different values in the count field.

aln_format can be "GAM" or "GAF"

◆ build_gbwt() [3/3]

std::unique_ptr< gbwt::DynamicGBWT > vg::HaplotypeIndexer::build_gbwt ( PathHandleGraph graph,
std::string  vcf_filename,
bool  delete_graph 
) const

Build a GBWT from the haplotypes in the given VCF file.

Respects excluded_samples and does not produce threads for them.

If needed, this function can delete the graph to save memory.

TODO: We copy the file name, as vcflib requires a non-const name.

◆ parse_vcf()

size_t vg::HaplotypeIndexer::parse_vcf ( PathHandleGraph graph,
const std::vector< path_handle_t > &  contigs,
vcflib::VariantCallFile &  variant_file,
std::vector< std::string > &  sample_names,
const function< void(size_t, const gbwt::VariantPaths &, gbwt::PhasingInformation &)> &  handle_contig_haplotype_batch,
bool  delete_graph 
) const

Parse a VCF file into the types needed for GBWT indexing.

Takes a graph, a vector of contigs in the graph to process, in order, and the corresponding VCF file, already open. Sample parsing on the VCF file should be turned off.

Inserts the sample names from the VCF into sample_names.

Calls the callback serially with the contig number, each contig's gbwt::VariantPaths, for each gbwt::PhasingInformation batch of samples. The gbwt::PhasingInformation is not const because the GBWT library needs to modify it in order to generate haplotypes from it efficiently.

If batch_file_prefix is set on the object, also dumps VCF parse information.

If needed, this function can delete the graph to save memory.

Returns the number of haplotypes created (2 per sample) This number will need to be adjusted if any samples' haplotypes are filtered out later. This function ignores any sample filters and processes the entire sample range.

Member Data Documentation

◆ batch_file_prefix

std::string vg::HaplotypeIndexer::batch_file_prefix = ""

If batch_file_prefix is nonempty, a file for each contig is saved to PREFIX_VCFCONTIG, and files for each batch of haplotypes are saved to files named like PREFIX_VCFCONTIG_STARTSAMPLE_ENDSAMPLE. Otherwise, the batch files are still saved, but to temporary files.

◆ discard_overlaps

bool vg::HaplotypeIndexer::discard_overlaps = false

Join together overlapping haplotypes.

◆ excluded_samples

std::unordered_set<std::string> vg::HaplotypeIndexer::excluded_samples

Excluded VCF sample names, for which threads will not be generated. Ignored during VCF parsing.

◆ force_phasing

bool vg::HaplotypeIndexer::force_phasing = false

Arbitrarily phase all unphased variants.

◆ gbwt_buffer_size

size_t vg::HaplotypeIndexer::gbwt_buffer_size = gbwt::DynamicGBWT::INSERT_BATCH_SIZE / gbwt::MILLION

Size of the GBWT buffer in millions of nodes.

◆ id_interval

size_t vg::HaplotypeIndexer::id_interval = gbwt::DynamicGBWT::SAMPLE_INTERVAL

Interval at which to sample for GBWT locate.

◆ max_missing_variant_warnings

size_t vg::HaplotypeIndexer::max_missing_variant_warnings = 10

Only report up to this many of them.

◆ path_to_vcf

std::map<std::string, std::string> vg::HaplotypeIndexer::path_to_vcf

Path names in the graph are mapped to VCF contig names via path_to_vcf, or used as-is if no entry there is found.

◆ paths_as_samples

bool vg::HaplotypeIndexer::paths_as_samples = false

Treat the embedded paths in the graph as samples. By default, the paths are interpreted as contigs.

◆ phase_homozygous

bool vg::HaplotypeIndexer::phase_homozygous = true

Phase homozygous unphased variants.

◆ regions

std::map<std::string, std::pair<size_t, size_t> > vg::HaplotypeIndexer::regions

Region restrictions for contigs, in VCF name space, as 0-based exclusive-end ranges.

◆ rename_variants

bool vg::HaplotypeIndexer::rename_variants = true

Use graph path names instead of VCF path names when composing variant alt paths.

◆ sample_range

std::pair<size_t, size_t> vg::HaplotypeIndexer::sample_range = std::pair<size_t, size_t>(0, std::numeric_limits<size_t>::max())

Range of VCF samples to process (first to past-last).

◆ samples_in_batch

size_t vg::HaplotypeIndexer::samples_in_batch = 200

Number of samples to process together in a haplotype batch.

◆ warn_on_missing_variants

bool vg::HaplotypeIndexer::warn_on_missing_variants = true

Print a warning if variants in the VCF can't be found in the graph.


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