private int getHitRegion(RPChromosomeRegion hitRegion, boolean contained) { int hitCount = 0; // check if new hit list is needed if(leafHitList == null){ 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 boolean hasNext() { return bedIterator.hasNext(); //To change body of implemented methods use File | Settings | File Templates. }
public MethylScore next() { BedFeature feat = null; while (feat == null && bedIterator.hasNext()) { feat = bedIterator.next(); String[] restOfFields = feat.getRestOfFields(); MethylScore score = type == Type.ZILLER ? createZillerScore(feat, restOfFields) : createUSCScore(feat, restOfFields); return score; } return null; }
return new BigBedIterator(); // an empty iterator BigBedIterator bedIterator = new BigBedIterator(fis, chromosomeIDTree, chromosomeDataTree, selectionRegion, contained);
public int setSelectionRegion(RPChromosomeRegion selectionRegion, boolean contained) { this.selectionRegion = selectionRegion; this.contained = 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; }
public Feature next() { BedFeature feat = bedIterator.next(); String[] restOfFields = feat.getRestOfFields(); String[] tokens = new String[restOfFields.length + 3]; tokens[0] = feat.getChromosome(); tokens[1] = String.valueOf(feat.getStartBase()); tokens[2] = String.valueOf(feat.getEndBase()); System.arraycopy(restOfFields, 0, tokens, 3, restOfFields.length); BasicFeature feature = bedCodec.decode(tokens); return feature; }
features = new ArrayList<BedFeature>(512 * leafNodeItems.size()); for (RPTreeLeafNodeItem item : leafNodeItems) { features.addAll(readBedDataBlock(item));
protected String next() throws IOException{ if(this.tabixIterator != null){ return this.tabixIterator.next(); } else if(this.bigBedIterator != null) { if( ! this.bigBedIterator.hasNext()){ return null; } BedFeature x= this.bigBedIterator.next(); if(x == null){ return null; } StringBuilder sb= new StringBuilder(); sb.append(x.getChromosome()); sb.append("\t"); sb.append(x.getStartBase()); sb.append("\t"); sb.append(x.getEndBase()); for(String field : x.getRestOfFields()){ sb.append("\t"); sb.append(field); } return sb.toString(); } else { throw new RuntimeException(); } }
return new BigBedIterator(); // an empty iterator BigBedIterator bedIterator = new BigBedIterator(fis, chromosomeIDTree, chromosomeDataTree, selectionRegion, contained);
public int setSelectionRegion(RPChromosomeRegion selectionRegion, boolean contained) { this.selectionRegion = selectionRegion; this.contained = 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; }
private int getHitRegion(RPChromosomeRegion hitRegion, boolean contained) { int hitCount = 0; // check if new hit list is needed if(leafHitList == null){ 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; }
private static String initRegionFromBigBed(String bigBedFile) throws IOException{ BBFileReader reader= new BBFileReader(bigBedFile); if(! reader.isBigBedFile()){ System.err.println("File " + bigBedFile + " is not bigBed."); throw new RuntimeException(); } String region= reader.getChromosomeNames().get(0); // Just get chrom to start with for(String chrom : reader.getChromosomeNames()){ BigBedIterator iter = reader.getBigBedIterator(chrom, 0, chrom, Integer.MAX_VALUE, false); if(iter.hasNext()){ BedFeature x= (BedFeature) iter.next(); region= x.getChromosome() + ":" + (x.getStartBase() + 1); reader.close(); return region; } } reader.close(); return region; }
return new BigBedIterator(); // an empty iterator BigBedIterator bedIterator = new BigBedIterator(fis, chromosomeIDTree, chromosomeDataTree, selectionRegion, contained);
int hitCount = getHitRegion(selectionRegion, contained); if(hitCount == 0) // no hits - no point in fetching data empty = true;
public boolean hasNext() { return bedIterator.hasNext(); //To change body of implemented methods use File | Settings | File Templates. }
/** * Returns an iterator for BigBed features for all chromosome regions. * <p/> * Note: the BBFile type should be BigBed; else a null iterator is returned. * <p/> * Returns: * Iterator to provide BedFeature(s) for all chromosome regions. * Error conditions: * 1) An empty iterator is returned if region has no data available * 2) A null object is returned if the file is not BigBed.(see isBigBedFile method) */ public BigBedIterator getBigBedIterator() { if (!isBigBedFile()) return null; // get all region bounds RPChromosomeRegion selectionRegion = chromosomeDataTree.getChromosomeBounds(); // compose an iterator boolean contained = true; /// all regions are contained BigBedIterator bedIterator = new BigBedIterator(fis, chromosomeIDTree, chromosomeDataTree, selectionRegion, contained); return bedIterator; }
int hitCount = getHitRegion(selectionRegion, contained); if(hitCount == 0) // no hits - no point in fetching data empty = true;
/** * Returns an iterator for BigBed features for all chromosome regions. * <p/> * Note: the BBFile type should be BigBed; else a null iterator is returned. * <p/> * Returns: * Iterator to provide BedFeature(s) for all chromosome regions. * Error conditions: * 1) An empty iterator is returned if region has no data available * 2) A null object is returned if the file is not BigBed.(see isBigBedFile method) */ public BigBedIterator getBigBedIterator() { if (!isBigBedFile()) return null; // get all region bounds RPChromosomeRegion selectionRegion = chromosomeDataTree.getChromosomeBounds(); // compose an iterator boolean contained = true; /// all regions are contained BigBedIterator bedIterator = new BigBedIterator(fis, chromosomeIDTree, chromosomeDataTree, selectionRegion, contained); return bedIterator; }
/** * Method returns the current bed feature and advances to the next bed record. * * Returns: * Bed feature for current BigBed data record. * * Note: If "next" method is called when a "next item" does not exist, * an UnsupportedOperationException will be thrown. */ public BedFeature next() { // Is there a need to fetch next data block? if(bedFeatureIndex < bedFeatureList.size()) return(bedFeatureList.get(bedFeatureIndex++)); // attempt to get next leaf item data block else { int nHits = getHitRegion(selectionRegion, contained); if(nHits > 0){ // Note: getDataBlock initializes bed feature index to 0 return(bedFeatureList.get(bedFeatureIndex++)); // return 1st Data Block item } else{ String result = String.format("Failed to find data for bed region (%d,%d,%d,%d)\n", hitRegion.getStartChromID(), hitRegion.getStartBase(), hitRegion.getEndChromID(), hitRegion.getEndBase()); log.error(result); return null; //throw new NoSuchElementException(result); } } }
/** * Method returns the current bed feature and advances to the next bed record. * * Returns: * Bed feature for current BigBed data record. * * Note: If "next" method is called when a "next item" does not exist, * an UnsupportedOperationException will be thrown. */ public BedFeature next() { // Is there a need to fetch next data block? if(bedFeatureIndex < bedFeatureList.size()) return(bedFeatureList.get(bedFeatureIndex++)); // attempt to get next leaf item data block else { int nHits = getHitRegion(selectionRegion, contained); if(nHits > 0){ // Note: getDataBlock initializes bed feature index to 0 return(bedFeatureList.get(bedFeatureIndex++)); // return 1st Data Block item } else{ String result = String.format("Failed to find data for bed region (%d,%d,%d,%d)\n", hitRegion.getStartChromID(), hitRegion.getStartBase(), hitRegion.getEndChromID(), hitRegion.getEndBase()); log.error(result); return null; //throw new NoSuchElementException(result); } } }