annotate src/edu/unc/genomics/wigmath/LogTransform.java @ 2:e16016635b2a

Uploaded
author timpalpant
date Mon, 13 Feb 2012 22:12:06 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
1 package edu.unc.genomics.wigmath;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
2
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
3 import java.io.IOException;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
4 import java.util.Iterator;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
5
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
6 import org.apache.log4j.Logger;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
7 import org.broad.igv.bbfile.WigItem;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
8
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
9 import com.beust.jcommander.Parameter;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
10
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
11 import edu.unc.genomics.io.WigFile;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
12 import edu.unc.genomics.io.WigFileException;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
13
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
14 public class LogTransform extends WigMathTool {
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
15
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
16 private static final Logger log = Logger.getLogger(LogTransform.class);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
17
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
18 @Parameter(names = {"-i", "--input"}, description = "Input file", required = true)
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
19 public WigFile inputFile;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
20 @Parameter(names = {"-b", "--base"}, description = "Logarithm base (default = 2)")
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
21 public double base = 2;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
22
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
23 private double baseChange;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
24
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
25 @Override
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
26 public void setup() {
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
27 baseChange = Math.log(base);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
28 inputs.add(inputFile);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
29 }
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
30
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
31 @Override
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
32 public float[] compute(String chr, int start, int stop) throws IOException, WigFileException {
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
33 log.debug("Computing difference for chunk "+chr+":"+start+"-"+stop);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
34
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
35 Iterator<WigItem> data = inputFile.query(chr, start, stop);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
36 float[] result = WigFile.flattenData(data, start, stop);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
37
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
38 for (int i = 0; i < result.length; i++) {
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
39 result[i] = (float) (Math.log(result[i]) / baseChange);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
40 }
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
41
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
42 return result;
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
43 }
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
44
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
45
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
46 /**
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
47 * @param args
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
48 * @throws WigFileException
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
49 * @throws IOException
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
50 */
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
51 public static void main(String[] args) throws IOException, WigFileException {
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
52 new LogTransform().instanceMain(args);
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
53 }
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
54
e16016635b2a Uploaded
timpalpant
parents:
diff changeset
55 }