1 #include "Variant.h" 2 #include "split.h" 3 #include <string> 4 #include <iostream> 5 6 using namespace std; 7 using namespace vcflib; 8 main(int argc,char ** argv)9int main(int argc, char** argv) { 10 11 if (argc < 3) { 12 cerr << "usage: " << argv[0] << " <vcf file> [SAMPLE1] [SAMPLE2] ..." << endl 13 << "outputs each record in the vcf file, removing samples not listed on the command line" << endl; 14 return 1; 15 } 16 17 string filename = argv[1]; 18 19 vector<string> samplesToKeep; 20 for (int i = 2; i < argc; ++i) { 21 samplesToKeep.push_back(argv[i]); 22 } 23 24 VariantCallFile variantFile; 25 if (filename == "-") { 26 variantFile.open(std::cin); 27 } else { 28 variantFile.open(filename); 29 } 30 31 if (!variantFile.is_open()) { 32 return 1; 33 } 34 35 Variant var(variantFile); 36 37 // update sample list in header 38 variantFile.updateSamples(samplesToKeep); 39 40 // and restrict the output sample names in the variant to those we are keeping 41 var.setOutputSampleNames(samplesToKeep); 42 43 // write the new header 44 cout << variantFile.header << endl; 45 46 // print the records, filtering is done via the setting of varA's output sample names 47 while (variantFile.getNextVariant(var)) { 48 cout << var << endl; 49 } 50 51 return 0; 52 53 } 54 55