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);
}
}
Aggregations