Debian Codegraph @

current/driver/CorrelateIdentity.java

raw symbols SCIP
1 package driver;
2
3 import java.io.File;
4 import java.io.PrintStream;
5 import java.util.ArrayList;
6 import java.util.Collections;
7
8 import fileIO.ReadWrite;
9 import fileIO.TextFile;
10 import fileIO.TextStreamWriter;
11 import shared.Parse;
12 import shared.Parser;
13 import shared.PreParser;
14 import shared.Shared;
15 import shared.Tools;
16
17 /**
18 * @author Brian Bushnell
19 * @date Nov 21, 2014
20 *
21 */
22 public class CorrelateIdentity {
23
24 /*--------------------------------------------------------------*/
25 /*---------------- Initialization ----------------*/
26 /*--------------------------------------------------------------*/
27
28 /**
29 * Code entrance from the command line.
30 * @param args Command line arguments
31 */
32 public static void main(String[] args){
33 //Create a new CorrelateIdentity instance
34 CorrelateIdentity x=new CorrelateIdentity(args);
35
36 ///And run it
37 x.process();
38
39 //Close the print stream if it was redirected
40 Shared.closeStream(outstream);
41 }
42
43 /**
44 * Constructor.
45 * @param args Command line arguments
46 */
47 public CorrelateIdentity(String[] args){
48
49 {//Preparse block for help, config files, and outstream
50 PreParser pp=new PreParser(args, getClass(), false);
51 args=pp.args;
52 outstream=pp.outstream;
53 }
54
55 /* Set global defaults */
56 ReadWrite.ZIPLEVEL=6;
57 ReadWrite.USE_UNPIGZ=true;
58 ReadWrite.USE_PIGZ=true;
59
60 /* Parse arguments */
61 for(int i=0; i<args.length; i++){
62
63 final String arg=args[i];
64 String[] split=arg.split("=");
65 String a=split[0].toLowerCase();
66 String b=split.length>1 ? split[1] : null;
67
68 if(Parser.parseZip(arg, a, b)){
69 //do nothing
70 }else if(Parser.parseQuality(arg, a, b)){
71 //do nothing
72 }else if(a.equals("in") || a.equals("in1")){
73 in1=b;
74 }else if(a.equals("in2")){
75 in2=b;
76 }else if(a.equals("out") || a.equals("out1")){
77 out=b;
78 }else if(a.equals("samplerate")){
79 samplerate=Float.parseFloat(b);
80 assert(samplerate<=1f && samplerate>=0f) : "samplerate="+samplerate+"; should be between 0 and 1";
81 }else if(a.equals("sampleseed")){
82 sampleseed=Long.parseLong(b);
83 }else if(a.equals("overwrite") || a.equals("ow")){
84 overwrite=Parse.parseBoolean(b);
85 }else{
86 throw new RuntimeException("Unknown parameter "+args[i]);
87 }
88 }
89
90 {//Process parser fields
91 Parser.processQuality();
92 }
93
94
95 if(!Tools.testOutputFiles(overwrite, append, false, out)){
96 throw new RuntimeException("\nCan't write to some output files; overwrite="+overwrite+"\n");
97 }
98 if(!Tools.testInputFiles(false, true, in1, in2)){
99 throw new RuntimeException("\nCan't read some input files.\n");
100 }
101 if(!Tools.testForDuplicateFiles(true, in1, in2, out)){
102 throw new RuntimeException("\nSome file names were specified multiple times.\n");
103 }
104
105 assert(in1==null || in1.toLowerCase().startsWith("stdin") || in1.toLowerCase().startsWith("standardin") || new File(in1).exists()) : "Can't find "+in1;
106 }
107
108
109 /*--------------------------------------------------------------*/
110 /*---------------- Outer Methods ----------------*/
111 /*--------------------------------------------------------------*/
112
113 public void process(){
114 final String[][] matrix1, matrix2;
115
116 {
117 TextFile tf=new TextFile(in1);
118 String[] s=tf.toStringLines();
119 tf.close();
120 matrix1=tf.doublesplitWhitespace(s, true);
121 }
122
123 {
124 TextFile tf=new TextFile(in2);
125 String[] s=tf.toStringLines();
126 tf.close();
127 matrix2=tf.doublesplitWhitespace(s, true);
128 }
129
130 ArrayList<String[]> list=new ArrayList<String[]>();
131 for(int i=0; i<matrix1.length; i++){
132 for(int j=1; j<=i; j++){
133 list.add(new String[] {matrix1[i][j], matrix2[i][j]});
134 }
135 }
136
137 Collections.shuffle(list);
138
139 TextStreamWriter tsw=new TextStreamWriter(out, overwrite, append, true);
140 tsw.start();
141 for(String[] pair : list){
142 tsw.print(pair[0]+"\t"+pair[1]+"\n");
143 }
144 tsw.poisonAndWait();
145 }
146
147 /*--------------------------------------------------------------*/
148 /*---------------- Fields ----------------*/
149 /*--------------------------------------------------------------*/
150
151 /** Input files */
152 public String in1, in2;
153 /** Output file */
154 public String out;
155
156 // private Random randy=new Random();
157
158 private float samplerate=1;
159 private float sampleseed=-1;
160 private int columnLength=Integer.MAX_VALUE;
161 private boolean overwrite=true;
162 private boolean append=false;
163
164 /*--------------------------------------------------------------*/
165 /*---------------- Static Fields ----------------*/
166 /*--------------------------------------------------------------*/
167
168 /** Verbose messages */
169 public static final boolean verbose=false; //123
170
171 /** Print messages to this stream */
172 private static PrintStream outstream=System.err;
173
174 }