annotate java-genomics-toolkit/src/edu/unc/genomics/visualization/StripMatrix.java @ 0:1daf3026d231

Upload alpha version
author timpalpant
date Mon, 13 Feb 2012 21:55:55 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
1 package edu.unc.genomics.visualization;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
2
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
3 import java.io.BufferedReader;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
4 import java.io.BufferedWriter;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
5 import java.io.IOException;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
6 import java.nio.charset.Charset;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
7 import java.nio.file.Files;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
8 import java.nio.file.Path;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
9
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
10 import org.apache.log4j.Logger;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
11
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
12 import com.beust.jcommander.Parameter;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
13
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
14 import edu.unc.genomics.CommandLineTool;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
15 import edu.unc.genomics.ReadablePathValidator;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
16
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
17 public class StripMatrix extends CommandLineTool {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
18
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
19 private static final Logger log = Logger.getLogger(StripMatrix.class);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
20
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
21 @Parameter(names = {"-i", "--input"}, description = "Input file (matrix2png format)", required = true, validateWith = ReadablePathValidator.class)
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
22 public Path inputFile;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
23 @Parameter(names = {"-o", "--output"}, description = "Output file (tabular)", required = true)
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
24 public Path outputFile;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
25
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
26 public void run() throws IOException {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
27 try (BufferedReader reader = Files.newBufferedReader(inputFile, Charset.defaultCharset())) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
28 try (BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset())) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
29 String line = reader.readLine();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
30 // Always copy the first (header) line
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
31 writer.write(line);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
32 writer.newLine();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
33 while ((line = reader.readLine()) != null) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
34 String[] row = line.split("\t");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
35 for (int i = 1; i < row.length; i++) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
36 String cell = row[i];
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
37 if (cell.equalsIgnoreCase("-")) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
38 writer.write("NaN");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
39 } else {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
40 writer.write(cell);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
41 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
42
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
43 if (i > 1) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
44 writer.write("\t");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
45 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
46 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
47 writer.newLine();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
48 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
49 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
50 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
51 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
52
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
53 public static void main(String[] args) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
54 new StripMatrix().instanceMain(args);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
55 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
56 }