| 1 |
package ml; |
| 2 |
|
| 3 |
import fileIO.ByteFile; |
| 4 |
import fileIO.ByteStreamWriter; |
| 5 |
import shared.LineParser1; |
| 6 |
import shared.Timer; |
| 7 |
import shared.Tools; |
| 8 |
import structures.IntList; |
| 9 |
import structures.ListNum; |
| 10 |
|
| 11 |
public class ReduceColumns { |
| 12 |
|
| 13 |
public static void main(String[] args) { |
| 14 |
|
| 15 |
Timer t=new Timer(); |
| 16 |
String in=args[0]; |
| 17 |
String out=args[1]; |
| 18 |
IntList columns=new IntList(); |
| 19 |
for(int i=2; i<args.length; i++) { |
| 20 |
columns.add(Integer.parseInt(args[i])); |
| 21 |
} |
| 22 |
columns.shrink(); |
| 23 |
|
| 24 |
ByteFile bf=ByteFile.makeByteFile(in, true); |
| 25 |
ByteStreamWriter bsw=ByteStreamWriter.makeBSW(out, true, false, true); |
| 26 |
|
| 27 |
LineParser1 lp=new LineParser1('\t'); |
| 28 |
boolean header=false; |
| 29 |
|
| 30 |
bsw.print("#dims").tab().print(columns.size()-1).tab().print(1).nl(); |
| 31 |
header=true; |
| 32 |
|
| 33 |
long linesIn=0, bytesIn=0; |
| 34 |
for(ListNum<byte[]> ln=bf.nextList(); ln!=null; ln=bf.nextList()) { |
| 35 |
for(byte[] line : ln) { |
| 36 |
linesIn++; |
| 37 |
bytesIn+=line.length; |
| 38 |
lp.set(line); |
| 39 |
if(lp.startsWith('#')) { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
}else { |
| 47 |
for(int i=0; i<columns.size; i++) { |
| 48 |
if(i>0) {bsw.tab();} |
| 49 |
bsw.print(lp.parseByteArray(columns.get(i))); |
| 50 |
} |
| 51 |
bsw.println(); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
bsw.poisonAndWait(); |
| 56 |
|
| 57 |
t.stop(); |
| 58 |
System.err.println(Tools.timeLinesBytesProcessed(t, linesIn, bytesIn, 8)); |
| 59 |
} |
| 60 |
|
| 61 |
} |