vcfpp
Public Member Functions | Public Attributes | List of all members
vcfpp::BcfReader Class Reference

Stream in variants from compressed/uncompressed VCF/BCF file or stdin. More...

#include <vcfpp.h>

Public Member Functions

 BcfReader ()
 Construct an empty BcfReader.
 
 BcfReader (const std::string &file)
 construct a vcf/bcf reader from file. More...
 
 BcfReader (const std::string &file, const std::string &region)
 construct a vcf/bcf reader with subset samples More...
 
 BcfReader (const std::string &file, const std::string &region, const std::string &samples)
 construct a vcf/bcf reader with subset samples in target region More...
 
void close ()
 Close the VCF file and its associated files.
 
void open (const std::string &file)
 Open a VCF/BCF/STDIN file for streaming in.
 
int setThreads (int n)
 set the number of threads to use
 
const BcfHeadergetHeader () const
 return a BcfHeader object
 
int getStatus (const std::string &region)
 query the status of a given region in the VCF More...
 
int getVariantsCount (const std::string &region)
 count the number of variants by iterating through a given region. More...
 
void setSamples (const std::string &samples)
 explicitly stream to specific samples More...
 
void setRegion (const std::string &region)
 explicitly stream to specific region. throw invalid_argument error if index file not found. throw runtime_error if the region was not a valid bcftools-like format or was not presenting in the VCF. More...
 
bool getNextVariant (BcfRecord &r)
 read in the next variant More...
 

Public Attributes

BcfHeader header
 a BcfHeader object
 
int nsamples
 number of samples in the VCF
 
std::vector< std::string > SamplesName
 a vector of samples name in the VCF
 

Detailed Description

Stream in variants from compressed/uncompressed VCF/BCF file or stdin.

Constructor & Destructor Documentation

◆ BcfReader() [1/3]

vcfpp::BcfReader::BcfReader ( const std::string &  file)
inline

construct a vcf/bcf reader from file.

Parameters
filethe input vcf/bcf with suffix vcf(.gz)/bcf(.gz) or stdin "-"

◆ BcfReader() [2/3]

vcfpp::BcfReader::BcfReader ( const std::string &  file,
const std::string &  region 
)
inline

construct a vcf/bcf reader with subset samples

Parameters
filethe input vcf/bcf with suffix vcf(.gz)/bcf(.gz) or stdin "-"
regionsamtools-like region "chr:start-end", skip if empty

◆ BcfReader() [3/3]

vcfpp::BcfReader::BcfReader ( const std::string &  file,
const std::string &  region,
const std::string &  samples 
)
inline

construct a vcf/bcf reader with subset samples in target region

Parameters
filethe input vcf/bcf with suffix vcf(.gz) or bcf(.gz)
regionsamtools-like region "chr:start-end", skip if empty
samplesLIST samples to include or exclude as a comma-separated string.
LIST : select samples in list
^LIST : exclude samples from list
"-" : include all samples
"" : exclude all samples

Member Function Documentation

◆ getNextVariant()

bool vcfpp::BcfReader::getNextVariant ( BcfRecord r)
inline

read in the next variant

Parameters
rthe BcfRecord object to be filled in.

◆ getStatus()

int vcfpp::BcfReader::getStatus ( const std::string &  region)
inline

query the status of a given region in the VCF

Returns
-2: the region is not a valid bcftools-like format, or it is not presenting in the VCF even though it's bcftols-like format.
-1: there is no index file found.
0: the region is valid but empty.
1: vaild and not empty.

◆ getVariantsCount()

int vcfpp::BcfReader::getVariantsCount ( const std::string &  region)
inline

count the number of variants by iterating through a given region.

Note
If you want to continue work on that region, remember to reset the region by setRegion()!
Also, check the status of the region first to handle the different cases!

◆ setRegion()

void vcfpp::BcfReader::setRegion ( const std::string &  region)
inline

explicitly stream to specific region. throw invalid_argument error if index file not found. throw runtime_error if the region was not a valid bcftools-like format or was not presenting in the VCF.

Parameters
regionthe string for region is samtools-like format, which can be 'chr', 'chr:start' and 'chr:start-end'

◆ setSamples()

void vcfpp::BcfReader::setSamples ( const std::string &  samples)
inline

explicitly stream to specific samples

Parameters
samplesthe string is bcftools-like format, which is comma separated list of samples to include (or exclude with "^" prefix).

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