Debian Codegraph @

current/template/A_Sample2.java

raw symbols SCIP
1 package template;
2
3 import java.util.ArrayList;
4
5 import fileIO.FileFormat;
6 import fileIO.ReadWrite;
7 import shared.Parser;
8 import shared.PreParser;
9 import shared.Shared;
10 import shared.Timer;
11 import shared.Tools;
12 import stream.ConcurrentReadInputStream;
13 import stream.ConcurrentReadOutputStream;
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_Sample2 {
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_Sample2 x=new A_Sample2(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_Sample2(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.FASTQ, 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 final ConcurrentReadOutputStream ros;
87 if(out1!=null){
88 final int buff=4;
89
90 if(cris.paired() && (in1==null || !in1.contains(".sam"))){
91 outstream.println("Writing interleaved.");
92 }
93
94 assert(!out1.equalsIgnoreCase(in1) && !out1.equalsIgnoreCase(in1)) : "Input file and output file have same name.";
95
96 ros=ConcurrentReadOutputStream.getStream(ffout1, null, buff, null, false);
97 ros.start();
98 }else{ros=null;}
99
100 long readsProcessed=0, basesProcessed=0;
101 {
102
103 ListNum<Read> ln=cris.nextList();
104 ArrayList<Read> reads=(ln!=null ? ln.list : null);
105
106 if(reads!=null && !reads.isEmpty()){
107 Read r=reads.get(0);
108 assert((ffin1==null || ffin1.samOrBam()) || (r.mate!=null)==cris.paired());
109 }
110
111 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
112 if(verbose){outstream.println("Fetched "+reads.size()+" reads.");}
113
114 for(int idx=0; idx<reads.size(); idx++){
115 final Read r1=reads.get(idx);
116 readsProcessed+=r1.pairCount();
117 basesProcessed+=r1.pairLength();
118
119 // ********* Process reads here *********
120 }
121
122 if(ros!=null){ros.add(reads, ln.id);}
123
124 cris.returnList(ln);
125 if(verbose){outstream.println("Returned a list.");}
126 ln=cris.nextList();
127 reads=(ln!=null ? ln.list : null);
128 }
129 if(ln!=null){
130 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty());
131 }
132 }
133 ReadWrite.closeStreams(cris, ros);
134 if(verbose){outstream.println("Finished.");}
135
136 t.stop();
137 outstream.println("Time: \t"+t);
138 outstream.println("Reads Processed: "+readsProcessed+" \t"+Tools.format("%.2fk reads/sec", (readsProcessed/(double)(t.elapsed))*1000000));
139 }
140
141 /*--------------------------------------------------------------*/
142
143 /*--------------------------------------------------------------*/
144
145 private String in1=null;
146 private String out1=null;
147
148 private final FileFormat ffin1;
149 private final FileFormat ffout1;
150
151 /*--------------------------------------------------------------*/
152
153 private long maxReads=-1;
154
155 /*--------------------------------------------------------------*/
156
157 private java.io.PrintStream outstream=System.err;
158 public static boolean verbose=false;
159
160 }