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