Search in sources :

Example 1 with BAMIndexer

use of htsjdk.samtools.BAMIndexer in project gatk by broadinstitute.

the class CreateHadoopBamSplittingIndex method createBaiAndSplittingIndex.

private static void createBaiAndSplittingIndex(final File inputBam, final File index, final int granularity, final ValidationStringency readValidationStringency) {
    assertIsBam(inputBam);
    try (SamReader reader = SamReaderFactory.makeDefault().validationStringency(readValidationStringency).setOption(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, true).open(inputBam);
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(index))) {
        final SAMFileHeader header = reader.getFileHeader();
        assertBamIsCoordinateSorted(header);
        final SplittingBAMIndexer indexer = new SplittingBAMIndexer(out, granularity);
        final BAMIndexer bamIndexer = new BAMIndexer(IOUtils.replaceExtension(index, BAMIndex.BAMIndexSuffix), header);
        for (final SAMRecord read : reader) {
            indexer.processAlignment(read);
            bamIndexer.processAlignment(read);
        }
        indexer.finish(inputBam.length());
        bamIndexer.finish();
    } catch (final IOException e) {
        throw new UserException("Couldn't create splitting index", e);
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) FileOutputStream(java.io.FileOutputStream) BAMIndexer(htsjdk.samtools.BAMIndexer) SplittingBAMIndexer(org.seqdoop.hadoop_bam.SplittingBAMIndexer) SAMRecord(htsjdk.samtools.SAMRecord) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BufferedOutputStream(java.io.BufferedOutputStream) SplittingBAMIndexer(org.seqdoop.hadoop_bam.SplittingBAMIndexer)

Aggregations

BAMIndexer (htsjdk.samtools.BAMIndexer)1 SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SAMRecord (htsjdk.samtools.SAMRecord)1 SamReader (htsjdk.samtools.SamReader)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 UserException (org.broadinstitute.hellbender.exceptions.UserException)1 SplittingBAMIndexer (org.seqdoop.hadoop_bam.SplittingBAMIndexer)1