Java Code Examples for org.broad.igv.bbfile.BBFileReader#getBigWigIterator()

The following examples show how to use org.broad.igv.bbfile.BBFileReader#getBigWigIterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FoldChange.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the data
 * @throws IOException
 */
private void set() throws IOException{
	MeanAndStd results = new MeanAndStd(w);
	mean = results.getMean();
	std = results.getStd();
	result = new ArrayList<TagNode>();
	BBFileReader wigReader = new BBFileReader(w);
	for (int i = 0;i < g.size();i++){
		String chrom = g.get(i).getChrom();
		int begin = g.get(i).getStart();
		int end = g.get(i).getStop();
		BigWigIterator iter = wigReader.getBigWigIterator(chrom,begin,chrom,end,false);
		while(iter.hasNext()){
			WigItem item = iter.next();
			int start = item.getStartBase();
			int stop = item.getEndBase();
			double value = item.getWigValue();
			if ((value/mean) >= l && (value/mean) <= u){
				TagNode temp = new TagNode(chrom,start,stop,(value/mean));
				result.add(temp);
			}
			
		}
	}
	wigReader=null;
}
 
Example 2
Source File: MeanAndStd.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the data across a specific region
 * @param node a TagNode representing a specific region for calculation
 * @throws IOException
 */
private void SetMeanAndStd2(TagNode node) throws IOException{
	BBFileReader wigReader = new BBFileReader(wigFile);
	String chrom = node.getChrom();
	int begin = node.getStart();
	int end = node.getStop();
	BigWigIterator iter = wigReader.getBigWigIterator(chrom, begin, chrom, end, false);
	Mean mu = new Mean();
	StandardDeviation dev = new StandardDeviation();
	while(iter.hasNext()){
		WigItem item = iter.next();
		int start = item.getStartBase();
		int stop = item.getEndBase();
		double value = item.getWigValue();
		for (int i = start; i < stop;i++){
			mu.increment(value);
			dev.increment(value);
		}
		
	}
	mean = mu.getResult();
	std = dev.getResult();
	wigReader=null;
}
 
Example 3
Source File: MeanAndStd.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the data across the entire genome
 * @throws IOException
 */
private void SetMeanAndStd() throws IOException{
	BBFileReader wigReader = new BBFileReader(wigFile);
	BigWigIterator iter = wigReader.getBigWigIterator();
	Mean mu = new Mean();
	StandardDeviation dev = new StandardDeviation();
	while(iter.hasNext()){
		WigItem item = iter.next();
		int start = item.getStartBase();
		int stop = item.getEndBase();
		double value = item.getWigValue();
		for (int i = start; i < stop;i++){
			mu.increment(value);
			dev.increment(value);
		}
		
	}
	mean = mu.getResult();
	std = dev.getResult();
}
 
Example 4
Source File: GetSignal.java    From HMMRATAC with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find the max and the max position
 * @throws IOException
 */
private void find() throws IOException{
	BBFileReader wigReader = new BBFileReader(wig);
	BigWigIterator iter = wigReader.getBigWigIterator(chr,start,chr,stop,false);
	Max m = new Max();
	Mean mu = new Mean();
	ArrayList<Double> values = new ArrayList<Double>();
	double tempMax=0;
	node  = null;
	while (iter.hasNext()){
		WigItem item = iter.next();
		double value = item.getWigValue();
		m.increment(value);
		for (int i = item.getStartBase();i < item.getEndBase();i++){
			values.add(value);
			mu.increment(value);
			if (value > tempMax){
				tempMax = value;
				node = new TagNode(chr,i,i+1);
			}
		}
		
	}
	
	val = values;
	if (values.size()>0){
		score = mu.getResult();
		max = m.getResult();
		median = values.get(values.size()/2);
	}
	else{
		score=0;max=0;median=0;
	}
	wigReader = null;
}
 
Example 5
Source File: PullWigAboveCutoff.java    From HMMRATAC with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the data
 * @throws IOException
 */
private void set() throws IOException{
	result = new ArrayList<TagNode>();
	
	for (int i = 0;i < g.size();i++){
		MeanAndStd results = new MeanAndStd(wig,g.get(i));
		double mean = results.getMean();
		double std = results.getStd();
		results=null;
		BBFileReader reader = new BBFileReader(wig);
		String chrom = g.get(i).getChrom();
		int begin = g.get(i).getStart();
		int end = g.get(i).getStop();
		BigWigIterator iter = reader.getBigWigIterator(chrom,begin,chrom,end,false);
		while (iter.hasNext()){
			WigItem item = iter.next();
			item.getChromosome();
			int start = item.getStartBase();
			int stop = item.getEndBase();
			double value = item.getWigValue();
			value = (value-mean) / std;
			if (value >= cut){
				TagNode temp = new TagNode(chrom,start,stop,value);
				result.add(temp);
			}
		
		}
		reader=null;
	}
	
}
 
Example 6
Source File: VarianceByBED.java    From HMMRATAC with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	for (int i = 0; i < args.length; i++) {

		switch (args[i].charAt((1))) {
		case'a':
			wig1 = args[i+1];
			i++;
			break;
		
		case'r':
			bed = args[i+1];
			i++;
			break;
		case'h':
			printUsage();
			System.exit(1);
		}
	}
	
	if (wig1 == null || bed == null){
		printUsage();
		System.exit(1);
	}

	bedFileReader reader = new bedFileReader(bed);
	ArrayList<TagNode> bedData = reader.getData();
	reader = null;
	BBFileReader wigReader1 = new BBFileReader(wig1);
	for (int i = 0; i < bedData.size();i++){
		String chrom = bedData.get(i).getChrom();
		int start = bedData.get(i).getStart();
		int stop = bedData.get(i).getStop();
		Variance var = new Variance();
		BigWigIterator iter1 = wigReader1.getBigWigIterator(chrom, start, chrom, stop, false);
		while(iter1.hasNext()){
			WigItem item = iter1.next();
			int begin = item.getStartBase();
			int end = item.getEndBase();
			double value = item.getWigValue();
			for (int a = begin;a < end;a++){
				var.increment(value);
			}
		}
		System.out.println(chrom+"\t"+start+"\t"+stop+"\t"+var.getResult());
	}
}
 
Example 7
Source File: BigWigUtils.java    From JuiceboxLegacy with MIT License 4 votes vote down vote up
/**
 * Private method, does the actual work
 *
 * @param reader
 * @param chr
 * @param start
 * @param end
 * @param windowSize
 */
private static void computeBins(BBFileReader reader, String chr, int start, int end, int windowSize) {
    BigWigIterator iter = reader.getBigWigIterator(chr, start, chr, end, false);
    double sum = 0;
    int nPts = 0;
    double max = 0;
    int currentBin = 0;

    while (iter.hasNext()) {
        WigItem datum = iter.next();
        int dPosition = (datum.getStartBase() + datum.getEndBase()) / 2;


        if (dPosition > (currentBin + 1) * windowSize) {
            // Output previous window
            // if (nPts > 0) {

            double mean = sum / nPts;
            int wStart = windowSize * currentBin;
            int wEnd = wStart + windowSize;
            // unclear why, but sometimes datum.getChromosome() is null
            //System.out.println(datum.getChromosome() + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
            System.out.println(chr + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);

            currentBin++;

            // deal with empty bins
            while (currentBin < dPosition / windowSize) {
                wStart = windowSize * currentBin;
                wEnd = wStart + windowSize;
                mean = 0;
                max = 0;
                System.out.println(chr + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
                // System.out.println(datum.getChromosome() + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
                currentBin++;
            }
            // Start new window
            currentBin = dPosition / windowSize;
            sum = 0;
            nPts = 0;
            max = 0;
        }

        sum += datum.getWigValue();
        max = Math.max(max, datum.getWigValue());
        nPts++;

    }
}
 
Example 8
Source File: BigWigUtils.java    From Juicebox with MIT License 4 votes vote down vote up
/**
 * Private method, does the actual work
 *
 * @param reader
 * @param chr
 * @param start
 * @param end
 * @param windowSize
 */
private static void computeBins(BBFileReader reader, String chr, int start, int end, int windowSize) {
    BigWigIterator iter = reader.getBigWigIterator(chr, start, chr, end, false);
    double sum = 0;
    int nPts = 0;
    double max = 0;
    int currentBin = 0;

    while (iter.hasNext()) {
        WigItem datum = iter.next();
        int dPosition = (datum.getStartBase() + datum.getEndBase()) / 2;


        if (dPosition > (currentBin + 1) * windowSize) {
            // Output previous window
            // if (nPts > 0) {

            double mean = sum / nPts;
            int wStart = windowSize * currentBin;
            int wEnd = wStart + windowSize;
            // unclear why, but sometimes datum.getChromosome() is null
            //System.out.println(datum.getChromosome() + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
            System.out.println(chr + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);

            currentBin++;

            // deal with empty bins
            while (currentBin < dPosition / windowSize) {
                wStart = windowSize * currentBin;
                wEnd = wStart + windowSize;
                mean = 0;
                max = 0;
                System.out.println(chr + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
                // System.out.println(datum.getChromosome() + "\t" + wStart + "\t" + wEnd + "\t" + mean + "\t" + max);
                currentBin++;
            }
            // Start new window
            currentBin = dPosition / windowSize;
            sum = 0;
            nPts = 0;
            max = 0;
        }

        sum += datum.getWigValue();
        max = Math.max(max, datum.getWigValue());
        nPts++;

    }
}