Package htsjdk.samtools

# Class CRAMBAIIndexer

java.lang.Object
htsjdk.samtools.CRAMBAIIndexer

All Implemented Interfaces:
  `CRAMIndexer`

public class CRAMBAIIndexer extends Object implements CRAMIndexer
Class for both constructing BAM index content and writing it out. There are two usage patterns: 1) Building a bam index (BAI) while building the CRAM file 2) Building a bam index (BAI) from an existing CRAI file 1) is driven by `CRAMContainerStreamWriter` and proceeds by calling `processContainer(htsjdk.samtools.cram.structure.Container, htsjdk.samtools.ValidationStringency)` after each `Container` is built, and `finish()` is called at the end. 2) is driven by `CRAIIndex.openCraiFileAsBaiStream(InputStream, SAMSequenceDictionary)` and proceeds by processing `CRAIEntry` elements obtained from `CRAMCRAIIndexer.readIndex(InputStream)`. `processBAIEntry(BAIEntry)` is called on each `CRAIEntry` and `finish()` is called at the end. NOTE: a third pattern of building a BAI from a CRAM file is also supported by this class, but it is unused. This would be accomplished via `createIndex(SeekableStream, File, Log, ValidationStringency)`.

## Constructor Summary

Constructors
Constructor
Description
`CRAMBAIIndexer(OutputStream output, SAMFileHeader fileHeader)`
Create a CRAM indexer that writes BAI to a stream.

## Method Summary

Modifier and Type
Method
Description
`static void`
`createIndex(SeekableStream stream, File output, Log log, ValidationStringency validationStringency)`
Generates a BAI index file from an input CRAM stream
`void`
`finish()`
After all the slices have been processed, finish is called.
`final void`
`processBAIEntry(BAIEntry baiEntry)`
`void`
`processContainer(Container container, ValidationStringency validationStringency)`
Index a container, any of mapped, unmapped and multiple references are allowed.

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

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

## Constructor Details

### CRAMBAIIndexer

public CRAMBAIIndexer(OutputStream output, SAMFileHeader fileHeader)
Create a CRAM indexer that writes BAI to a stream.

Parameters:
  `output` - Index will be written here. output will be closed when finish() method is called.
  `fileHeader` - header for the corresponding bam file.

## Method Details

### processContainer

public void processContainer(Container container, ValidationStringency validationStringency)
Index a container, any of mapped, unmapped and multiple references are allowed. The only requirement is sort order by coordinate. For multiref containers the method reads the container through unpacking all reads. This is slower than single reference but should be faster than normal reading.

Specified by:
  `processContainer` in interface `CRAMIndexer`
Parameters:
  `container` - container to be indexed
  `validationStringency` - stringency for validating records (used when processing multi-reference slices, since creating an index on a multi-ref slices requires actually decoding the records in order to resove the constituent reference spans}

### processBAIEntry

public final void processBAIEntry(BAIEntry baiEntry)

### finish

public void finish()
After all the slices have been processed, finish is called. Writes any final information and closes the output file.

Specified by:
  `finish` in interface `CRAMIndexer`

### createIndex

public static void createIndex(SeekableStream stream, File output, Log log, ValidationStringency validationStringency)
Generates a BAI index file from an input CRAM stream

Parameters:
  `stream` - CRAM stream to index
  `output` - File for output index file
  `log` - optional `Log` to output progress