@BeforeTest public void init() { bai = new DiskBasedBAMFileIndex(new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam.bai"), null); csi = new CSIIndex(new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam.csi"), false, null); mcsi = new CSIIndex(new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam.csi"), true, null); try { ucsi = new CSIIndex(Paths.get("src/test/resources/htsjdk/samtools/BAMFileIndexTest/uncompressed_index.bam.csi"), null); } catch (IOException e) { e.printStackTrace(); } ubai = new DiskBasedBAMFileIndex(new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/uncompressed_index.bam.bai"),null); }
/** * 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; }