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