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"
#include "api/internal/io/BgzfStream_p.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)
{
// for (int i=0; i < 4000; i++) {
// cout << "# This is line " << i << " of a file with a large header." << endl;
// }
// return 0;
if (argc < 2) {
cerr << "Error: Need one input file. Use \"-\" for stdin." << endl;
}
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
// ifstream inFileStream(argv[1]);
// static const int BUF_SIZE = 8192;
// BamTools::Internal::BgzfStream bgStream;
// bgStream.OpenStream(&inFileStream, BamTools::IBamIODevice::ReadOnly);
// char sLine[BUF_SIZE];
// while (bgStream.IsOpen()) {
// memset(sLine, 0, BUF_SIZE);
// bgStream.Read(sLine, BUF_SIZE-1);
// if((int)strlen(sLine) < BUF_SIZE-1) {
// bgStream.Close();
// }
// printf("%s", sLine);
// }
// return 0;
// QuickString filename(argv[1]);
// istream *inputStream = NULL;
// if (filename == "-") {
// inputStream = &cin;
// } else {
// inputStream = new ifstream(filename.c_str());
// }
//
// BamTools::BamReader _bamReader;
// try {
// _bamReader.OpenStream(inputStream);
// }
// catch (...) {
// fprintf(stderr, "ERROR: Unable to open BAM file from standard input.\n");
// exit(1);
// }
//// try {
//// _bamReader.Open(argv[1]);
//// }
//// catch (...) {
//// fprintf(stderr, "ERROR: Unable to open BAM file %s\n",argv[1]);
//// exit(1);
//// }
//// }
// QuickString _bamHeader = _bamReader.GetHeaderText();
// BamTools::RefVector _references = _bamReader.GetReferenceData();
//
// if (_bamHeader.empty() || _references.empty()) {
// cout << "This is not a bam file." << endl;
// } else {
// cout << "This is a BAM file." << endl;
// }
// return 0;
//
// 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;
//
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
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;
}
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;
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
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