/** * Computes the number of bins on the given level. * @param levelNumber Level for which to compute the size. * @return */ @Override public int getLevelSize(final int levelNumber) { if (levelNumber >= getBinDepth()) { throw new SAMException("Level number (" + levelNumber + ") is greater than or equal to maximum (" + getBinDepth() + ")."); } return 1<<3*(levelNumber); }
/** * Extends the functionality of {@link AbstractBAMFileIndex#getFirstBinInLevel(int)} , * which cannot be overridden due to its static nature. */ public int getFirstBinInLevelForCSI(final int levelNumber) { if (levelNumber >= getBinDepth()) { throw new SAMException("Level number (" + levelNumber + ") is greater than or equal to maximum (" + getBinDepth() + ")."); } return ((1<<3*levelNumber) - 1)/7; }
@Test public static void testGetNumIndexLevels() { Assert.assertEquals(csi.getBinDepth(), 6); Assert.assertEquals(ucsi.getBinDepth(), 7); } @Test
@Override public BinList getBinsOverlapping(int referenceIndex, int startPos, int endPos) { final BitSet regionBins = GenomicIndexUtil.regionToBins(startPos, endPos, getMinShift(), getBinDepth()); if (regionBins == null) { return null; } return new BinList(referenceIndex,regionBins); }
@Override public int getLevelForBin(Bin bin) { if(bin == null || bin.getBinNumber() > getMaxBins()) { throw new SAMException("Tried to get level for invalid bin: " + bin); } for (int i = getBinDepth()-1; i > -1 ; i--) { if (bin.getBinNumber() >= getFirstBinInLevelForCSI(i)) { return i; } } throw new SAMException("Unable to find correct level for bin: " + bin); }
/** * The maximum possible bin number for this reference sequence. * This is based on the maximum coordinate position of the reference * which is based on the size of the reference */ private int getMaxBinNumberForReference(final int reference) { try { final int sequenceLength = getBamDictionary().getSequence(reference).getSequenceLength(); return getFirstBinInLevelForCSI(getBinDepth() - 1) + (sequenceLength >> getMinShift()); } catch (final Exception e) { return getMaxBins(); } }
@Override public BAMFileSpan getSpanOverlapping(int referenceIndex, int startPos, int endPos) { final BAMIndexContent queryResults = query(referenceIndex, startPos, endPos); int initialBinNumber = getFirstBinInLevelForCSI(getBinDepth() - 1) + (startPos - 1 >> getMinShift()); long minimumOffset = 0L; Bin targetBin;
final BitSet regionBins = GenomicIndexUtil.regionToBins(startPos, endPos, getMinShift(), getBinDepth()); if (regionBins == null) { return null;