Class BAMIndexer

java.lang.Object
htsjdk.samtools.BAMIndexer

public class BAMIndexer extends Object
Class for both constructing BAM index content and writing it out. There are two usage patterns: 1) Building a bam index from an existing bam file 2) Building a bam index while building the bam file In both cases, processAlignment is called for each alignment record and finish() is called at the end.
  • Constructor Details

    • BAMIndexer

      public BAMIndexer(Path output, SAMFileHeader fileHeader)
      Parameters:
      output - binary BAM Index (.bai) file
      fileHeader - header for the corresponding bam file
    • BAMIndexer

      public BAMIndexer(File output, SAMFileHeader fileHeader)
      Parameters:
      output - binary BAM Index (.bai) file
      fileHeader - header for the corresponding bam file
    • BAMIndexer

      public BAMIndexer(OutputStream output, SAMFileHeader fileHeader)
      Prepare to index a BAM.
      Parameters:
      output - Index will be written here. output will be closed when finish() method is called.
      fileHeader - header for the corresponding bam file.
    • BAMIndexer

      public BAMIndexer(OutputStream output, SAMFileHeader fileHeader, boolean fillInUninitializedValues)
      Prepare to index a BAM.
      Parameters:
      output - Index will be written here. output will be closed when finish() method is called.
      fileHeader - header for the corresponding bam file.
      fillInUninitializedValues - if true, set uninitialized values (-1) to the last non-zero offset; if false, leave uninitialized values as -1, which is required when merging index files (see BAMIndexMerger)
  • Method Details

    • processAlignment

      public void processAlignment(SAMRecord rec)
      Record any index information for a given BAM record. If this alignment starts a new reference, write out the old reference. Requires a non-null value for rec.getFileSource().
      Parameters:
      rec - The BAM record
    • finish

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

      public static void createAndWriteIndex(File input, File output, boolean textOutput)
      Generates a BAM index file, either textual or binary, from an input BAI file. Only used for testing, but located here for visibility into CachingBAMFileIndex.
      Parameters:
      output - BAM Index (.bai) file (or bai.txt file when text)
      textOutput - Whether to create text output or binary
    • createIndex

      public static void createIndex(SamReader reader, Path output)
      Generates a BAM index file from an input BAM file
      Parameters:
      reader - SamReader for input BAM file
      output - Path for output index file
    • createIndex

      public static void createIndex(SamReader reader, File output)
      Generates a BAM index file from an input BAM file
      Parameters:
      reader - SamReader for input BAM file
      output - File for output index file
    • createIndex

      public static void createIndex(SamReader reader, Path output, Log log)
      Generates a BAM index file from an input BAM file
      Parameters:
      reader - SamReader for input BAM file
      output - Path for output index file
    • createIndex

      public static void createIndex(SamReader reader, File output, Log log)
      Generates a BAM index file from an input BAM file
      Parameters:
      reader - SamReader for input BAM file
      output - File for output index file