use of org.broad.igv.tdf.TDFDataset in project ASCIIGenome by dariober.
the class TrackWiggles method tdfRangeToScreen.
/**
* Fetch data in tdf file in given range and puts it in a list of ScreenWiggleLocusInfo.
* a Adapted from dumpRange. Really it should implement iterator.
* @param genomeToScreenMapping Typically from GenomicCoords.getMapping()
*
* @author berald01
*/
private List<ScreenWiggleLocusInfo> tdfRangeToScreen(String ibfFile, String chrom, int startLocation, int endLocation, List<Double> genomeToScreenMapping) {
List<ScreenWiggleLocusInfo> screenWiggleLocusInfoList = new ArrayList<ScreenWiggleLocusInfo>();
for (int i = 0; i < genomeToScreenMapping.size(); i++) {
screenWiggleLocusInfoList.add(new ScreenWiggleLocusInfo());
}
TDFReader reader = TDFReader.getReader(ibfFile);
for (String dsName : reader.getDatasetNames()) {
String[] tokens = dsName.split("/");
String chrName = tokens[1];
if (!chrName.equals(chrom) || !dsName.contains("raw")) {
// Not the right chrom or track
continue;
}
TDFDataset ds = reader.getDataset(dsName);
int tileWidth = ds.getTileWidth();
int startTile = startLocation / tileWidth;
int endTile = endLocation / tileWidth;
for (int tileNumber = startTile; tileNumber <= endTile; tileNumber++) {
TDFTile tile = reader.readTile(ds, tileNumber);
if (tile == null) {
// System.out.println("Null tile: " + dsName + " [" + tileNumber + "]");
} else {
int nTracks = reader.getTrackNames().length;
if (nTracks > 1) {
throw new RuntimeException("More than one track found in tdf file " + ibfFile);
}
int nBins = tile.getSize();
if (nBins > 0) {
for (int b = 0; b < nBins; b++) {
int start = tile.getStartPosition(b);
int end = tile.getEndPosition(b);
if (start > endLocation) {
break;
}
if (end >= startLocation) {
int tileStartPos = tile.getStartPosition(b);
float tileValue = tile.getValue(0, b);
// Where should this position be mapped on screen?
int idx = Utils.getIndexOfclosestValue(tileStartPos + 1, genomeToScreenMapping);
screenWiggleLocusInfoList.get(idx).increment(tileValue);
}
}
// End process bins in this tile
}
}
// End process this tile
}
// End iter tiles
}
// End iter datasets names
reader.close();
return screenWiggleLocusInfoList;
}
Aggregations