-
Notifications
You must be signed in to change notification settings - Fork 2
/
sra_diff.cpp
136 lines (96 loc) · 2.61 KB
/
sra_diff.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
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include "bloom.h"
#include "binary_io.h"
using namespace std;
void parse_accessions(ifstream &m_fin, vector<SraAccession> &m_acc);
int main(int argc, char *argv[])
{
try{
if(argc != 3){
cerr << "Usage: " << argv[0] << " <binary metadata file 1> <binary metadata file 2>" << endl;
return EXIT_SUCCESS;
}
ifstream fin_1(argv[1], ios::binary);
if(!fin_1){
cerr << "Unable to open file 1: " << argv[1] << endl;
return EXIT_FAILURE;
}
ifstream fin_2(argv[2], ios::binary);
if(!fin_2){
cerr << "Unable to open file 2: " << argv[2] << endl;
return EXIT_FAILURE;
}
vector<SraAccession> acc_1;
vector<SraAccession> acc_2;
cerr << "Reading file 1: " << argv[1] << endl;
try{
parse_accessions(fin_1, acc_1);
sort( acc_1.begin(), acc_1.end() );
}
catch(...){
cerr << "Unable to parse file 1: " << argv[1] << endl;
}
cerr << "Reading file 2: " << argv[2] << endl;
try{
parse_accessions(fin_2, acc_2);
sort( acc_2.begin(), acc_2.end() );
}
catch(...){
cerr << "Unable to parse file 2: " << argv[2] << endl;
}
vector<SraAccession>::const_iterator iter_1 = acc_1.begin();
vector<SraAccession>::const_iterator iter_2 = acc_2.begin();
cerr << "Comparing accession sets" << endl;
while(true){
if( iter_1 == acc_1.end() ){
cout << "Reached the last accession of the first file" << endl;
cout << "There are " << (acc_2.size() - ( iter_2 - acc_2.begin() ) )
<< " accessions remaining in the second file" << endl;
break;
}
if( iter_2 == acc_2.end() ){
cout << "Reached the last accession of the second file" << endl;
cout << "There are " << (acc_1.size() - ( iter_1 - acc_1.begin() ) )
<< " accessions remaining in the first file" << endl;
break;
}
if(*iter_1 < *iter_2){
cout << "1: " << accession_to_str(*iter_1) << endl;
++iter_1;
continue;
}
if(*iter_2 < *iter_1){
cout << "2: " << accession_to_str(*iter_2) << endl;
++iter_2;
continue;
}
// *iter_1 == *iter_2
++iter_1;
++iter_2;
}
}
catch(const char *error){
cerr << "Caught the error: " << error << endl;
return EXIT_FAILURE;
}
catch(...){
cerr << "Caught an unhandled error!" << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
void parse_accessions(ifstream &m_fin, vector<SraAccession> &m_acc)
{
FilterInfo info;
size_t num_info;
binary_read(m_fin, num_info);
m_acc.resize(num_info);
for(size_t i = 0;i < num_info;++i){
binary_read(m_fin, info);
m_acc[i] = info.run_accession;
}
}