Debian Codegraph @

current/template/A_SampleSummary.java

raw symbols SCIP
1 package template;
2
3 import java.util.ArrayList;
4
5 import fileIO.ByteStreamWriter;
6 import fileIO.FileFormat;
7 import fileIO.ReadWrite;
8 import shared.Parser;
9 import shared.PreParser;
10 import shared.Shared;
11 import shared.Timer;
12 import shared.Tools;
13 import stream.ConcurrentReadInputStream;
14 import stream.Read;
15 import structures.ListNum;
16
17 /**
18 * @author Brian Bushnell
19 * @date Oct 6, 2014
20 *
21 */
22 public class A_SampleSummary {
23
24 public static void main(String[] args){
25 //Start a timer immediately upon code entrance.
26 Timer t=new Timer();
27
28 //Create an instance of this class
29 A_SampleSummary x=new A_SampleSummary(args);
30
31 //Run the object
32 x.process(t);
33
34 //Close the print stream if it was redirected
35 Shared.closeStream(x.outstream);
36 }
37
38 public A_SampleSummary(String[] args){
39
40 {//Preparse block for help, config files, and outstream
41 PreParser pp=new PreParser(args, getClass(), false);
42 args=pp.args;
43 outstream=pp.outstream;
44 }
45
46 Parser parser=new Parser();
47 for(int i=0; i<args.length; i++){
48 String arg=args[i];
49 String[] split=arg.split("=");
50 String a=split[0].toLowerCase();
51 String b=split.length>1 ? split[1] : null;
52 if(b!=null && b.equalsIgnoreCase("null")){b=null;}
53
54 if(a.equals("parse_flag_goes_here")){
55 //Set a variable here
56 }else if(parser.parse(arg, a, b)){
57 //do nothing
58 }else{
59 // throw new RuntimeException("Unknown parameter "+args[i]);
60 assert(false) : "Unknown parameter "+args[i];
61 outstream.println("Unknown parameter "+args[i]);
62 }
63 }
64
65 {//Process parser fields
66 Parser.processQuality();
67
68 maxReads=parser.maxReads;
69 in1=parser.in1;
70 out1=parser.out1;
71 }
72
73 ffout1=FileFormat.testOutput(out1, FileFormat.TXT, null, true, true, false, false);
74 ffin1=FileFormat.testInput(in1, FileFormat.FASTQ, null, true, true);
75 }
76
77 void process(Timer t){
78
79 final ConcurrentReadInputStream cris;
80 {
81 cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, null);
82 cris.start();
83 }
84 boolean paired=cris.paired();
85
86 long readsProcessed=0, basesProcessed=0;
87 {
88
89 ListNum<Read> ln=cris.nextList();
90 ArrayList<Read> reads=(ln!=null ? ln.list : null);
91
92 if(reads!=null && !reads.isEmpty()){
93 Read r=reads.get(0);
94 assert((ffin1==null || ffin1.samOrBam()) || (r.mate!=null)==cris.paired());
95 }
96
97 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
98 if(verbose){outstream.println("Fetched "+reads.size()+" reads.");}
99
100 for(int idx=0; idx<reads.size(); idx++){
101 final Read r1=reads.get(idx);
102 readsProcessed+=r1.pairCount();
103 basesProcessed+=r1.pairLength();
104
105 // ********* Process reads here *********
106 }
107
108 cris.returnList(ln);
109 if(verbose){outstream.println("Returned a list.");}
110 ln=cris.nextList();
111 reads=(ln!=null ? ln.list : null);
112 }
113 if(ln!=null){
114 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty());
115 }
116 }
117 errorState=ReadWrite.closeStreams(cris) | errorState;
118 if(verbose){outstream.println("Finished reading data.");}
119
120 outputResults();
121
122 t.stop();
123 outstream.println("Time: \t"+t);
124 outstream.println("Reads Processed: "+readsProcessed+" \t"+Tools.format("%.2fk reads/sec", (readsProcessed/(double)(t.elapsed))*1000000));
125 assert(!errorState) : "An error was encountered.";
126 }
127
128 private void outputResults(){
129 ByteStreamWriter bsw=new ByteStreamWriter(ffout1);
130 bsw.start();
131
132 //Write stuff to the bsw
133 bsw.println("Stuff");
134
135 errorState=bsw.poisonAndWait() | errorState;
136 }
137
138 /*--------------------------------------------------------------*/
139
140 /*--------------------------------------------------------------*/
141
142 private String in1=null;
143 private String out1=null;
144
145 private final FileFormat ffin1;
146 private final FileFormat ffout1;
147
148 /*--------------------------------------------------------------*/
149
150 private long maxReads=-1;
151 private boolean errorState=false;
152
153 /*--------------------------------------------------------------*/
154
155 private java.io.PrintStream outstream=System.err;
156 public static boolean verbose=false;
157
158 }