Debian Codegraph @

current/driver/ParseCrossblockResults.java

raw symbols SCIP
1 package driver;
2
3 import java.io.File;
4 import java.io.PrintStream;
5
6 import fileIO.FileFormat;
7 import fileIO.ReadWrite;
8 import fileIO.TextFile;
9 import fileIO.TextStreamWriter;
10 import shared.Parse;
11 import shared.Parser;
12 import shared.PreParser;
13 import shared.Shared;
14 import shared.Timer;
15 import shared.Tools;
16
17 /**
18 * @author Brian Bushnell
19 * @date June 9, 2016
20 *
21 */
22 public class ParseCrossblockResults {
23
24 public static void main(String[] args){
25 Timer t=new Timer();
26 ParseCrossblockResults x=new ParseCrossblockResults(args);
27 x.process(t);
28
29 //Close the print stream if it was redirected
30 Shared.closeStream(x.outstream);
31 }
32
33 public ParseCrossblockResults(String[] args){
34
35 {//Preparse block for help, config files, and outstream
36 PreParser pp=new PreParser(args, getClass(), false);
37 args=pp.args;
38 outstream=pp.outstream;
39 }
40
41 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=false;
42
43 Parser parser=new Parser();
44 for(int i=0; i<args.length; i++){
45 String arg=args[i];
46 String[] split=arg.split("=");
47 String a=split[0].toLowerCase();
48 String b=split.length>1 ? split[1] : null;
49
50 if(parser.parse(arg, a, b)){
51 //do nothing
52 }else if(a.equals("verbose")){
53 verbose=Parse.parseBoolean(b);
54 ReadWrite.verbose=verbose;
55 }else if(parser.in1==null && i==0 && Tools.looksLikeInputStream(arg)){
56 parser.in1=arg;
57 }else{
58 outstream.println("Unknown parameter "+args[i]);
59 assert(false) : "Unknown parameter "+args[i];
60 // throw new RuntimeException("Unknown parameter "+args[i]);
61 }
62 }
63
64 {//Process parser fields
65 Parser.processQuality();
66
67 maxReads=parser.maxReads;
68
69 overwrite=parser.overwrite;
70 append=parser.append;
71
72 in1=parser.in1;
73
74 out1=parser.out1;
75 }
76
77 if(in1==null){throw new RuntimeException("Error - at least one input file is required.");}
78
79 if(out1!=null && out1.equalsIgnoreCase("null")){out1=null;}
80
81 if(!Tools.testOutputFiles(overwrite, append, false, out1)){
82 outstream.println((out1==null)+", "+out1);
83 throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out1+"\n");
84 }
85
86 ffout1=FileFormat.testOutput(out1, FileFormat.TEXT, null, true, overwrite, append, false);
87
88 ffin1=FileFormat.testInput(in1, FileFormat.TEXT, null, false, false);
89 }
90
91 void process(Timer t){
92
93 final TextFile tf;
94 {
95 tf=new TextFile(ffin1);
96 if(verbose){outstream.println("Started tf");}
97 }
98
99 long linesProcessed=0;
100 long charsProcessed=0;
101
102 {
103 String line;
104 while((maxReads<0 || linesProcessed<maxReads) && (line=tf.nextLine())!=null){
105 linesProcessed++;
106 charsProcessed+=line.length();
107 if(!line.startsWith("#")){
108 processLine(line);
109 }
110 }
111 }
112 errorState|=tf.close();
113
114 if(ffout1!=null){
115 final TextStreamWriter tsw;
116 {
117 tsw=new TextStreamWriter(ffout1);
118 tsw.start();
119 if(verbose){outstream.println("Started tsw");}
120 errorState|=tsw.poisonAndWait();
121 }
122 }
123
124 t.stop();
125 outstream.println(Tools.timeLinesBytesProcessed(t, linesProcessed, charsProcessed, 8));
126
127 if(errorState){
128 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
129 }
130 }
131
132
133 private void processLine(String line){
134 ResultsLine rl=new ResultsLine(line);
135 if(rl.removed){
136 basesDiscarded+=rl.length;
137 contigsDiscarded++;
138 }else{
139 basesKept+=rl.length;
140 contigsKept++;
141 }
142 }
143
144
145
146 /*--------------------------------------------------------------*/
147
148 private static class ResultsLine{
149
150 public ResultsLine(String s){
151 String[] split=s.split("\t");
152 length=Integer.parseInt(split[3]);
153 removed=Integer.parseInt(split[2])==1;
154 }
155
156 final int length;
157 final boolean removed;
158
159 }
160
161 /*--------------------------------------------------------------*/
162
163 /*--------------------------------------------------------------*/
164
165 private String in1=null;
166 private String out1=null;
167
168 /*--------------------------------------------------------------*/
169
170 private long maxReads=-1;
171
172 private long basesKept=0;
173 private long basesDiscarded=0;
174 private long contigsKept=0;
175 private long contigsDiscarded=0;
176
177 public long basesKept(){return basesKept;}
178 public long basesDiscarded(){return basesDiscarded;}
179 public long contigsKept(){return contigsKept;}
180 public long contigsDiscarded(){return contigsDiscarded;}
181
182 public long contigs(){return contigsKept+contigsDiscarded;}
183 public long bases(){return basesKept+basesDiscarded;}
184
185 /*--------------------------------------------------------------*/
186
187 private final FileFormat ffin1;
188 private final FileFormat ffout1;
189
190
191 /*--------------------------------------------------------------*/
192
193 private PrintStream outstream=System.err;
194 public static boolean verbose=false;
195 public boolean errorState=false;
196 private boolean overwrite=true;
197 private boolean append=false;
198
199 }