Package htsjdk.samtools.util
Class SamRecordTrackingBuffer<T extends SamRecordWithOrdinal>
java.lang.Object
htsjdk.samtools.util.SamRecordTrackingBuffer<T>
This class stores SAMRecords for return. The purpose of this class is to buffer records that need to be modified or processed in some
fashion, and only return (or emit) them when they have been recorded as being fully examined. If we have too many records in RAM,
we can spill over to disk. The order in which they are given (via SamRecordWithOrdinal) determines their order of being returned. It is the
responsibility of the user of this class to make sure all records have unique index and are added in order.
When a record is examined, we also store a result state. This is currently a boolean to reduce on memory and disk footprint.
We store groups of records in blocks and the size of these blocks can be controlled. If we have too many records in RAM, we start
spilling blocks to disk.
Users should check isEmpty() to see if any records are still being tracked. If so, they should check canEmit() to see if the
next record can be returned. If so, they can call next() to get that record.
When users are done with this structure, call close().
-
Constructor Summary
ConstructorDescriptionSamRecordTrackingBuffer
(int maxRecordsInRam, int blockSize, List<File> tmpDirs, SAMFileHeader header, Class<T> clazz) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(SamRecordWithOrdinal samRecordWithOrdinal) Add the given SAMRecordIndex to the buffer.boolean
canEmit()
Returns true if we can return the next record (it has been examined).void
close()
Close IO resources associated with each underlying BufferBlockboolean
contains
(SamRecordWithOrdinal samRecordWithOrdinal) Returns true if this buffer contains the record at the given index, false otherwiseboolean
isEmpty()
Returns true if we are tracking no records, false otherwisenext()
Returns the next element in the iteration.void
remove()
Removes the next record from this buffervoid
setResultState
(SamRecordWithOrdinal samRecordWithOrdinal, boolean resultState) Mark the current samRecordWithOrdinal as having been examined.long
size()
Return the total number of elements in the queue, both in memory and on disk
-
Constructor Details
-
SamRecordTrackingBuffer
public SamRecordTrackingBuffer(int maxRecordsInRam, int blockSize, List<File> tmpDirs, SAMFileHeader header, Class<T> clazz) - Parameters:
maxRecordsInRam
- how many records to buffer before spilling to diskblockSize
- the number of records in a given blocktmpDirs
- the temporary directories to use when spilling to diskheader
- the headerclazz
- the class that extends SamRecordWithOrdinal
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returns true if we are tracking no records, false otherwise -
canEmit
public boolean canEmit()Returns true if we can return the next record (it has been examined). -
add
Add the given SAMRecordIndex to the buffer. The records must be added in order.- Parameters:
samRecordWithOrdinal
- The samRecordWithOrdinal to be added
-
next
Returns the next element in the iteration.- Returns:
- The next element in the iteration.
- Throws:
NoSuchElementException
- if the buffer is empty.SAMException
- if the buffer is not competent to emit (canEmit returns false)
-
remove
public void remove()Removes the next record from this buffer -
size
public long size()Return the total number of elements in the queue, both in memory and on disk -
contains
Returns true if this buffer contains the record at the given index, false otherwise -
setResultState
Mark the current samRecordWithOrdinal as having been examined.- Parameters:
samRecordWithOrdinal
- The samRecordWithOrdinal to be markedresultState
- Boolean flag indicating the result of the examination of this record.- Throws:
SAMException
- if the provided recordIndex is not found within the SamRecordTrackingBuffer
-
close
public void close()Close IO resources associated with each underlying BufferBlock
-