private int getHitRegion(RPChromosomeRegion hitRegion, boolean contained) { int hitCount = 0; // check if new hit list is needed // Note: getHitList will reset mLeafItemIndex to 0, the beginning of new hit list if (leafHitList == null) { //|| mLeafItemIndex >= mLeafHitList.size()){ hitCount = getHitList(hitRegion, contained); if (hitCount == 0) return 0; // no hit data found } else { hitCount = leafHitList.size() - leafItemIndex; if (hitCount == 0) return 0; // hit list exhausted } // Perform a block read for starting base of selection region - use first leaf hit dataBlockRead = getDataBlock(leafItemIndex++); // try next item - probably intersection issue // Note: recursive call until a block is valid or hit list exhuasted if (!dataBlockRead) hitCount = getHitRegion(hitRegion, contained); return hitCount; }
protected List<LocusScore> getZoomSummaryScores(String chr, int start, int end, int zoom) { Chromosome c = genome.getChromosome(chr); if (c == null) return null; double nBins = Math.pow(2, zoom); double scale = c.getLength() / (nBins * 700); BBZoomLevelHeader zlHeader = getZoomLevelForScale(scale); if (zlHeader == null) return null; int bbLevel = zlHeader.getZoomLevel(); int reductionLevel = zlHeader.getReductionLevel(); // If we are at the highest precomputed resolution compare to the requested resolution. If they differ // by more than a factor of 2 compute "on the fly" String tmp = chrNameMap.get(chr); String querySeq = tmp == null ? chr : tmp; if (reader.isBigBedFile() || bbLevel > 1 || (bbLevel == 1 && (reductionLevel / scale) < 2)) { ArrayList<LocusScore> scores = new ArrayList(1000); ZoomLevelIterator zlIter = reader.getZoomLevelIterator(bbLevel, querySeq, start, querySeq, end, false); while (zlIter.hasNext()) { ZoomDataRecord rec = zlIter.next(); float v = getValue(rec); BasicScore bs = new BasicScore(rec.getChromStart(), rec.getChromEnd(), v); scores.add(bs); } return scores; } else { // No precomputed scores for this resolution level return null; } }
public int setSelectionRegion(RPChromosomeRegion selectionRegion, boolean contained) { this.selectionRegion = selectionRegion; isContained = contained; // set up hit list and first data block read leafHitList = null; // Must nullify existing hit list first! int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) // no hits - no point in fetching data throw new RuntimeException("No wig data found in the selection region"); // Ready for next() data extraction return hitCount; }
ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained);
public int setSelectionRegion(RPChromosomeRegion selectionRegion, boolean contained) { this.selectionRegion = selectionRegion; isContained = contained; // set up hit list and first data block read leafHitList = null; // Must nullify existing hit list first! int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) // no hits - no point in fetching data throw new RuntimeException("No wig data found in the selection region"); // Ready for next() data extraction return hitCount; }
ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained);
private int getHitRegion(RPChromosomeRegion hitRegion, boolean contained) { int hitCount = 0; // check if new hit list is needed // Note: getHitList will reset mLeafItemIndex to 0, the beginning of new hit list if (leafHitList == null) { //|| mLeafItemIndex >= mLeafHitList.size()){ hitCount = getHitList(hitRegion, contained); if (hitCount == 0) return 0; // no hit data found } else { hitCount = leafHitList.size() - leafItemIndex; if (hitCount == 0) return 0; // hit list exhausted } // Perform a block read for starting base of selection region - use first leaf hit dataBlockRead = getDataBlock(leafItemIndex++); // try next item - probably intersection issue // Note: recursive call until a block is valid or hit list exhuasted if (!dataBlockRead) hitCount = getHitRegion(hitRegion, contained); return hitCount; }
public int setSelectionRegion(RPChromosomeRegion selectionRegion, boolean contained) { this.selectionRegion = selectionRegion; isContained = contained; // set up hit list and first data block read leafHitList = null; // Must nullify existing hit list first! int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) // no hits - no point in fetching data throw new RuntimeException("No wig data found in the selection region"); // Ready for next() data extraction return hitCount; }
/** * Returns an iterator for zoom level records for all chromosome regions. * <p/> * Note: the BBFile can be BigBed or BigWig. * <p/> * Parameters: * zoomLevel - zoom level for data extraction; levels start at 1 * <p/> * Returns: * Iterator to provide BedFeature(s) for the requested chromosome region. * Error conditions: * 1) An empty iterator is returned if region has no data available */ synchronized public ZoomLevelIterator getZoomLevelIterator(int zoomLevel) { // check for valid zoom level if (zoomLevel < 1 || zoomLevel > zoomLevelCount) throw new RuntimeException("Error: ZoomLevelIterator zoom level is out of range\n"); // get the appropriate zoom level R+ zoom data index tree RPTree zoomDataTree = zoomLevels.getZoomLevelRPTree(zoomLevel); // get all regions bounds RPChromosomeRegion selectionRegion = zoomDataTree.getChromosomeBounds(); // compose an iterator boolean contained = true; //all regions are contained ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained); return zoomIterator; }
private int getHitRegion(RPChromosomeRegion hitRegion, boolean contained) { int hitCount = 0; // check if new hit list is needed // Note: getHitList will reset mLeafItemIndex to 0, the beginning of new hit list if (leafHitList == null) { //|| mLeafItemIndex >= mLeafHitList.size()){ hitCount = getHitList(hitRegion, contained); if (hitCount == 0) return 0; // no hit data found } else { hitCount = leafHitList.size() - leafItemIndex; if (hitCount == 0) return 0; // hit list exhausted } // Perform a block read for starting base of selection region - use first leaf hit dataBlockRead = getDataBlock(leafItemIndex++); // try next item - probably intersection issue // Note: recursive call until a block is valid or hit list exhuasted if (!dataBlockRead) hitCount = getHitRegion(hitRegion, contained); return hitCount; }
ZoomDataRecord wItem; int length, chunkStart, chunkEnd; while (zoomIterator.hasNext()) { wItem = zoomIterator.next(); chunkStart = (Math.max(region.getStart(), wItem.getChromStart()) - region.getStart()) / windowSize; chunkEnd = (Math.min(region.getEnd(), wItem.getChromEnd()) - region.getStart() - 1) / windowSize;
int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) { empty = true;
/** * Returns an iterator for zoom level records for all chromosome regions. * <p/> * Note: the BBFile can be BigBed or BigWig. * <p/> * Parameters: * zoomLevel - zoom level for data extraction; levels start at 1 * <p/> * Returns: * Iterator to provide BedFeature(s) for the requested chromosome region. * Error conditions: * 1) An empty iterator is returned if region has no data available */ public ZoomLevelIterator getZoomLevelIterator(int zoomLevel) { // check for valid zoom level if (zoomLevel < 1 || zoomLevel > zoomLevelCount) throw new RuntimeException("Error: ZoomLevelIterator zoom level is out of range\n"); // get the appropriate zoom level R+ zoom data index tree RPTree zoomDataTree = zoomLevels.getZoomLevelRPTree(zoomLevel); // get all regions bounds RPChromosomeRegion selectionRegion = zoomDataTree.getChromosomeBounds(); // compose an iterator boolean contained = true; //all regions are contained ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained); return zoomIterator; }
@Test public void testBigBed() throws IOException { String path = TestUtils.DATA_DIR + "bb/chr21.refseq.bb"; BBFileReader bbReader = new BBFileReader(path); BBFileHeader bbFileHdr = bbReader.getBBFileHeader(); assertTrue(bbFileHdr.isBigBed()); String chr = "chr21"; int start = 26490012; int end = 42182827; for (BBZoomLevelHeader header : bbReader.getZoomLevels().getZoomLevelHeaders()) { assertNotNull(header); ZoomLevelIterator zlIter = bbReader.getZoomLevelIterator(header.getZoomLevel(), chr, start, chr, end, false); while (zlIter.hasNext()) { ZoomDataRecord rec = zlIter.next(); int n = rec.getBasesCovered(); if (n > 0) { assertEquals(chr, rec.getChromName()); assertTrue(rec.getChromEnd() >= start && rec.getChromStart() <= end); } } } }
int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) { empty = true;
/** * Returns an iterator for zoom level records for all chromosome regions. * <p/> * Note: the BBFile can be BigBed or BigWig. * <p/> * Parameters: * zoomLevel - zoom level for data extraction; levels start at 1 * <p/> * Returns: * Iterator to provide BedFeature(s) for the requested chromosome region. * Error conditions: * 1) An empty iterator is returned if region has no data available */ public ZoomLevelIterator getZoomLevelIterator(int zoomLevel) { // check for valid zoom level if (zoomLevel < 1 || zoomLevel > zoomLevelCount) throw new RuntimeException("Error: ZoomLevelIterator zoom level is out of range\n"); // get the appropriate zoom level R+ zoom data index tree RPTree zoomDataTree = zoomLevels.getZoomLevelRPTree(zoomLevel); // get all regions bounds RPChromosomeRegion selectionRegion = zoomDataTree.getChromosomeBounds(); // compose an iterator boolean contained = true; //all regions are contained ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained); return zoomIterator; }
int hitCount = getHitRegion(selectionRegion, contained); if (hitCount == 0) { empty = true;
ZoomLevelIterator zoomIterator = new ZoomLevelIterator(fis, chromosomeIDTree, zoomDataTree, zoomLevel, selectionRegion, contained);