| 1 |
package template; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import fileIO.FileFormat; |
| 6 |
import fileIO.ReadWrite; |
| 7 |
import shared.Parse; |
| 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.ConcurrentReadInputStreamD; |
| 15 |
import stream.ConcurrentReadOutputStream; |
| 16 |
import stream.Read; |
| 17 |
import structures.ListNum; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class A_SampleD { |
| 25 |
|
| 26 |
public static void main(String[] args){ |
| 27 |
|
| 28 |
Timer t=new Timer(); |
| 29 |
|
| 30 |
|
| 31 |
A_SampleD x=new A_SampleD(args); |
| 32 |
assert(false) : "To support MPI, uncomment this."; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
x.process(t); |
| 37 |
|
| 38 |
|
| 39 |
Shared.closeStream(x.outstream); |
| 40 |
|
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
public A_SampleD(String[] args){ |
| 45 |
|
| 46 |
{ |
| 47 |
PreParser pp=new PreParser(args, getClass(), false); |
| 48 |
args=pp.args; |
| 49 |
outstream=pp.outstream; |
| 50 |
} |
| 51 |
|
| 52 |
Parser parser=new Parser(); |
| 53 |
for(int i=0; i<args.length; i++){ |
| 54 |
String arg=args[i]; |
| 55 |
String[] split=arg.split("="); |
| 56 |
String a=split[0].toLowerCase(); |
| 57 |
String b=split.length>1 ? split[1] : null; |
| 58 |
if(b!=null && b.equalsIgnoreCase("null")){b=null;} |
| 59 |
|
| 60 |
if(a.equals("verbose")){ |
| 61 |
verbose=Parse.parseBoolean(b); |
| 62 |
ConcurrentReadInputStreamD.verbose=verbose; |
| 63 |
}else if(a.equals("parse_flag_goes_here")){ |
| 64 |
|
| 65 |
}else if(parser.parse(arg, a, b)){ |
| 66 |
|
| 67 |
}else{ |
| 68 |
outstream.println("A_SampleD: Unknown parameter "+args[i]); |
| 69 |
assert(false) : "Unknown parameter "+args[i]; |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
{ |
| 75 |
Parser.processQuality(); |
| 76 |
|
| 77 |
maxReads=parser.maxReads; |
| 78 |
in1=parser.in1; |
| 79 |
out1=parser.out1; |
| 80 |
} |
| 81 |
|
| 82 |
ffout1=FileFormat.testOutput(out1, FileFormat.FASTQ, null, true, true, false, false); |
| 83 |
ffin1=FileFormat.testInput(in1, FileFormat.FASTQ, null, true, true); |
| 84 |
} |
| 85 |
|
| 86 |
void process(Timer t){ |
| 87 |
|
| 88 |
final ConcurrentReadInputStream crisD=ConcurrentReadInputStream.getReadInputStream( |
| 89 |
maxReads, false, ffin1, null, Shared.USE_MPI, Shared.MPI_KEEP_ALL); |
| 90 |
crisD.start(); |
| 91 |
final boolean paired=crisD.paired(); |
| 92 |
|
| 93 |
final ConcurrentReadOutputStream ros; |
| 94 |
if(out1!=null){ |
| 95 |
final int buff=4; |
| 96 |
|
| 97 |
if(paired && (in1==null || !in1.contains(".sam"))){ |
| 98 |
outstream.println("A_SampleD: Writing interleaved."); |
| 99 |
} |
| 100 |
|
| 101 |
assert(!out1.equalsIgnoreCase(in1) && !out1.equalsIgnoreCase(in1)) : "Input file and output file have same name."; |
| 102 |
|
| 103 |
ros=ConcurrentReadOutputStream.getStream(ffout1, null, buff, null, false); |
| 104 |
ros.start(); |
| 105 |
}else{ros=null;} |
| 106 |
|
| 107 |
long readsProcessed=0; |
| 108 |
{ |
| 109 |
|
| 110 |
ListNum<Read> ln=crisD.nextList(); |
| 111 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 112 |
if(verbose){outstream.println("A_SampleD: Initial A_SampleD list: "+(reads==null ? -1 : reads.size()));} |
| 113 |
|
| 114 |
if(reads!=null && !reads.isEmpty()){ |
| 115 |
Read r=reads.get(0); |
| 116 |
assert((ffin1==null || ffin1.samOrBam()) || (r.mate!=null)==crisD.paired()); |
| 117 |
} |
| 118 |
|
| 119 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 120 |
if(verbose){outstream.println("A_SampleD: Fetched "+reads.size()+" reads.");} |
| 121 |
|
| 122 |
for(int idx=0; idx<reads.size(); idx++){ |
| 123 |
final Read r1=reads.get(idx); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
readsProcessed++; |
| 128 |
} |
| 129 |
|
| 130 |
if(ros!=null){ros.add(reads, ln.id);} |
| 131 |
|
| 132 |
crisD.returnList(ln.id, ln.list.isEmpty()); |
| 133 |
if(verbose){outstream.println("A_SampleD: Returned a list.");} |
| 134 |
ln=crisD.nextList(); |
| 135 |
reads=(ln!=null ? ln.list : null); |
| 136 |
} |
| 137 |
if(ln!=null){ |
| 138 |
crisD.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 139 |
} |
| 140 |
} |
| 141 |
ReadWrite.closeStreams(crisD, ros); |
| 142 |
if(verbose){outstream.println("A_SampleD: Finished.");} |
| 143 |
|
| 144 |
t.stop(); |
| 145 |
outstream.println("A_SampleD: Time: \t"+t); |
| 146 |
outstream.println("A_SampleD: Rank "+ Shared.MPI_RANK + ": Reads Processed: "+readsProcessed+" \t"+ |
| 147 |
Tools.format("%.2fk reads/sec", (readsProcessed/(double)(t.elapsed))*1000000)); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
private String in1=null; |
| 155 |
private String out1=null; |
| 156 |
|
| 157 |
private final FileFormat ffin1; |
| 158 |
private final FileFormat ffout1; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
private long maxReads=-1; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
private java.io.PrintStream outstream=System.err; |
| 167 |
public static boolean verbose=false; |
| 168 |
|
| 169 |
} |