| 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 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class CorrelateIdentity { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public static void main(String[] args){ |
| 33 |
|
| 34 |
CorrelateIdentity x=new CorrelateIdentity(args); |
| 35 |
|
| 36 |
|
| 37 |
x.process(); |
| 38 |
|
| 39 |
|
| 40 |
Shared.closeStream(outstream); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public CorrelateIdentity(String[] args){ |
| 48 |
|
| 49 |
{ |
| 50 |
PreParser pp=new PreParser(args, getClass(), false); |
| 51 |
args=pp.args; |
| 52 |
outstream=pp.outstream; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
ReadWrite.ZIPLEVEL=6; |
| 57 |
ReadWrite.USE_UNPIGZ=true; |
| 58 |
ReadWrite.USE_PIGZ=true; |
| 59 |
|
| 60 |
|
| 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 |
|
| 70 |
}else if(Parser.parseQuality(arg, a, b)){ |
| 71 |
|
| 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 |
{ |
| 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 |
|
| 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 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public String in1, in2; |
| 153 |
|
| 154 |
public String out; |
| 155 |
|
| 156 |
|
| 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 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public static final boolean verbose=false; |
| 170 |
|
| 171 |
|
| 172 |
private static PrintStream outstream=System.err; |
| 173 |
|
| 174 |
} |