Package htsjdk.samtools

# Class BamFileIoUtils

java.lang.Object
htsjdk.samtools.BamFileIoUtils

public class BamFileIoUtils extends Object

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BAM_FILE_EXTENSION`
Deprecated.
since June 2019 Use `FileExtensions.BAM` instead.

## Constructor Summary

Constructors
Constructor
Description
`BamFileIoUtils()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`blockCopyBamFile(File inputFile, OutputStream outputStream, boolean skipHeader, boolean skipTerminator)`
`static void`
`blockCopyBamFile(Path inputFile, OutputStream outputStream, boolean skipHeader, boolean skipTerminator)`
Copy data from a BAM file to an OutputStream by directly copying the gzip blocks.
`static void`
`gatherWithBlockCopying(List<File> bams, File output, boolean createIndex, boolean createMd5)`
Assumes that all inputs and outputs are block compressed VCF files and copies them without decompressing and parsing most of the gzip blocks.
`static boolean`
`isBamFile(File file)`
`static void`
`reheaderBamFile(SAMFileHeader samFileHeader, File inputFile, File outputFile, boolean createMd5, boolean createIndex)`
Support File input types for backward compatibility.
`static void`
`reheaderBamFile(SAMFileHeader samFileHeader, Path inputFile, Path outputFile)`
`static void`
`reheaderBamFile(SAMFileHeader samFileHeader, Path inputFile, Path outputFile, boolean createMd5, boolean createIndex)`
Copy a BAM file but replacing the header

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

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

## Field Details

### BAM_FILE_EXTENSION

@Deprecated public static final String BAM_FILE_EXTENSION
Deprecated.
since June 2019 Use `FileExtensions.BAM` instead.

See Also:
  - Constant Field Values

## Constructor Details

### BamFileIoUtils

public BamFileIoUtils()

## Method Details

### isBamFile

public static boolean isBamFile(File file)

### reheaderBamFile

public static void reheaderBamFile(SAMFileHeader samFileHeader, Path inputFile, Path outputFile)

### reheaderBamFile

public static void reheaderBamFile(SAMFileHeader samFileHeader, File inputFile, File outputFile, boolean createMd5, boolean createIndex)
Support File input types for backward compatibility. Use the same method with Path inputs below.

### reheaderBamFile

public static void reheaderBamFile(SAMFileHeader samFileHeader, Path inputFile, Path outputFile, boolean createMd5, boolean createIndex)
Copy a BAM file but replacing the header

Parameters:
  `samFileHeader` - The header to use in the new file
  `inputFile` - The BAM file to copy, sans header
  `outputFile` - The new BAM file, constructed with the new header and the content from inputFile
  `createMd5` - Whether or not to create an MD5 file for the new BAM
  `createIndex` - Whether or not to create an index file for the new BAM

### blockCopyBamFile

public static void blockCopyBamFile(File inputFile, OutputStream outputStream, boolean skipHeader, boolean skipTerminator)

### blockCopyBamFile

public static void blockCopyBamFile(Path inputFile, OutputStream outputStream, boolean skipHeader, boolean skipTerminator)
Copy data from a BAM file to an OutputStream by directly copying the gzip blocks.

Parameters:
  `inputFile` - The BAM file to be copied
  `outputStream` - The stream to write the copied data to
  `skipHeader` - If true, the header of the input file will not be copied to the output stream
  `skipTerminator` - If true, the terminator block of the input file will not be written to the output stream

### gatherWithBlockCopying

public static void gatherWithBlockCopying(List<File> bams, File output, boolean createIndex, boolean createMd5)
Assumes that all inputs and outputs are block compressed VCF files and copies them without decompressing and parsing most of the gzip blocks. Will decompress and parse blocks up to the one containing the end of the header in each file (often the first block) and re-compress any data remaining in that block into a new block in the output file. Subsequent blocks (excluding a terminator block if present) are copied directly from input to output.