Mercurial > repos > timpalpant > java_genomics_toolkit
comparison src/edu/unc/genomics/wigmath/LogTransform.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 LogTransform extends WigMathTool { | |
| 15 | |
| 16 private static final Logger log = Logger.getLogger(LogTransform.class); | |
| 17 | |
| 18 @Parameter(names = {"-i", "--input"}, description = "Input file", required = true) | |
| 19 public WigFile inputFile; | |
| 20 @Parameter(names = {"-b", "--base"}, description = "Logarithm base (default = 2)") | |
| 21 public double base = 2; | |
| 22 | |
| 23 private double baseChange; | |
| 24 | |
| 25 @Override | |
| 26 public void setup() { | |
| 27 baseChange = Math.log(base); | |
| 28 inputs.add(inputFile); | |
| 29 } | |
| 30 | |
| 31 @Override | |
| 32 public float[] compute(String chr, int start, int stop) throws IOException, WigFileException { | |
| 33 log.debug("Computing difference for chunk "+chr+":"+start+"-"+stop); | |
| 34 | |
| 35 Iterator<WigItem> data = inputFile.query(chr, start, stop); | |
| 36 float[] result = WigFile.flattenData(data, start, stop); | |
| 37 | |
| 38 for (int i = 0; i < result.length; i++) { | |
| 39 result[i] = (float) (Math.log(result[i]) / baseChange); | |
| 40 } | |
| 41 | |
| 42 return result; | |
| 43 } | |
| 44 | |
| 45 | |
| 46 /** | |
| 47 * @param args | |
| 48 * @throws WigFileException | |
| 49 * @throws IOException | |
| 50 */ | |
| 51 public static void main(String[] args) throws IOException, WigFileException { | |
| 52 new LogTransform().instanceMain(args); | |
| 53 } | |
| 54 | |
| 55 } |
