18 #include "SamCoordOutput.h" 19 #include "SamHelper.h" 29 SamCoordOutput::~SamCoordOutput()
40 myOutputFile = outFile;
52 myReadBuffer.insert(std::pair<uint64_t, SamRecord*>(chromPos, record));
66 static std::multimap<uint64_t, SamRecord*>::iterator iter;
70 bool returnVal =
true;
71 iter = myReadBuffer.begin();
73 if((myOutputFile == NULL) || (myHeader == NULL))
76 "SamCoordOutput::flush, no output file/header is set, so records removed without being written\n";
80 while((iter != myReadBuffer.end()) &&
81 (((*iter).first <= chromPos) || (chromID == -1)))
83 if((myOutputFile != NULL) && (myHeader != NULL))
86 myOutputFile->
WriteRecord(*myHeader, *((*iter).second));
94 delete((*iter).second);
100 myReadBuffer.erase(myReadBuffer.begin(), iter);
SamCoordOutput(SamRecordPool &pool)
Create an output buffer returning any written records to the specified pool.
void setOutputFile(SamFile *outFile, SamFileHeader *header)
Set the already opened output file to write to when flushed.
int32_t getReferenceID()
Get the reference sequence id of the record (BAM format rid).
Allows the user to easily read/write a SAM/BAM file.
bool add(SamRecord *record)
Add the specified record to this read buffer.
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
bool flush(int32_t chromID, int32_t pos0Based)
Flush the buffer based on the specified chromosome id/position, writing any records that start at/bef...
bool flushAll()
Flush the entire buffer, writing all records.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record...
void releaseRecord(SamRecord *record)
If record is not NULL, adds it back to the free list.
int32_t get0BasedPosition()
Get the 0-based(BAM) leftmost position of the record.
static uint64_t combineChromPos(int32_t chromID, int32_t position)
Helper method that combines the chromosome ID and position into a 64bit number by shifting the chromo...