-
Notifications
You must be signed in to change notification settings - Fork 2
/
Glac2VCF.cpp
195 lines (151 loc) · 5.67 KB
/
Glac2VCF.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Glac2VCF.h"
using namespace std;
Glac2VCF::Glac2VCF(){
}
Glac2VCF::~Glac2VCF(){
}
string Glac2VCF::usage() const{
string usage=string("")+"glac2vcf [options] <ACF file>\n"+
"This program takes an ACF/GLF file and prints the segregating sites in Treemix format\n"+
"\n"+
"Options:\n"+
"\t--root\t\tPrint the root (Default "+boolStringify(printRoot)+" )\n"+
"\t--anc\t\tPrint the anc (Default "+boolStringify(printAnc)+" )\n"+
"\t--one\t\tPrint records with a single base as homozygous (Default "+boolStringify(singleAlleleAsHomo)+" )\n"+
"\t \t\tex: 1,0:0 becomes GT=0/0 \n"+
"\n";
return usage;
}
int Glac2VCF::run(int argc, char *argv[]){
if(argc == 1 ||
(argc == 2 && (string(argv[1]) == "-h" || string(argv[1]) == "--help") )
){
cerr << "Usage "<<usage()<<endl;
return 1;
}
int lastOpt=1;
for(int i=1;i<(argc);i++){
if((string(argv[i]) == "-") ){
lastOpt=i;
break;
}
if(string(argv[i])[0] != '-' ){
lastOpt=i;
break;
}
if( string(argv[i]) == "--root" ){
printRoot=true;
continue;
}
if( string(argv[i]) == "--anc" ){
printAnc=true;
continue;
}
if( string(argv[i]) == "--one" ){
singleAlleleAsHomo=true;
continue;
}
cerr<<"Error unknown option "<<argv[i]<<endl;
exit(1);
}
GlacParser gp (argv[lastOpt]);
//gp.isACFormat()){
vector<string> toprintPop;
for(unsigned j=0;j<gp.getPopulationsNames()->size();j++){
if(j == 0){
if(!printRoot)
continue;
toprintPop.push_back(gp.getPopulationsNames()->at(j));
continue;
}
if(j == 1){
if(!printAnc)
continue;
toprintPop.push_back(gp.getPopulationsNames()->at(j));
continue;
}
toprintPop.push_back(gp.getPopulationsNames()->at(j));
}
string programLine;
for(int i=0;i<(argc);i++){
programLine+=(string(argv[i])+" ");
}
cout<<"##fileformat=VCFv4.2"<<endl;
cout<<"##FILTER=<ID=PASS,Description=\"All filters passed\">"<<endl;
cout<<"##glactoolsVersion="<<returnGitHubVersion(argv[-1],"")<<endl;
cout<<"##glactoolsCommand="<<programLine<<endl;
cout<<"##reference=N/A"<<endl;
for(unsigned int i=0;i<gp.getNumberOfChromosomes();i++){
cout<<"##contig=<ID="<<gp.getChrKnown()[i]<<",length="<<gp.getChrKnownLength()[i]<<">"<<endl;
}
// ##ALT=<ID=*,Description="Represents allele(s) other than observed.">
// ##INFO=<ID=INDEL,Number=0,Type=Flag,Description="Indicates that the variant is an INDEL.">
// ##INFO=<ID=IDV,Number=1,Type=Integer,Description="Maximum number of reads supporting an indel">
// ##INFO=<ID=IMF,Number=1,Type=Float,Description="Maximum fraction of reads supporting an indel">
// ##INFO=<ID=DP,Number=1,Type=Integer,Description="Raw read depth">
// ##INFO=<ID=VDB,Number=1,Type=Float,Description="Variant Distance Bias for filtering splice-site artefacts in RNA-seq data (bigger is better)",Version="3">
// ##INFO=<ID=RPB,Number=1,Type=Float,Description="Mann-Whitney U test of Read Position Bias (bigger is better)">
// ##INFO=<ID=MQB,Number=1,Type=Float,Description="Mann-Whitney U test of Mapping Quality Bias (bigger is better)">
// ##INFO=<ID=BQB,Number=1,Type=Float,Description="Mann-Whitney U test of Base Quality Bias (bigger is better)">
// ##INFO=<ID=MQSB,Number=1,Type=Float,Description="Mann-Whitney U test of Mapping Quality vs Strand Bias (bigger is better)">
// ##INFO=<ID=SGB,Number=1,Type=Float,Description="Segregation based metric.">
// ##INFO=<ID=MQ0F,Number=1,Type=Float,Description="Fraction of MQ0 reads (smaller is better)">
// ##INFO=<ID=I16,Number=16,Type=Float,Description="Auxiliary tag used for calling, see description of bcf_callret1_t in bam2bcf.h">
// ##INFO=<ID=QS,Number=R,Type=Float,Description="Auxiliary tag used for calling">
if( gp.isACFormat() ){
cout<<"##FORMAT=<ID=GT,Number=1,Type=String,Description=\"Genotype\">"<<endl;
//cout<<"##FORMAT=<ID=PL,Number=G,Type=Integer,Description=\"List of Phred-scaled genotype likelihoods\">"<<endl;
}else{
cout<<"##FORMAT=<ID=PL,Number=G,Type=Integer,Description=\"List of Phred-scaled genotype likelihoods\">"<<endl;
}
// #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT inC6.q25.bam
cout<<"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\t"<<vectorToString( toprintPop," ")<<endl;
AlleleRecords * arr;
unsigned int totalRecords=0;
// unsigned int keptRecords=0;
while(gp.hasData()){
//cout<<"data"<<endl;
arr = gp.getData();
if( totalRecords!=0 && (totalRecords%10000000) == 0){
cerr<<"Looked at "<<totalRecords<<" records @ "<<arr->chr<<":"<<arr->coordinate<<endl;
}
cout<<gp.getChromosomeName(arr->chri)<<"\t"<<arr->coordinate<<"\t"<<"."<<"\t"<<arr->ref<<"\t"<<arr->alt<<"\t"<<0<<"\t"<<"."<<"\t"<<".";
// if(test->alt == 'N'){
// continue;
// }
// string toprint="";
// int counterIndRef=0;
// int counterIndAlt=0;
if( gp.isACFormat() ){
cout<<"\tGT";
for(unsigned j=0;j<arr->vectorAlleles->size();j++){
if(j == 0){
if(!printRoot)
continue;
}
if(j == 1){
if(!printAnc)
continue;
}
cout<<"\t"<<arr->vectorAlleles->at(j).toGT(singleAlleleAsHomo);
}
}else{
cout<<"\tPL";
for(unsigned j=0;j<arr->vectorGLs->size();j++){
if(j == 0){
if(!printRoot)
continue;
}
if(j == 1){
if(!printAnc)
continue;
}
cout<<"\t"<<arr->vectorGLs->at(j).toPL();
}
}
cout<<endl;
totalRecords++;
}
cerr<<"Program "<<argv[0]<<" wrote "<<totalRecords<<", terminated gracefully"<<endl;
return 0;
}