Commit 930ddf38 authored by nkindlon's avatar nkindlon
Browse files

Added -nobuf option, and changed flush to occur after every record if -nobuf is set.

parent bb49512d
......@@ -20,6 +20,7 @@ Context::Context()
_showHelp(false),
_obeySplits(false),
_uncompressedBam(false),
_useBufferedOutput(true),
_anyHit(false),
_noHit(false),
_writeA(false),
......@@ -288,6 +289,10 @@ bool Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
setSortedInput(true);
markUsed(i - skipFirstArgs);
}
else if(strcmp(argv[i], "-nobuf") == 0) {
setUseBufferedOutput(false);
markUsed(i - skipFirstArgs);
}
else if(strcmp(argv[i], "-header") == 0) {
setPrintHeader(true);
markUsed(i - skipFirstArgs);
......
......@@ -105,6 +105,9 @@ public:
bool getUncompressedBam() const { return _uncompressedBam; }
void setUncompressedBam(bool val) { _uncompressedBam = val; }
bool getUseBufferedOutput() const { return _useBufferedOutput; }
void setUseBufferedOutput(bool val) { _useBufferedOutput = val; }
//
// INTERSECT METOHDS
//
......@@ -241,6 +244,7 @@ protected:
bool _showHelp;
bool _obeySplits;
bool _uncompressedBam;
bool _useBufferedOutput;
bool _anyHit;
bool _noHit;
......
......@@ -43,7 +43,7 @@ private:
bool _streamFinished;
QuickString _currScanBuffer;
//The minus ones in these constants are for leaving room for a null terminator after reading into buffers.
static const int MAIN_BUF_READ_SIZE = 2047; // 2 Kb minus 1
static const int MAIN_BUF_READ_SIZE = 1023; // 2 Kb minus 1
static const int GZIP_LINE_BUF_SIZE = 8191; // 8K
bool readFileChunk();
bool getTypeData();
......
......@@ -82,6 +82,7 @@ bool RecordOutputMgr::printKeyAndTerminate(RecordKeyList &keyList) {
} else if (bamCode == NOT_BAM) {
keyList.getKey()->print(_outBuf);
return false;
}
//otherwise, it was BAM_AS_BED, and the key was printed.
return false;
......@@ -157,6 +158,7 @@ void RecordOutputMgr::printRecord(RecordKeyList &keyList, RecordKeyList *blockLi
tab();
_outBuf.append('0');
newline();
if (needsFlush()) flush();
}
else if (_context->getLeftJoin()) {
if (printKeyAndTerminate(keyList)) {
......@@ -166,6 +168,7 @@ void RecordOutputMgr::printRecord(RecordKeyList &keyList, RecordKeyList *blockLi
tab();
null(false, true);
newline();
if (needsFlush()) flush();
_currBlockList = NULL;
return;
}
......@@ -202,6 +205,7 @@ void RecordOutputMgr::checkForHeader() {
}
}
_context->setPrintHeader(false);
if (needsFlush()) flush();
}
void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record *hitRecord)
......@@ -269,22 +273,26 @@ void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record
if (!_context->getWriteA() && !_context->getWriteB() && !_context->getWriteOverlap() && !_context->getLeftJoin()) {
printKey(keyRecord, *startStr, *endStr);
newline();
if (needsFlush()) flush();
}
else if ((_context->getWriteA() && _context->getWriteB()) || _context->getLeftJoin()) {
printKey(keyRecord);
tab();
hitRecord->print(_outBuf);
newline();
if (needsFlush()) flush();
}
else if (_context->getWriteA()) {
printKey(keyRecord);
newline();
if (needsFlush()) flush();
}
else if (_context->getWriteB()) {
printKey(keyRecord, *startStr, *endStr);
tab();
hitRecord->print(_outBuf);
newline();
if (needsFlush()) flush();
}
else if (_context->getWriteOverlap()) {
int printOverlapBases = max(0, minEnd-maxStart);
......@@ -294,6 +302,7 @@ void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record
tab();
int2str(printOverlapBases, _outBuf, true);
newline();
if (needsFlush()) flush();
}
}
......@@ -305,6 +314,7 @@ void RecordOutputMgr::reportOverlapSummary(RecordKeyList &keyList)
return;
}
newline();
if (needsFlush()) flush();
} else if (_context->getWriteCount()) {
if (printKeyAndTerminate(keyList)) {
return;
......@@ -312,11 +322,13 @@ void RecordOutputMgr::reportOverlapSummary(RecordKeyList &keyList)
tab();
int2str(numOverlapsFound, _outBuf, true);
newline();
if (needsFlush()) flush();
} else if (_context->getNoHit() && numOverlapsFound == 0) {
if (printKeyAndTerminate(keyList)) {
return;
}
newline();
if (needsFlush()) flush();
}
}
......
......@@ -10,10 +10,10 @@
using namespace std;
#include "Context.h"
#include "RecordKeyList.h"
#include "api/BamWriter.h"
class Context;
class BlockMgr;
class RecordOutputMgr {
......@@ -53,7 +53,13 @@ private:
void reportOverlapSummary(RecordKeyList &keyList);
static const unsigned int MAX_OUTBUF_SIZE = 16384; //16 K
bool needsFlush() const { return _outBuf.size() >= MAX_OUTBUF_SIZE *.9; }
// If we are using buffered output, only flush the output buffer if it's least
// 90% full. If we're not using buffered output, flush if it's not empty
bool needsFlush() const {
return ((_context->getUseBufferedOutput() &&_outBuf.size() >= MAX_OUTBUF_SIZE *.9) ||
(!_context->getUseBufferedOutput() && !_outBuf.empty()));
}
void flush();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment