-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.cpp
71 lines (60 loc) · 2.32 KB
/
output.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
// ******************************************************
// vcfCTools (c) 2011 Alistair Ward
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ------------------------------------------------------
// Last modified: 18 February 2011
// ------------------------------------------------------
// output describes the output class and all operations.
// ******************************************************
#include "output.h"
using namespace std;
using namespace vcfCTools;
// Constructor.
output::output(void)
{}
// Destructor.
output::~output(void)
{}
// Open the output file.
ostream* output::openOutputFile(string& outputFile) {
ostream* outputStream;
if (outputFile == "") {outputStream = &cout;}
else {outputStream = new ofstream(outputFile.c_str());}
return outputStream;
}
// Populate the output buffer with a record.
void output::flushToBuffer(int position, string& referenceSequence) {
// If the reference sequence of the variant to add to the buffer
// is not the same as the stored value and there are variants in the
// buffer, flush the buffer to the output file.
if (outputBuffer.size() != 0 && currentReferenceSequence != referenceSequence) {
currentReferenceSequence = referenceSequence;
for (obIter = outputBuffer.begin(); obIter != outputBuffer.end(); obIter++) {
for (recordIter = obIter->second.begin(); recordIter != obIter->second.end(); recordIter++) {
*outputStream << *recordIter << endl;
}
outputBuffer.erase(obIter);
}
}
// If the output buffer contains more than 1000 entries, flush the
// first entry to the output and erase it from the buffer.
if (outputBuffer.size() > 1000) {
obIter = outputBuffer.begin();
for (recordIter = obIter->second.begin(); recordIter != obIter->second.end(); recordIter++) {
*outputStream << *recordIter << endl;
}
outputBuffer.erase(obIter);
}
// Add the new built record to the buffer.
outputBuffer[position].push_back(outputRecord);
}
// Clear all entries out of the output buffer.
void output::flushOutputBuffer() {
for (obIter = outputBuffer.begin(); obIter != outputBuffer.end(); obIter++) {
for (recordIter = obIter->second.begin(); recordIter != obIter->second.end(); recordIter++) {
*outputStream << *recordIter << endl;
}
outputBuffer.erase(obIter);
}
}