Package htsjdk.samtools

# 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 Summary

Constructors
Constructor
Description
`MergingSamRecordIterator(SamFileHeaderMerger headerMerger, boolean forcePresorted)`
Deprecated.
replaced by `MergingSamRecordIterator(SamFileHeaderMerger, Collection, boolean)`
`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.
`MergingSamRecordIterator(SamFileHeaderMerger headerMerger, Map<SamReader,CloseableIterator<SAMRecord>> iterators, boolean assumeSorted)`
Add a set of SAM file iterators to the merging iterator.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close down all open iterators.
`SAMFileHeader`
`getMergedHeader()`
Returns the merged header that the merging iterator is working from.
`boolean`
`hasNext()`
Returns true if any of the underlying iterators has more records, otherwise false.
`SAMRecord`
`next()`
Returns the next record from the top most iterator during merging.
`void`
`remove()`
Unsupported operation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface htsjdk.samtools.util.CloseableIterator

`stream, toList`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

## Constructor Details

### MergingSamRecordIterator

@Deprecated public MergingSamRecordIterator(SamFileHeaderMerger headerMerger, boolean forcePresorted)
Deprecated.
replaced by `MergingSamRecordIterator(SamFileHeaderMerger, Collection, boolean)`
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.