Mercurial > repos > timpalpant > java_genomics_toolkit
comparison src/edu/unc/genomics/ngs/IntervalLengthDistribution.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.ngs; | |
| 2 | |
| 3 import java.io.BufferedWriter; | |
| 4 import java.io.IOException; | |
| 5 import java.nio.charset.Charset; | |
| 6 import java.nio.file.Files; | |
| 7 import java.nio.file.Path; | |
| 8 | |
| 9 import org.apache.commons.math.stat.Frequency; | |
| 10 import org.apache.log4j.Logger; | |
| 11 | |
| 12 import com.beust.jcommander.Parameter; | |
| 13 | |
| 14 import edu.unc.genomics.CommandLineTool; | |
| 15 import edu.unc.genomics.Interval; | |
| 16 import edu.unc.genomics.io.IntervalFile; | |
| 17 | |
| 18 public class IntervalLengthDistribution extends CommandLineTool { | |
| 19 | |
| 20 private static final Logger log = Logger.getLogger(IntervalLengthDistribution.class); | |
| 21 | |
| 22 @Parameter(names = {"-i", "--input"}, description = "Interval file", required = true) | |
| 23 public IntervalFile<? extends Interval> inputFile; | |
| 24 @Parameter(names = {"-o", "--output"}, description = "Output file", required = true) | |
| 25 public Path outputFile; | |
| 26 | |
| 27 | |
| 28 @Override | |
| 29 public void run() throws IOException { | |
| 30 log.debug("Generating histogram of interval lengths"); | |
| 31 Frequency freq = new Frequency(); | |
| 32 int min = Integer.MAX_VALUE; | |
| 33 int max = -1; | |
| 34 for (Interval i : inputFile) { | |
| 35 int L = i.length(); | |
| 36 freq.addValue(L); | |
| 37 | |
| 38 if (L < min) { | |
| 39 min = L; | |
| 40 } | |
| 41 if (L > max) { | |
| 42 max = L; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 log.debug("Writing histogram output"); | |
| 47 try (BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset())) { | |
| 48 for (int i = min; i <= max; i++) { | |
| 49 writer.write(i+"\t"+freq.getCount(i)); | |
| 50 writer.newLine(); | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 public static void main(String[] args) { | |
| 56 new IntervalLengthDistribution().instanceMain(args); | |
| 57 } | |
| 58 | |
| 59 } |
