use of org.broad.igv.tdf.TDFReader in project ASCIIGenome by dariober.
the class TrackWiggles method getAttributesFromTDF.
private String getAttributesFromTDF(String attr) {
String path = this.getWorkFilename();
try {
ResourceLocator resourceLocator = new ResourceLocator(path);
TDFReader reader = new TDFReader(resourceLocator);
TDFGroup rootGroup = reader.getGroup("/");
return rootGroup.getAttribute(attr);
} catch (Exception e) {
return null;
}
}
use of org.broad.igv.tdf.TDFReader in project ASCIIGenome by dariober.
the class TrackWiggles method getChromosomeNames.
@Override
public List<String> getChromosomeNames() {
if (this.getTrackFormat().equals(TrackFormat.TDF)) {
ResourceLocator resourceLocator = new ResourceLocator(this.getWorkFilename());
TDFReader reader = new TDFReader(resourceLocator);
List<String> chroms = new ArrayList<String>(reader.getChromosomeNames());
if (chroms.get(0).equals("All")) {
chroms.remove(0);
}
return chroms;
// chroms.addAll();
}
if (this.getTrackFormat().equals(TrackFormat.BEDGRAPH)) {
TabixIndex tbi = (TabixIndex) IndexFactory.loadIndex(this.getWorkFilename() + TabixUtils.STANDARD_INDEX_EXTENSION);
return tbi.getSequenceNames();
}
if (this.getTrackFormat().equals(TrackFormat.BIGWIG)) {
return this.bigWigReader.getChromosomeNames();
}
return null;
}
use of org.broad.igv.tdf.TDFReader 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