Newer
Older
using namespace std;
#include "Context.h"
#include "FileRecordMgr.h"
#include <iostream>
#include <cstdio>
#include "RecordKeyList.h"
#include "NewChromsweep.h"
#include "DualQueue.h"
#include "ParseTools.h"
#include <sstream>
#include <iomanip>
//#include "FormatGuess.h"
#include "PushBackStreamBuf.h"
#include "InflateStreamBuf.h"
#include "InputStreamMgr.h"
#include "BufferedStreamMgr.h"
//void doSweep(const Context *context);
//void testDualQueue(Context *context);
//
//void test_streams();
using namespace std;
int nek_sandbox1_main2(int argc,char** argv);
int nek_sandbox1_main(int argc,char** argv)
{
if (argc < 2) {
cerr << "Error: Need one input file. Use \"-\" for stdin." << endl;
}
nkindlon
committed
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
ifstream myFile(argv[1]);
if (!myFile.good()) {
cerr << "Error: Can't open genome file" << argv[1] << "Exiting..." << endl;
exit(1);
}
string sLine;
vector<QuickString> fields;
QuickString chrName;
vector<QuickString> chroms;
chroms.push_back("1");
chroms.push_back("2");
chroms.push_back("10");
chroms.push_back("11");
vector<int> chromCounts(4, 0);
int chromIdx = 0;
while (!myFile.eof()) {
sLine.clear();
fields.clear();
getline(myFile, sLine);
if (sLine[0] == '@') {
cout << sLine << endl;
continue;
}
Tokenize(sLine.c_str(), fields);
const QuickString &currChrom = fields[2];
if (currChrom == chroms[chromIdx]) {
cout << sLine << endl;
chromCounts[chromIdx]++;
if (chromCounts[chromIdx] >= 3000) {
chromIdx++;
}
if (chromIdx > 3) {
break;
}
}
}
return 0;
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
Context context;
context.addInputFile(argv[1]);
context.setSortedInput(true);
// context.setObeySplits(true);
FileRecordMgr frm(0, &context);
// frm.getBlockMgr()->setBreakOnSkipOps(true);
if (!frm.open()) {
cerr << "Error: couldn't open file " << argv[1] << ". Exiting." << endl;
exit(1);
}
cout << "File Type is : " << frm.getFileType() << ", " << frm.getFileTypeName() << "." << endl;
cout << "RecordType is : " << frm.getRecordType() << ", " << frm.getRecordTypeName() << "." << endl;
bool headerFound = false;
QuickString outbuf;
while (!frm.eof()) {
Record *record = frm.allocateAndGetNextRecord();
if (!headerFound && frm.hasHeader()) {
cout << frm.getHeader() << endl;
headerFound = true;
}
if (record == NULL) {
break;
}
if (record->getStartPos() == 90647945) {
printf("Breakpoint here.\n");
}
outbuf.clear();
record->print(outbuf);
printf("%s\n", outbuf.c_str());
// RecordKeyList recList(record);
// int blockCount = frm.getBlockMgr()->getBlocks(recList);
// printf("The %d blocks are:\n", blockCount);
// for (RecordKeyList::const_iterator_type iter = recList.begin(); iter != recList.end(); iter = recList.next()) {
// iter->value()->print();
// printf("\n");
// }
// printf("\n\n");
// frm.getBlockMgr()->deleteBlocks(recList);
frm.deleteRecord(record);
}
cout << "Final header is: " << frm.getHeader() << endl;
frm.close();
return 0;
}
//int nek_sandbox1_main2(int argc,char** argv)
//{
//
//
// vector<FormatGuess *> formats;
// formats.push_back(new VCFGuess());
// formats.push_back(new XMLGuess());
//
// PushBackStreamBuf pbs(std::cin.rdbuf());
// std::istream in(&pbs);
// const char* format=0;
// for(size_t i=0;i< 2;++i)
// {
// if( formats[i]->guess(&pbs))
// {
// format=formats[i]->format();
// break;
// }
// }
// std::string line;
// while(getline(in,line))
// {
// if(format!=0) cout << format << "\t";
// cout << line << endl;
// }
// return 0;
//}
//
#ifdef false
int nek_sandbox1_main(int argc, char **argv) {
for (int i=0; i < argc; i ++) {
cout << "Arg " << i << " is: " << argv[i] << endl;
}
test_streams();
return 0;
/////////////////////////////////
//
// BLOCK FOR DUEL QUEUE
//
if (argc < 2) {
cerr << "Error: need at least one file name." << endl;
return 1;
}
Context *context = new Context();
context->addInputFile(argv[1]);
testDualQueue(context);
return 0;
//
////////////////////////////////
/////////////////////////////////
//
// BLOCK FOR SWEEP
//
if (argc < 3) {
cerr << "Error: need at least two data file names." << endl;
return 1;
}
Context *context = new Context();
context->parseCmdArgs(argc, argv, 1);
doSweep(context);
return 0;
//
////////////////////////////////
}
void doSweep(const char *file1, const char *file2, const string &genomeFile)
{
Context *context = new Context();
context->addInputFile(file1);
context->addInputFile(file2);
context->openGenomeFile(genomeFile);
ChromSweep sweep = ChromSweep(context);
if (!sweep.init()) {
cerr << "ERROR: Failure to open files in jaccard's getIntersection method." << endl;
return;
}
RecordKeyList hit_set;
while (sweep.next(hit_set)) {
// _intersectionVal += getTotalIntersection(&hit_set);
continue;
}
unsigned long unionVal = sweep.getQueryTotalRecordLength() + sweep.getDatabaseTotalRecordLength();
cout << endl << endl << "Union value is: " << unionVal << endl << endl;
}
void testDualQueue(Context *context) {
DualQueue<Record *, DualQueueAscending > dqAsc;
// DualQueue<Record *, DualQueueDescending> dqDesc;
FileRecordMgr frm(context->getInputFileName(0), context);
frm.open();
printf("Original record order is:\n");
while (!frm.eof()) {
Record *record = frm.allocateAndGetNextRecord();
if (record == NULL) {
continue;
}
// printf("\n\nNext Record is:\n");
record->print();
printf("\n");
dqAsc.push(record);
// dqDesc.push(record);
}
printf("\nSupposedly ascending order is:\n");
while (!dqAsc.empty()) {
const Record *record = dqAsc.top();
dqAsc.pop();
record->print();
printf("\n");
}
// printf("\nSupposedly descending order is:\n");
// while (!dqDesc.empty()) {
// const Record *record = dqDesc.top();
// dqDesc.pop();
// record->print();
// printf("\n");
// }
frm.close();
}
void test_streams()
{
char myBuf[10];
memset(myBuf, 0, 10);
cin >> noskipws >> setw(9) >> myBuf;
stringstream newStream;
newStream << "myBuf =:" << myBuf << endl;
newStream << "Full stream was:" << endl;
newStream << myBuf;
newStream << cin.rdbuf();
cout << newStream.str() << endl;
}
#endif //ifdef false