Class MergingSamRecordIterator

java.lang.Object
htsjdk.samtools.MergingSamRecordIterator
All Implemented Interfaces:
CloseableIterator<SAMRecord>, Closeable, AutoCloseable, Iterator<SAMRecord>

public class MergingSamRecordIterator extends Object implements CloseableIterator<SAMRecord>
Provides an iterator interface for merging multiple underlying iterators into a single iterable stream. The underlying iterators/files must all have the same sort order unless the requested output format is unsorted, in which case any combination is valid.
  • Constructor Details

    • MergingSamRecordIterator

      @Deprecated public MergingSamRecordIterator(SamFileHeaderMerger headerMerger, boolean forcePresorted)
      Constructs a new merging iterator with the same set of readers and sort order as provided by the header merger parameter.
      Parameters:
      headerMerger - The merged header and contents of readers.
      forcePresorted - True to ensure that the iterator checks the headers of the readers for appropriate sort order.
    • MergingSamRecordIterator

      public MergingSamRecordIterator(SamFileHeaderMerger headerMerger, Collection<SamReader> readers, boolean assumeSorted)
      Constructs a new merging iterator with the same set of readers and sort order as provided by the header merger parameter.
      Parameters:
      headerMerger - The merged header and contents of readers.
      assumeSorted - false ensures that the iterator checks the headers of the readers for appropriate sort order.
    • MergingSamRecordIterator

      public MergingSamRecordIterator(SamFileHeaderMerger headerMerger, Map<SamReader,CloseableIterator<SAMRecord>> iterators, boolean assumeSorted)
      Add a set of SAM file iterators to the merging iterator. Use this to restrict the merged iteration to a given genomic interval, rather than iterating over every read in the backing file or stream.
      Parameters:
      headerMerger - The merged header and contents of readers.
      iterators - Iterator traversing over reader contents.
  • Method Details

    • close

      public void close()
      Close down all open iterators.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CloseableIterator<SAMRecord>
    • hasNext

      public boolean hasNext()
      Returns true if any of the underlying iterators has more records, otherwise false.
      Specified by:
      hasNext in interface Iterator<SAMRecord>
    • next

      public SAMRecord next()
      Returns the next record from the top most iterator during merging.
      Specified by:
      next in interface Iterator<SAMRecord>
    • remove

      public void remove()
      Unsupported operation.
      Specified by:
      remove in interface Iterator<SAMRecord>
    • getMergedHeader

      public SAMFileHeader getMergedHeader()
      Returns the merged header that the merging iterator is working from.