Java Code Examples for org.apache.commons.math3.stat.descriptive.moment.StandardDeviation#increment()

The following examples show how to use org.apache.commons.math3.stat.descriptive.moment.StandardDeviation#increment() . 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: bedGraphMath.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
private void setMeanAndStd(){
	Mean mu = new Mean();
	StandardDeviation dev = new StandardDeviation();
	for (String chr : bedgraph.keySet()){
		
		ArrayList<TagNode> inTemp = bedgraph.get(chr);
		Collections.sort(inTemp,  TagNode.basepairComparator);
		for (int i = 0; i < inTemp.size();i++){
			int length = inTemp.get(i).getLength();
			double value = inTemp.get(i).getScore2();
			for (int a = 0; a < length;a++){
				mu.increment(value);
				dev.increment(value);
			}
		}
	}
	mean = mu.getResult();
	std = dev.getResult();
}
 
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: StandardDeviationFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
public Double evaluate(Collection<?> values, boolean biasCorrected){
	StandardDeviation statistic = new StandardDeviation();
	statistic.setBiasCorrected(biasCorrected);

	for(Object value : values){
		Number number = (Number)TypeUtil.parseOrCast(DataType.DOUBLE, value);

		statistic.increment(number.doubleValue());
	}

	return statistic.getResult();
}
 
Example 5
Source File: PileupGenerator.java    From HMMRATAC with GNU General Public License v3.0 4 votes vote down vote up
private void Generate(){
	SAMFileReader reader = new SAMFileReader(bam,index);
	Mean mu = new Mean();
	StandardDeviation std = new StandardDeviation();
	for (int i = 0; i < genome.size();i++){
		String chr = genome.get(i).getChrom();
		int start = genome.get(i).getStart();
		int stop = genome.get(i).getStop();
		ArrayList<PileupNode2> temp = new ArrayList<PileupNode2>();
		for (int a = start;a < stop;a++){
			//new
			int begin;
			int end;
			if (a >= 1000){
				begin = a -1000;
			}else{
				begin = 0;
			}
			if (a <= stop - 1000){
				end = a + 1000;
			}else{
				end = stop;
			}
			//above is new
			CloseableIterator<SAMRecord> iter = reader.query(chr, begin, end, false);
			double value = 0;
			while(iter.hasNext()){
				SAMRecord record = iter.next();
				if(!record.getReadUnmappedFlag() && !record.getMateUnmappedFlag() && record.getFirstOfPairFlag()) {
					int tagstart = -1;
					int tagstop = -1;
				
					if(record.getInferredInsertSize() > 0) {
						tagstart = record.getAlignmentStart();
						
						tagstop = record.getAlignmentStart() + record.getInferredInsertSize() - 1;
					}else if (record.getInferredInsertSize() < 0 ) {
						tagstart = record.getAlignmentEnd() + record.getInferredInsertSize() + 1;
						tagstop = record.getAlignmentEnd();
					}
					if (tagstart == a || tagstop == a || (tagstart < a && tagstop > a)){
						value+=1;
					}
				}
				
			}
			iter.close();
			PileupNode2 node = new PileupNode2(a,value,chr);
			temp.add(node);
			mu.increment(value);
			std.increment(value);
		}
		PileupToBedGraph convert = new PileupToBedGraph(temp,1);
		bedgraph.addAll(convert.getBedGraph());
		
	}
	reader.close();
	mean = mu.getResult();
	stddev = std.getResult();
}