7
using namespace vcflib;
10
int main(int argc, char** argv) {
13
cerr << "usage: " << argv[0] << " <vcf file>" << endl
14
<< "report the genotypes for each sample, for each variant in the vcf file" << endl;
18
string filename = argv[1];
20
VariantCallFile variantFile;
22
if (filename == "-") {
23
variantFile.open(std::cin);
25
variantFile.open(filename);
28
if (!variantFile.is_open()) {
32
Variant var(variantFile);
33
while (variantFile.getNextVariant(var)) {
34
map<string, map<string, vector<string> > >::iterator s = var.samples.begin();
35
map<string, map<string, vector<string> > >::iterator sEnd = var.samples.end();
37
cout << var.sequenceName << "\t"
38
<< var.position << "\t"
40
var.printAlt(cout); cout << "\t";
41
var.printAlleles(cout); cout << "\t";
43
for (; s != sEnd; ++s) {
44
map<string, vector<string> >& sample = s->second;
45
string& genotype = sample["GT"].front(); // XXX assumes we can only have one GT value
46
vector<string> gt = split(genotype, "|/");
48
// report the sample and it's genotype
49
cout << s->first << ":";
50
for (vector<string>::iterator g = gt.begin(); g != gt.end(); ++g) {
51
if (g->c_str() == ".") {
54
int index = atoi(g->c_str());
55
cout << var.alleles[index];
57
if (g != (gt.end()-1)) cout << "/";