-
Notifications
You must be signed in to change notification settings - Fork 2
/
GlacCAT.cpp
160 lines (131 loc) · 3.51 KB
/
GlacCAT.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
/*
* GlacCAT
* Date: Jul-30-2017
* Author : Gabriel Renaud gabriel.reno [at sign here ] gmail.com
*
*/
#include "GlacCAT.h"
GlacCAT::GlacCAT(){
}
GlacCAT::~GlacCAT(){
}
string GlacCAT::usage() const{
return string(string("glactools") +" cat [options] <glf file1> <glf file2> .. "+"\n"+
"\nThis program concatenates ACF/GLF files given that they were from the same genome assembly\n"+
"uses the first file as header and prints to STDOUT\n"
"\n"+
"Options:\n"+
"\t"+"-u" + "\t\t\t"+"Unsafe mode, will not check if the acf/glf files are compatible\n"+
"\t"+" " + "\t\t\t"+"use this if you are sure the acf come from the same reference genome, it is much faster (default: "+booleanAsString(false)+")\n"
);
}
int GlacCAT::run(int argc, char *argv[]){
AlleleRecords * arr;
//AlleleRecords * arw;
GlacWriter * gw=NULL;
string sqLines="";
string defline="";
uint16_t chriRead=0;
bool unsafemode=false;
int firstIndex=1;
if(string(argv[1]) == "-u"){
unsafemode=true;
firstIndex=2;
}
for(int i=firstIndex;i<(argc);i++){
string filename = string(argv[i]);
GlacParser gp (filename);
size_t sizeRecords;
if(i==firstIndex){//first file
gw = new GlacWriter(gp.getSizePops(),
false,
2,
1,//compression threads
uncompressed);
string newheader=gp.getHeader();
sqLines = gp.getHeaderSQ();
defline = gp.getDefline();
if(!gw->writeHeader(newheader)){
cerr<<"GlacCat: error writing header "<<endl;
return 1;
}
//first record
if(gp.hasData()){
arr = gp.getData();
chriRead = arr->chri;
if(!gw->writeAlleleRecord(arr)){
cerr<<"GlacCAT: error writing record "<<arr<<endl;
exit(1);
}
}
if(unsafemode){
sizeRecords=gp.getSizeRecord();
char * buffer;
while(true){
buffer = gp.fillBuffer(sizeRecords);
if(buffer == 0){
break;
}
if(!gw->writeBuffer(buffer,sizeRecords)){
cerr<<"GlacCAT: error writing record "<<endl;
exit(1);
}
delete(buffer);
}
}else{
while(gp.hasData()){
arr = gp.getData();
if(!gw->writeAlleleRecord(arr)){
cerr<<"GlacCAT: error writing record "<<arr<<endl;
exit(1);
}
}
}
}else{
if(sqLines != gp.getHeaderSQ()){
cerr<<"GlacCat: error the SQ lines do not match in headers in file: "<<string(argv[i])<<" does not match the ones in "<<string(argv[1])<<endl;
return 1;
}
if(defline != gp.getDefline()){
cerr<<"GlacCat: error the defline do not match in headers in file: "<<string(argv[i])<<" does not match the one in "<<string(argv[1])<<endl;
return 1;
}
//first record
if(gp.hasData()){
arr = gp.getData();
if(chriRead > arr->chri){
cerr<<"GlacCAT: WARNING chromosomal coordinate in "<<arr<<" is greater than in the previous file, indexing will not work"<<endl;
}
chriRead = arr->chri;
if(!gw->writeAlleleRecord(arr)){
cerr<<"GlacCAT: error writing record "<<arr<<endl;
exit(1);
}
}
if(unsafemode){
char * buffer;
while(true){
buffer = gp.fillBuffer(sizeRecords);
if(buffer == 0){
break;
}
if(!gw->writeBuffer(buffer,sizeRecords)){
cerr<<"GlacCAT: error writing record "<<endl;
exit(1);
}
delete(buffer);
}
}else{
while(gp.hasData()){
arr = gp.getData();
if(!gw->writeAlleleRecord(arr)){
cerr<<"GlacCAT: error writing record "<<arr<<endl;
exit(1);
}
}
}
}
}
delete(gw);
return 0;
}