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

#include <site_emitter.hpp>

Public Member Functions

 SiteEmitter (SortedVCFWriter &output)
 
virtual ~SiteEmitter ()=default
 
bool emit (const PathPositionHandleGraph &graph, const CalledSite &site, const allele_source_t &alleles, const field_writer_t &write_fields)
 

Public Attributes

bool genotype_snarls = false
 
double allele_merge_threshold = 1.0
 
int64_t allele_merge_min_len = 0
 Merge alleles only in a record whose core length is at least this. More...
 
GLLayout gl_layout = GLLayout::IMajor
 The order that will be used in GL fields. More...
 

Static Public Attributes

static constexpr size_t max_uncalled_alleles = 5
 

Protected Member Functions

virtual bool same_as_reference (const CalledSite &site, int trav)
 
virtual int64_t phase (const CalledSite &site, const vector< int > &genotype, const map< int, int > &trav_to_allele, string &gt)
 
virtual int write_blocks (const PathPositionHandleGraph &graph, const CalledSite &site, const SiteRecord &record)
 
virtual void finish_record (const CalledSite &site, vcflib::Variant &record)
 Change the finished record just before it is written. By default it is left alone. More...
 
virtual void on_site_done (const CalledSite &site, const map< int, int > &trav_to_allele, bool has_line)
 

Protected Attributes

SortedVCFWriter & output
 The output the records go to. More...
 

Private Types

using Spellings = map< size_t, pair< string, vector< NodeVisit > >>
 The spelling of each traversal that emit has asked the allele source for, by traversal. More...
 

Private Member Functions

void number_called_alleles (const CalledSite &site, const allele_source_t &alleles, Spellings &spelled, SiteRecord &record, map< string, int > &allele_to_gt, vector< int > &site_trav)
 
SiteRecord build_record (const PathPositionHandleGraph &graph, const CalledSite &site, const allele_source_t &alleles, const field_writer_t &write_fields)
 Build the record of site, up to the point where it could be split into blocks. More...
 
bool file_record (const PathPositionHandleGraph &graph, const CalledSite &site, SiteRecord &record)
 

Static Private Member Functions

static const pair< string, vector< NodeVisit > > & spelling (const allele_source_t &alleles, Spellings &spelled, size_t trav)
 Return the spelling of traversal trav, asking alleles for it only the first time. More...
 
static void add_uncalled_alleles (const CalledSite &site, const allele_source_t &alleles, Spellings &spelled, map< string, int > &allele_to_gt, vector< int > &site_trav)
 

Detailed Description

An emitter that accepts CalledSites and produces VCF records into a SortedVCFWriter.

It can be subclassed to customize its VCF record generation behavior.

Member Typedef Documentation

◆ Spellings

using vg::SiteEmitter::Spellings = map<size_t, pair<string, vector<NodeVisit> >>
private

The spelling of each traversal that emit has asked the allele source for, by traversal.

Constructor & Destructor Documentation

◆ SiteEmitter()

vg::SiteEmitter::SiteEmitter ( SortedVCFWriter &  output)
explicit

Make an emitter that writes into output, which must outlive it, and declare the AT field in the header of output.

◆ ~SiteEmitter()

virtual vg::SiteEmitter::~SiteEmitter ( )
virtualdefault

Member Function Documentation

◆ add_uncalled_alleles()

void vg::SiteEmitter::add_uncalled_alleles ( const CalledSite &  site,
const allele_source_t &  alleles,
Spellings &  spelled,
map< string, int > &  allele_to_gt,
vector< int > &  site_trav 
)
staticprivate

Add up to max_uncalled_alleles alleles of site that were not called, in order of their sequences, to allele_to_gt and site_trav.

◆ build_record()

SiteRecord vg::SiteEmitter::build_record ( const PathPositionHandleGraph &  graph,
const CalledSite &  site,
const allele_source_t &  alleles,
const field_writer_t &  write_fields 
)
private

Build the record of site, up to the point where it could be split into blocks.

◆ emit()

bool vg::SiteEmitter::emit ( const PathPositionHandleGraph &  graph,
const CalledSite &  site,
const allele_source_t &  alleles,
const field_writer_t &  write_fields 
)

Write the record of site.

Traversals that spell the same sequence become one allele. Where the genotype has an allele marker, the record has "*" or ".", and a genotype with "." and no ALT gets "*" as its ALT, so that the record is valid VCF. A record with no ALT is hidden unless genotype_snarls is set.

Parameters
allelesSpells the site's traversals.
write_fieldsWrites the genotyper's fields once the alleles are numbered.
Returns
false only if the writer refused a line the site wanted.

◆ file_record()

bool vg::SiteEmitter::file_record ( const PathPositionHandleGraph &  graph,
const CalledSite &  site,
SiteRecord &  record 
)
private

Send a built record to the writer, unless write_blocks splits the site, and report the site to on_site_done.

Returns
false only if the writer refused a line the site wanted.

◆ finish_record()

void vg::SiteEmitter::finish_record ( const CalledSite &  site,
vcflib::Variant &  record 
)
protectedvirtual

Change the finished record just before it is written. By default it is left alone.

◆ number_called_alleles()

void vg::SiteEmitter::number_called_alleles ( const CalledSite &  site,
const allele_source_t &  alleles,
Spellings &  spelled,
SiteRecord &  record,
map< string, int > &  allele_to_gt,
vector< int > &  site_trav 
)
private

Number the reference allele and the alleles of the called genotype of site, whose REF is already in record. Traversals that spell the same sequence share one allele, and the reference allele is number 0.

Fill the empty allele_to_gt with the VCF allele number of each allele sequence, and the empty site_trav with the traversal each VCF allele is spelled from, or -1 for "*". Fill in record.genotype and record.trav_to_allele to match.

◆ on_site_done()

void vg::SiteEmitter::on_site_done ( const CalledSite &  site,
const map< int, int > &  trav_to_allele,
bool  has_line 
)
protectedvirtual

Handle a site whose records have all been sent to the writer. By default do nothing.

Parameters
trav_to_alleleIf the site got one record, the VCF allele of each called traversal in it. If write_blocks split the site, empty, since each record numbers its own alleles.
has_lineIf the site got one record, whether that record was written rather than hidden or refused. If the site was split, whether any of its records was written.

◆ phase()

int64_t vg::SiteEmitter::phase ( const CalledSite &  site,
const vector< int > &  genotype,
const map< int, int > &  trav_to_allele,
string &  gt 
)
protectedvirtual

Decide how the genotype should be phased. Return the phase set it should be in, or -1 for none, and replace the GT string gt with the phased one if it should be phased. genotype is in VCF allele numbers, and trav_to_allele gives the VCF allele of each traversal in it. By default the genotype should stay unphased, in no phase set.

◆ same_as_reference()

bool vg::SiteEmitter::same_as_reference ( const CalledSite &  site,
int  trav 
)
protectedvirtual

Return whether traversal trav, which is not the reference traversal, should be treated as the same as the reference allele. By default no other traversal should be.

◆ spelling()

const pair< string, vector< NodeVisit > > & vg::SiteEmitter::spelling ( const allele_source_t &  alleles,
Spellings &  spelled,
size_t  trav 
)
staticprivate

Return the spelling of traversal trav, asking alleles for it only the first time.

◆ write_blocks()

int vg::SiteEmitter::write_blocks ( const PathPositionHandleGraph &  graph,
const CalledSite &  site,
const SiteRecord &  record 
)
protectedvirtual

Decide whether the site should be split into several records. If it should, write them and return the number of lines written. If it should not, write nothing and return -1, and the site gets one record. The default implementation never splits a site.

Member Data Documentation

◆ allele_merge_min_len

int64_t vg::SiteEmitter::allele_merge_min_len = 0

Merge alleles only in a record whose core length is at least this.

◆ allele_merge_threshold

double vg::SiteEmitter::allele_merge_threshold = 1.0

Merge called ALT alleles whose similarity, a modified length-weighted Jaccard, is at least this. 1.0 merges none.

◆ genotype_snarls

bool vg::SiteEmitter::genotype_snarls = false

Write a record even for a reference call, with up to max_uncalled_alleles alleles that were not called added, and trim the alleles only as far as the site's boundary nodes.

◆ gl_layout

GLLayout vg::SiteEmitter::gl_layout = GLLayout::IMajor

The order that will be used in GL fields.

◆ max_uncalled_alleles

constexpr size_t vg::SiteEmitter::max_uncalled_alleles = 5
staticconstexpr

How many alleles that were not called a reference call written under genotype_snarls gets at most.

◆ output

SortedVCFWriter& vg::SiteEmitter::output
protected

The output the records go to.


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