-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlacClosest.cpp
119 lines (78 loc) · 2.28 KB
/
GlacClosest.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
#include "GlacClosest.h"
using namespace std;
GlacClosest::GlacClosest(){
}
GlacClosest::~GlacClosest(){
}
string GlacClosest::usage() const{
string usage=string("glactools")+" closest <ACF or GLF file>"+
"\nThis program will print to stdout the distance to the closest site for each record\n\n";
return usage;
}
int GlacClosest::run(int argc, char *argv[]){
//int main (int argc, char *argv[]) {
if(argc == 1 ||
(argc == 2 && (string(argv[1]) == "-h" || string(argv[1]) == "--help") )
){
cerr << "Usage "<<usage()<<endl;
return 1;
}
string glacfile = string(argv[argc-1]);
GlacParser gp (glacfile);
AlleleRecords * dataRow;
unsigned int totalRecords=0;
unsigned int lastCoordinateM2=0;
unsigned int lastCoordinateM1=0;
unsigned int lastCoordinateM =0;
uint16_t chri=UINT16_MAX;
bool newChr1=true;
bool newChr2=true;
while(gp.hasData()){
dataRow = gp.getData();
if( chri != dataRow->chri){
//cerr<<"Chromosomes differ for line :"<<(*dataRow)<<endl;
newChr1=true;
newChr2=true;
lastCoordinateM2=0;
lastCoordinateM1=0;
lastCoordinateM =0;
//return 1;
}
if(newChr1){
lastCoordinateM2=dataRow->coordinate;
chri=dataRow->chri;
totalRecords++;
newChr1=false;
continue;
}
if(newChr2){
lastCoordinateM1=dataRow->coordinate;
if(lastCoordinateM1<lastCoordinateM2){
cerr<<"Coordinate are not sorted :"<<(*dataRow)<<endl;
return 1;
}
chri=dataRow->chri;
totalRecords++;
cout<<(lastCoordinateM1-lastCoordinateM2)<<endl;
newChr2=false;
continue;
}
lastCoordinateM=dataRow->coordinate;
if(lastCoordinateM<lastCoordinateM1){
cerr<<"Coordinate are not sorted :"<<(*dataRow)<<endl;
return 1;
}
if( (lastCoordinateM1-lastCoordinateM2) < (lastCoordinateM-lastCoordinateM1) ){
cout<<(lastCoordinateM1-lastCoordinateM2)<<endl;
}else{
cout<<(lastCoordinateM-lastCoordinateM1)<<endl;
}
//for next iteration
lastCoordinateM2=lastCoordinateM1;
lastCoordinateM1=lastCoordinateM;
totalRecords++;
}
cout<<(lastCoordinateM1-lastCoordinateM2)<<endl;
cerr<<"Program "<<argv[0]<<" looked at "<<totalRecords<<" terminated gracefully"<<endl;
return 0;
}