File: vcflib-api.1

package info (click to toggle)
libvcflib 1.0.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 70,520 kB
  • sloc: cpp: 39,837; python: 532; perl: 474; ansic: 317; ruby: 295; sh: 254; lisp: 148; makefile: 123; javascript: 94
file content (102 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
.\" Automatically generated by Pandoc 2.19.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
.ie "\f[CB]x\f[]"x" \{\
. ftr V B
. ftr VI BI
. ftr VB B
. ftr VBI BI
.\}
.el \{\
. ftr V CR
. ftr VI CI
. ftr VB CB
. ftr VBI CBI
.\}
.TH "-\f[I]- coding: utf-8 -\f[R]-" "" "" "" ""
.hy
.SH VCFLib API
.PP
This document describes the VCFLIB API as it is used by the vcflib
modules and the python ffi.
vcflib follows the VCF
standard (http://samtools.github.io/hts-specs/VCFv4.1.pdf).
.PP
VCFLIB contains a lot of functionality, but the basis of going through a
VCF file and fetching record (by record) information is straightforward
and visible in all modules.
A recent example can be found in vcfwave.
.SS Open the VCF file
.IP
.nf
\f[C]
VariantCallFile variantFile;

if (optind < argc) {
    string filename = argv[optind];
    variantFile.open(filename);
} else {
    variantFile.open(std::cin);
}

if (!variantFile.is_open()) {
    return 1;
}
\f[R]
.fi
.SS Read records
.PP
The following will parse the records and you can print out the first two
fields with
.IP
.nf
\f[C]
Variant var(variantFile);
while (variantFile.getNextVariant(var)) {
  cout << var.sequenceName << \[dq] \[dq] << var.position << endl;
}
\f[R]
.fi
.SS Other fields
.PP
In the file
Variant.h (https://github.com/vcflib/vcflib/blob/master/src/Variant.h)
the Variant class is defined with fields/accessors, such as
.IP
.nf
\f[C]
    string sequenceName;
    long position;
    long zeroBasedPosition(void) const;
    string id;
    string ref;
    vector<string> alt;      // a list of all the alternate alleles present at this locus
    vector<string> alleles;  // a list all alleles (ref + alt) at this locus
\f[R]
.fi
.PP
See above read records example to parse a file.
Some things to know are that info fields are split into fields with
values in `info' and flags that are true in `infoFlags'.
The order of info fields is not kept in the C++ map data structure so we
have to keep track of order in an infoKeys vector.
.SS Output a VCF record
.PP
The default string outputter of the Variant class outputs a VCF record
using the field that are defined:
.IP
.nf
\f[C]
Variant var(variantFile);
while (variantFile.getNextVariant(var)) {
  cout << var << endl;
}
\f[R]
.fi
.PP
will output VCF.
.SS Mirroring in the Python FFI
.PP
The Python FFI follows this API though some accessors may be renamed.
See pythonffi.cpp and pyvcflib.md.