Search in sources :

Example 1 with TDFReader

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;
    }
}
Also used : TDFGroup(org.broad.igv.tdf.TDFGroup) TDFReader(org.broad.igv.tdf.TDFReader) InvalidColourException(exceptions.InvalidColourException) InvalidRecordException(exceptions.InvalidRecordException) SQLException(java.sql.SQLException) IOException(java.io.IOException) InvalidGenomicCoordsException(exceptions.InvalidGenomicCoordsException) ResourceLocator(org.broad.igv.util.ResourceLocator)

Example 2 with TDFReader

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;
}
Also used : ArrayList(java.util.ArrayList) MakeTabixIndex(sortBgzipIndex.MakeTabixIndex) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) TDFReader(org.broad.igv.tdf.TDFReader) ResourceLocator(org.broad.igv.util.ResourceLocator)

Example 3 with TDFReader

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;
}
Also used : TDFTile(org.broad.igv.tdf.TDFTile) TDFDataset(org.broad.igv.tdf.TDFDataset) ArrayList(java.util.ArrayList) TDFReader(org.broad.igv.tdf.TDFReader)

Aggregations

TDFReader (org.broad.igv.tdf.TDFReader)3 ArrayList (java.util.ArrayList)2 ResourceLocator (org.broad.igv.util.ResourceLocator)2 InvalidColourException (exceptions.InvalidColourException)1 InvalidGenomicCoordsException (exceptions.InvalidGenomicCoordsException)1 InvalidRecordException (exceptions.InvalidRecordException)1 TabixIndex (htsjdk.tribble.index.tabix.TabixIndex)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 TDFDataset (org.broad.igv.tdf.TDFDataset)1 TDFGroup (org.broad.igv.tdf.TDFGroup)1 TDFTile (org.broad.igv.tdf.TDFTile)1 MakeTabixIndex (sortBgzipIndex.MakeTabixIndex)1