Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/icecream/IceCreamGrader.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package icecream; | |
2 | |
3 import java.io.File; | |
4 import java.io.PrintStream; | |
5 import java.util.ArrayList; | |
6 | |
7 import fileIO.ByteFile; | |
8 import fileIO.ByteFile1; | |
9 import fileIO.ByteFile2; | |
10 import fileIO.FileFormat; | |
11 import fileIO.ReadWrite; | |
12 import shared.Parse; | |
13 import shared.Parser; | |
14 import shared.PreParser; | |
15 import shared.ReadStats; | |
16 import shared.Shared; | |
17 import shared.Timer; | |
18 import shared.Tools; | |
19 import stream.ConcurrentGenericReadInputStream; | |
20 import stream.ConcurrentReadInputStream; | |
21 import stream.FASTQ; | |
22 import stream.FastaReadInputStream; | |
23 import stream.Read; | |
24 import stream.SamLine; | |
25 import structures.ListNum; | |
26 | |
27 /** | |
28 * @author Brian Bushnell | |
29 * @date June 11, 2019 | |
30 * | |
31 */ | |
32 public class IceCreamGrader { | |
33 | |
34 public static void main(String[] args){ | |
35 //Start a timer immediately upon code entrance. | |
36 Timer t=new Timer(); | |
37 | |
38 //Create an instance of this class | |
39 IceCreamGrader x=new IceCreamGrader(args); | |
40 | |
41 //Run the object | |
42 x.process(t); | |
43 | |
44 //Close the print stream if it was redirected | |
45 Shared.closeStream(x.outstream); | |
46 } | |
47 | |
48 public IceCreamGrader(String[] args){ | |
49 | |
50 {//Preparse block for help, config files, and outstream | |
51 PreParser pp=new PreParser(args, getClass(), false); | |
52 args=pp.args; | |
53 outstream=pp.outstream; | |
54 } | |
55 | |
56 //Set shared static variables | |
57 Shared.capBuffers(4); //Only for singlethreaded programs | |
58 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; | |
59 ReadWrite.MAX_ZIP_THREADS=Shared.threads(); | |
60 FASTQ.TEST_INTERLEAVED=FASTQ.FORCE_INTERLEAVED=false; | |
61 SamLine.SET_FROM_OK=true; | |
62 | |
63 Parser parser=new Parser(); | |
64 for(int i=0; i<args.length; i++){ | |
65 String arg=args[i]; | |
66 String[] split=arg.split("="); | |
67 String a=split[0].toLowerCase(); | |
68 String b=split.length>1 ? split[1] : null; | |
69 if(b!=null && b.equalsIgnoreCase("null")){b=null;} | |
70 | |
71 if(a.equals("verbose")){ | |
72 verbose=Parse.parseBoolean(b); | |
73 ByteFile1.verbose=verbose; | |
74 ByteFile2.verbose=verbose; | |
75 stream.FastaReadInputStream.verbose=verbose; | |
76 ConcurrentGenericReadInputStream.verbose=verbose; | |
77 stream.FastqReadInputStream.verbose=verbose; | |
78 ReadWrite.verbose=verbose; | |
79 }else if(parser.parse(arg, a, b)){ | |
80 //do nothing | |
81 } | |
82 | |
83 else if(parser.in1==null && i==0 && !arg.contains("=") && (arg.toLowerCase().startsWith("stdin") || new File(arg).exists())){ | |
84 parser.in1=arg; | |
85 }else if(parser.out1==null && i==1 && !arg.contains("=")){ | |
86 parser.out1=arg; | |
87 }else{ | |
88 outstream.println("Unknown parameter "+args[i]); | |
89 assert(false) : "Unknown parameter "+args[i]; | |
90 // throw new RuntimeException("Unknown parameter "+args[i]); | |
91 } | |
92 } | |
93 | |
94 {//Process parser fields | |
95 Parser.processQuality(); | |
96 | |
97 maxReads=parser.maxReads; | |
98 | |
99 overwrite=ReadStats.overwrite=parser.overwrite; | |
100 append=ReadStats.append=parser.append; | |
101 | |
102 in1=parser.in1; | |
103 | |
104 extin=parser.extin; | |
105 } | |
106 | |
107 assert(FastaReadInputStream.settingsOK()); | |
108 | |
109 if(in1==null){throw new RuntimeException("Error - at least one input file is required.");} | |
110 if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2){ | |
111 ByteFile.FORCE_MODE_BF2=false; | |
112 ByteFile.FORCE_MODE_BF1=true; | |
113 } | |
114 | |
115 ffin1=FileFormat.testInput(in1, FileFormat.FASTQ, extin, true, true); | |
116 } | |
117 | |
118 void process(Timer t){ | |
119 | |
120 final ConcurrentReadInputStream cris; | |
121 { | |
122 cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, null); | |
123 cris.start(); | |
124 if(verbose){outstream.println("Started cris");} | |
125 } | |
126 | |
127 long readsProcessed=0, readsOut=0; | |
128 long basesProcessed=0, basesOut=0; | |
129 | |
130 { | |
131 | |
132 ListNum<Read> ln=cris.nextList(); | |
133 ArrayList<Read> reads=(ln!=null ? ln.list : null); | |
134 | |
135 // outstream.println("Fetched "+reads); | |
136 | |
137 if(reads!=null && !reads.isEmpty()){ | |
138 Read r=reads.get(0); | |
139 assert((ffin1==null || ffin1.samOrBam()) || (r.mate!=null)==cris.paired()); | |
140 } | |
141 | |
142 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning | |
143 | |
144 final ArrayList<Read> listOut=new ArrayList<Read>(reads.size()); | |
145 for(int idx=0; idx<reads.size(); idx++){ | |
146 final Read r1=reads.get(idx); | |
147 | |
148 final int initialLength1=r1.length(); | |
149 final boolean keep=process(r1); | |
150 if(keep){ | |
151 listOut.add(r1); | |
152 readsOut++; | |
153 basesOut+=r1.length(); | |
154 } | |
155 | |
156 readsProcessed++; | |
157 basesProcessed+=initialLength1; | |
158 } | |
159 | |
160 cris.returnList(ln); | |
161 ln=cris.nextList(); | |
162 reads=(ln!=null ? ln.list : null); | |
163 } | |
164 if(ln!=null){ | |
165 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); | |
166 } | |
167 } | |
168 | |
169 errorState|=ReadStats.writeAll(); | |
170 | |
171 errorState|=ReadWrite.closeStreams(cris); | |
172 | |
173 t.stop(); | |
174 outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8)); | |
175 // outstream.println(Tools.readsBasesOut(readsProcessed, basesProcessed, readsOut, basesOut, 8, false)); | |
176 outstream.println(); | |
177 outstream.println(Tools.numberPercent("Good Reads:", goodReads, goodReads*100.0/readsProcessed, 3, 8)); | |
178 outstream.println(Tools.numberPercent("Good Bases:", goodBases, goodBases*100.0/basesProcessed, 3, 8)); | |
179 outstream.println(Tools.numberPercent("Bad Reads:", badReads, badReads*100.0/readsProcessed, 3, 8)); | |
180 outstream.println(Tools.numberPercent("Bad Bases:", badBases, badBases*100.0/basesProcessed, 3, 8)); | |
181 | |
182 if(errorState){ | |
183 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); | |
184 } | |
185 } | |
186 | |
187 /*--------------------------------------------------------------*/ | |
188 | |
189 private boolean process(Read r){ | |
190 boolean iceCream=ReadBuilder.isIceCream(r.id); | |
191 if(iceCream){ | |
192 badReads++; | |
193 badBases+=r.length(); | |
194 }else{ | |
195 goodReads++; | |
196 goodBases+=r.length(); | |
197 } | |
198 return true; | |
199 } | |
200 | |
201 /*--------------------------------------------------------------*/ | |
202 | |
203 private String in1=null; | |
204 | |
205 private String extin=null; | |
206 | |
207 /*--------------------------------------------------------------*/ | |
208 | |
209 private long maxReads=-1; | |
210 | |
211 private long goodReads=0; | |
212 private long goodBases=0; | |
213 private long badReads=0; | |
214 private long badBases=0; | |
215 | |
216 /*--------------------------------------------------------------*/ | |
217 | |
218 private final FileFormat ffin1; | |
219 | |
220 | |
221 /*--------------------------------------------------------------*/ | |
222 | |
223 private PrintStream outstream=System.err; | |
224 public static boolean verbose=false; | |
225 public boolean errorState=false; | |
226 private boolean overwrite=false; | |
227 private boolean append=false; | |
228 | |
229 } |