@Override public SamReader.Type type() { if (mIndexFile != null && getIndexType().equals(SamIndexes.CSI)) { return SamReader.Type.BAM_CSI_TYPE; } return SamReader.Type.BAM_TYPE; }
@Test (expectedExceptions = SAMFormatException.class) public static void testGetIndexTypeException() { Assert.assertTrue(bamFileReaderWrong.getIndexType().equals(SamIndexes.BAI)); }
@Test public static void testGetIndexTypeDefault() { Assert.assertTrue(bamFileReaderNull.getIndexType().equals(SamIndexes.BAI)); }
@Test public static void testGetIndexTypeOK() { BAMIndexMetaData.printIndexStats(bamFile); Assert.assertTrue(bamFileReaderBAI.getIndexType().equals(SamIndexes.BAI)); Assert.assertTrue(bamFileReaderCSI.getIndexType().equals(SamIndexes.CSI)); }
try { final BAMFileReader bam = new BAMFileReader(inputBamFile, null, false, false, ValidationStringency.SILENT, new DefaultSAMRecordFactory()); if (!bam.hasIndex() || bam.getIndexType() == null) { throw new SAMException("No index for bam file " + inputBamFile);
/** * Retrieves the index for the given file type. Ensure that the index is of the specified type. * @return An index of the given type. */ @Override public BAMIndex getIndex() { if(!hasIndex()) throw new SAMException("No index is available for this BAM file."); if(mIndex == null) { SamIndexes samIndex = getIndexType(); if (samIndex == null) { mIndex = mEnableIndexCaching ? new CachingBAMFileIndex(mIndexStream, getFileHeader().getSequenceDictionary()) : new DiskBasedBAMFileIndex(mIndexStream, getFileHeader().getSequenceDictionary()); } else if (samIndex.equals(SamIndexes.BAI)) { mIndex = mEnableIndexCaching ? new CachingBAMFileIndex(mIndexFile, getFileHeader().getSequenceDictionary(), mEnableIndexMemoryMapping) : new DiskBasedBAMFileIndex(mIndexFile, getFileHeader().getSequenceDictionary(), mEnableIndexMemoryMapping); } else if (samIndex.equals(SamIndexes.CSI)) { mIndex = new CSIIndex(mIndexFile, mEnableIndexMemoryMapping, getFileHeader().getSequenceDictionary()); } else { throw new SAMFormatException("Unsupported BAM index file: " + mIndexFile.getName()); } } return mIndex; }