Class VcfStream
High-level VCF I/O class.

Defined in <seqan/vcf_io.h>
Signature class VcfStream;

Member Function Overview

Interface Function Overview

Member Variable Overview

Detailed Description

Examples

The following example demonstrates reading a VCF file and printing the variant locations.

#include <seqan/basic.h>
#include <seqan/vcf_io.h>

using namespace seqan;

int main()
{
    CharString path = SEQAN_PATH_TO_ROOT();
    append(path, "/extras/demos/vcf_io/example.vcf");

    VcfStream vcfIn(toCString(path));
    if (!isGood(vcfIn))
    {
        std::cerr << "ERROR: Could not open " << path << " for reading!\n";
        return 1;
    }

    VcfRecord record;
    while (!atEnd(vcfIn))
    {
        if (readRecord(record, vcfIn) != 0)
        {
            std::cerr << "ERROR: Problem reading from " << path << "\n";
            return 1;
        }

        // Note that we print the position 1-based since we use text output
        // whereas it is 0-based in the VcfRecord.
        std::cout << vcfIn.header.sequenceNames[record.rID]
                  << "\t" << (record.beginPos + 1) << "\n";
    }
    
    return 0;
}

The output is as follows:

20	14370
20	17330
20	1110696
20	1230237
20	1234567

Member Functions Detail

VcfStream::VcfStream(); VcfStream::VcfStream(fileName[, mode]);

Constructor.

Parameters

fileName Path to the fiel to open. Type: char const *.
mode The mode to open the file in. Type: VcfStream::Mode. Default: READ.

Interface Functions Detail

bool atEnd(stream);

Query a VcfStream for being at the end.

Parameters

stream The VcfStream to query.

Returns

bool true if the stream is a the end and false otherwise.

int close(stream);

Close a VcfStream.

Parameters

stream The VcfStream to close.

Returns

int Status code, 0 on success, non-0 on errors.

int flush(stream);

Flush a VcfStream.

Parameters

stream The VcfStream to flush.

Returns

int Status code, 0 on success, non-0 on errors.

bool isGood(stream);

Query error state of VcfStream.

Parameters

stream The VcfStream to query.

Returns

bool true if the stream is ready for reading and writing.

bool open(vcfStream, fileName[, mode]);

Open a VcfStream.

Parameters

vcfStream The VcfStream to open.
fileName Path to the file to open. Type: char const *.
mode Mode to open the file in. Type VcfStream::Mode. Default: READ.

Returns

bool true if the file could be opened and false otherwise.

int readRecord(record, stream);

Read a record from a VcfStream.

Parameters

record The VcfRecord to read into.
stream The VcfStream to read from.

Returns

int Status code, 0 on success, non-0 value on error.

int writeRecord(stream, record);

Write a record to a VcfStream.

Parameters

stream The VcfStream to write to.
record The VcfRecord to write.

Returns

int Status code, 0 on success, non-0 value on error.

Member Variables Detail

VcfHeader VcfStream::header

Member to store header information.