comparison src/edu/unc/genomics/wigmath/Scale.java @ 2:e16016635b2a

Uploaded
author timpalpant
date Mon, 13 Feb 2012 22:12:06 -0500
parents
children
comparison
equal deleted inserted replaced
1:a54db233ee3d 2:e16016635b2a
1 package edu.unc.genomics.wigmath;
2
3 import java.io.IOException;
4 import java.util.Iterator;
5
6 import org.apache.log4j.Logger;
7 import org.broad.igv.bbfile.WigItem;
8
9 import com.beust.jcommander.Parameter;
10
11 import edu.unc.genomics.io.WigFile;
12 import edu.unc.genomics.io.WigFileException;
13
14 public class Scale extends WigMathTool {
15
16 private static final Logger log = Logger.getLogger(Scale.class);
17
18 @Parameter(names = {"-i", "--input"}, description = "Input file", required = true)
19 public WigFile inputFile;
20 @Parameter(names = {"-m", "--multiplier"}, description = "Multiplier (scale factor, default = 1/mean)")
21 public Double multiplier;
22
23
24 @Override
25 public void setup() {
26 inputs.add(inputFile);
27
28 if (multiplier == null) {
29 multiplier = inputFile.numBases() / inputFile.total();
30 }
31 }
32
33 @Override
34 public float[] compute(String chr, int start, int stop) throws IOException, WigFileException {
35 log.debug("Computing difference for chunk "+chr+":"+start+"-"+stop);
36
37 Iterator<WigItem> data = inputFile.query(chr, start, stop);
38 float[] result = WigFile.flattenData(data, start, stop);
39
40 for (int i = 0; i < result.length; i++) {
41 result[i] = (float) (multiplier * result[i]);
42 }
43
44 return result;
45 }
46
47
48 /**
49 * @param args
50 * @throws WigFileException
51 * @throws IOException
52 */
53 public static void main(String[] args) throws IOException, WigFileException {
54 new Scale().instanceMain(args);
55 }
56
57 }