| 1 |
package pacbio; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import aligner.MultiStateAligner9PacBioAdapter; |
| 6 |
import aligner.MultiStateAligner9PacBioAdapter2; |
| 7 |
import dna.AminoAcid; |
| 8 |
import dna.Data; |
| 9 |
import fileIO.FileFormat; |
| 10 |
import fileIO.ReadWrite; |
| 11 |
import shared.KillSwitch; |
| 12 |
import shared.Parse; |
| 13 |
import shared.Parser; |
| 14 |
import shared.PreParser; |
| 15 |
import shared.Shared; |
| 16 |
import shared.Timer; |
| 17 |
import shared.Tools; |
| 18 |
import stream.ConcurrentReadInputStream; |
| 19 |
import stream.ConcurrentReadOutputStream; |
| 20 |
import stream.FastaReadInputStream; |
| 21 |
import stream.Read; |
| 22 |
import structures.ListNum; |
| 23 |
import tracker.ReadStats; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class RemoveAdapters2 { |
| 32 |
|
| 33 |
public static void main(String[] args){ |
| 34 |
{ |
| 35 |
PreParser pp=new PreParser(args, new Object() { }.getClass().getEnclosingClass(), false); |
| 36 |
args=pp.args; |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
boolean verbose=false; |
| 41 |
|
| 42 |
String in1=null; |
| 43 |
String in2=null; |
| 44 |
long maxReads=-1; |
| 45 |
|
| 46 |
String outname1=null; |
| 47 |
String outname2=null; |
| 48 |
|
| 49 |
String query=pacbioAdapter; |
| 50 |
Shared.capBufferLen(20); |
| 51 |
|
| 52 |
boolean splitReads=true; |
| 53 |
|
| 54 |
for(int i=0; i<args.length; i++){ |
| 55 |
final String arg=args[i]; |
| 56 |
final String[] split=arg.split("="); |
| 57 |
String a=split[0].toLowerCase(); |
| 58 |
String b=split.length>1 ? split[1] : null; |
| 59 |
|
| 60 |
if(Parser.parseCommonStatic(arg, a, b)){ |
| 61 |
|
| 62 |
}else if(Parser.parseZip(arg, a, b)){ |
| 63 |
|
| 64 |
}else if(Parser.parseQuality(arg, a, b)){ |
| 65 |
|
| 66 |
}else if(Parser.parseFasta(arg, a, b)){ |
| 67 |
|
| 68 |
}else if(a.equals("path") || a.equals("root") || a.equals("tempdir")){ |
| 69 |
Data.setPath(b); |
| 70 |
}else if(a.equals("usealtmsa")){ |
| 71 |
USE_ALT_MSA=Parse.parseBoolean(b); |
| 72 |
}else if(a.equals("fasta") || a.equals("in") || a.equals("input") || a.equals("in1") || a.equals("input1")){ |
| 73 |
in1=b; |
| 74 |
if(b.indexOf('#')>-1){ |
| 75 |
in1=b.replace("#", "1"); |
| 76 |
in2=b.replace("#", "2"); |
| 77 |
} |
| 78 |
}else if(a.equals("in2") || a.equals("input2")){ |
| 79 |
in2=b; |
| 80 |
}else if(a.equals("query") || a.equals("adapter")){ |
| 81 |
query=b; |
| 82 |
}else if(a.equals("split")){ |
| 83 |
splitReads=Parse.parseBoolean(b); |
| 84 |
}else if(a.equals("plusonly")){ |
| 85 |
boolean x=Parse.parseBoolean(b); |
| 86 |
if(x){TRY_PLUS=true; TRY_MINUS=false;} |
| 87 |
}else if(a.equals("minusonly")){ |
| 88 |
boolean x=Parse.parseBoolean(b); |
| 89 |
if(x){TRY_PLUS=false; TRY_MINUS=true;} |
| 90 |
}else if(a.startsWith("mincontig")){ |
| 91 |
minContig=Integer.parseInt(b); |
| 92 |
}else if(a.equals("append") || a.equals("app")){ |
| 93 |
append=ReadStats.append=Parse.parseBoolean(b); |
| 94 |
}else if(a.equals("overwrite") || a.equals("ow")){ |
| 95 |
overwrite=Parse.parseBoolean(b); |
| 96 |
System.out.println("Set overwrite to "+overwrite); |
| 97 |
}else if(a.equals("threads") || a.equals("t")){ |
| 98 |
if(b.equalsIgnoreCase("auto")){THREADS=Shared.LOGICAL_PROCESSORS;} |
| 99 |
else{THREADS=Integer.parseInt(b);} |
| 100 |
System.out.println("Set threads to "+THREADS); |
| 101 |
}else if(a.equals("reads") || a.equals("maxreads")){ |
| 102 |
maxReads=Parse.parseKMG(b); |
| 103 |
}else if(a.startsWith("outname") || a.startsWith("outfile") || a.equals("out")){ |
| 104 |
if(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none") || split.length==1){ |
| 105 |
System.out.println("No output file."); |
| 106 |
outname1=null; |
| 107 |
OUTPUT_READS=false; |
| 108 |
}else{ |
| 109 |
OUTPUT_READS=true; |
| 110 |
if(b.indexOf('#')>-1){ |
| 111 |
outname1=b.replace('#', '1'); |
| 112 |
outname2=b.replace('#', '2'); |
| 113 |
}else{ |
| 114 |
outname1=b; |
| 115 |
} |
| 116 |
} |
| 117 |
}else if(a.equals("minratio")){ |
| 118 |
MINIMUM_ALIGNMENT_SCORE_RATIO=Float.parseFloat(b); |
| 119 |
System.out.println("Set MINIMUM_ALIGNMENT_SCORE_RATIO to "+MINIMUM_ALIGNMENT_SCORE_RATIO); |
| 120 |
}else if(a.equals("suspectratio")){ |
| 121 |
SUSPECT_RATIO=Float.parseFloat(b); |
| 122 |
}else if(a.startsWith("verbose")){ |
| 123 |
verbose=Parse.parseBoolean(b); |
| 124 |
}else{ |
| 125 |
throw new RuntimeException("Unknown parameter: "+args[i]); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
{ |
| 130 |
Parser.processQuality(); |
| 131 |
} |
| 132 |
|
| 133 |
assert(FastaReadInputStream.settingsOK()); |
| 134 |
if(in1==null){throw new RuntimeException("Please specify input file.");} |
| 135 |
|
| 136 |
|
| 137 |
final ConcurrentReadInputStream cris; |
| 138 |
{ |
| 139 |
FileFormat ff1=FileFormat.testInput(in1, FileFormat.FASTQ, null, true, true); |
| 140 |
FileFormat ff2=FileFormat.testInput(in2, FileFormat.FASTQ, null, true, true); |
| 141 |
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ff1, ff2); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
} |
| 146 |
boolean paired=cris.paired(); |
| 147 |
if(verbose){System.err.println("Paired: "+paired);} |
| 148 |
|
| 149 |
ConcurrentReadOutputStream ros=null; |
| 150 |
if(OUTPUT_READS){ |
| 151 |
final int buff=(!ordered ? THREADS : Tools.max(24, 2*THREADS)); |
| 152 |
|
| 153 |
FileFormat ff1=FileFormat.testOutput(outname1, FileFormat.FASTQ, null, true, overwrite, append, ordered); |
| 154 |
FileFormat ff2=FileFormat.testOutput(outname2, FileFormat.FASTQ, null, true, overwrite, append, ordered); |
| 155 |
ros=ConcurrentReadOutputStream.getStream(ff1, ff2, buff, null, true); |
| 156 |
} |
| 157 |
process(cris, ros, query, splitReads); |
| 158 |
} |
| 159 |
|
| 160 |
public static void process(ConcurrentReadInputStream cris, ConcurrentReadOutputStream ros, String query, boolean split){ |
| 161 |
|
| 162 |
Timer t=new Timer(); |
| 163 |
|
| 164 |
cris.start(); |
| 165 |
|
| 166 |
System.out.println("Started read stream."); |
| 167 |
|
| 168 |
|
| 169 |
if(ros!=null){ |
| 170 |
ros.start(); |
| 171 |
System.out.println("Started output threads."); |
| 172 |
} |
| 173 |
ProcessThread[] pts=new ProcessThread[THREADS]; |
| 174 |
for(int i=0; i<pts.length; i++){ |
| 175 |
pts[i]=new ProcessThread(cris, ros, MINIMUM_ALIGNMENT_SCORE_RATIO, query, split); |
| 176 |
pts[i].start(); |
| 177 |
} |
| 178 |
System.out.println("Started "+pts.length+" processing thread"+(pts.length==1 ? "" : "s")+"."); |
| 179 |
|
| 180 |
for(int i=0; i<pts.length; i++){ |
| 181 |
ProcessThread pt=pts[i]; |
| 182 |
synchronized(pt){ |
| 183 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 184 |
try { |
| 185 |
pt.join(); |
| 186 |
} catch (InterruptedException e) { |
| 187 |
|
| 188 |
e.printStackTrace(); |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
if(i==0){ |
| 193 |
System.out.print("Detecting finished threads: 0"); |
| 194 |
}else{ |
| 195 |
System.out.print(", "+i); |
| 196 |
} |
| 197 |
} |
| 198 |
System.out.println('\n'); |
| 199 |
ReadWrite.closeStreams(cris, ros); |
| 200 |
|
| 201 |
printStatistics(pts); |
| 202 |
|
| 203 |
t.stop(); |
| 204 |
System.out.println("Time: \t"+t); |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
public static void printStatistics(ProcessThread[] pts){ |
| 209 |
|
| 210 |
long plusAdaptersFound=0; |
| 211 |
long minusAdaptersFound=0; |
| 212 |
long goodReadsFound=0; |
| 213 |
long badReadsFound=0; |
| 214 |
|
| 215 |
long truepositive=0; |
| 216 |
long truenegative=0; |
| 217 |
long falsepositive=0; |
| 218 |
long falsenegative=0; |
| 219 |
long expected=0; |
| 220 |
long unexpected=0; |
| 221 |
long basesIn=0; |
| 222 |
long basesOut=0; |
| 223 |
long readsOut=0; |
| 224 |
|
| 225 |
for(ProcessThread pt : pts){ |
| 226 |
plusAdaptersFound+=pt.plusAdaptersFound; |
| 227 |
minusAdaptersFound+=pt.minusAdaptersFound; |
| 228 |
goodReadsFound+=pt.goodReadsFound; |
| 229 |
badReadsFound+=pt.badReadsFound; |
| 230 |
basesIn+=pt.basesIn; |
| 231 |
basesOut+=pt.basesOut; |
| 232 |
readsOut+=pt.readsOut; |
| 233 |
|
| 234 |
truepositive+=pt.truepositive; |
| 235 |
truenegative+=pt.truenegative; |
| 236 |
falsepositive+=pt.falsepositive; |
| 237 |
falsenegative+=pt.falsenegative; |
| 238 |
expected+=pt.expected; |
| 239 |
unexpected+=pt.unexpected; |
| 240 |
} |
| 241 |
|
| 242 |
long totalReads=goodReadsFound+badReadsFound; |
| 243 |
long totalAdapters=plusAdaptersFound+minusAdaptersFound; |
| 244 |
if(expected<1){expected=1;} |
| 245 |
if(unexpected<1){unexpected=1;} |
| 246 |
|
| 247 |
System.out.println("Reads In: \t"+totalReads+" \t("+basesIn+" bases, avg length "+(basesIn/totalReads)+")"); |
| 248 |
System.out.println("Good reads: \t"+goodReadsFound); |
| 249 |
System.out.println("Bad reads: \t"+badReadsFound+" \t("+totalAdapters+" adapters)"); |
| 250 |
System.out.println("Plus adapters: \t"+plusAdaptersFound); |
| 251 |
System.out.println("Minus adapters: \t"+minusAdaptersFound); |
| 252 |
System.out.println("Adapters per megabase: \t"+Tools.format("%.3f",totalAdapters*1000000f/basesIn)); |
| 253 |
if(readsOut>0){System.out.println("Reads Out: \t"+readsOut+" \t("+basesOut+" bases, avg length "+(basesOut/readsOut)+")");} |
| 254 |
System.out.println(); |
| 255 |
if(truepositive>0 || truenegative>0 || falsepositive>0 || falsenegative>0){ |
| 256 |
System.out.println("Adapters Expected: \t"+expected); |
| 257 |
System.out.println("True Positive: \t"+truepositive+" \t"+Tools.format("%.3f%%", truepositive*100f/expected)); |
| 258 |
System.out.println("True Negative: \t"+truenegative+" \t"+Tools.format("%.3f%%", truenegative*100f/unexpected)); |
| 259 |
System.out.println("False Positive: \t"+falsepositive+" \t"+Tools.format("%.3f%%", falsepositive*100f/unexpected)); |
| 260 |
System.out.println("False Negative: \t"+falsenegative+" \t"+Tools.format("%.3f%%", falsenegative*100f/expected)); |
| 261 |
} |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
private static class ProcessThread extends Thread{ |
| 266 |
|
| 267 |
public ProcessThread(ConcurrentReadInputStream cris_, |
| 268 |
ConcurrentReadOutputStream ros_, float minRatio_, String query_, boolean split_) { |
| 269 |
cris=cris_; |
| 270 |
ros=ros_; |
| 271 |
minRatio=minRatio_; |
| 272 |
query1=query_.getBytes(); |
| 273 |
query2=AminoAcid.reverseComplementBases(query1); |
| 274 |
ALIGN_ROWS=query1.length+1; |
| 275 |
ALIGN_COLUMNS=ALIGN_ROWS*3+20; |
| 276 |
SPLIT=split_; |
| 277 |
|
| 278 |
stride=(int)(query1.length*0.95f); |
| 279 |
window=(int)(query1.length*2.5f+10); |
| 280 |
assert(window<ALIGN_COLUMNS); |
| 281 |
|
| 282 |
msa=new MultiStateAligner9PacBioAdapter(ALIGN_ROWS, ALIGN_COLUMNS); |
| 283 |
msa2=USE_ALT_MSA ? new MultiStateAligner9PacBioAdapter2() : null; |
| 284 |
|
| 285 |
maxSwScore=msa.maxQuality(query1.length); |
| 286 |
minSwScore=(int)(maxSwScore*MINIMUM_ALIGNMENT_SCORE_RATIO); |
| 287 |
minSwScoreSuspect=(int)(maxSwScore*Tools.min(MINIMUM_ALIGNMENT_SCORE_RATIO*SUSPECT_RATIO, MINIMUM_ALIGNMENT_SCORE_RATIO-((1-SUSPECT_RATIO)*.2f))); |
| 288 |
maxImperfectSwScore=msa.maxImperfectScore(query1.length); |
| 289 |
|
| 290 |
suspectMidpoint=(minSwScoreSuspect+minSwScore)/2; |
| 291 |
} |
| 292 |
|
| 293 |
@Override |
| 294 |
public void run(){ |
| 295 |
ListNum<Read> ln=cris.nextList(); |
| 296 |
ArrayList<Read> readlist=ln.list; |
| 297 |
|
| 298 |
while(!readlist.isEmpty()){ |
| 299 |
|
| 300 |
|
| 301 |
for(int i=0; i<readlist.size(); i++){ |
| 302 |
Read r=readlist.get(i); |
| 303 |
|
| 304 |
if(r.length()<minContig && (r.mate==null || r.mateLength()<minContig)){ |
| 305 |
readlist.set(i, null); |
| 306 |
}else{ |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
if(r.synthetic()){syntheticReads++;} |
| 312 |
|
| 313 |
processRead(r); |
| 314 |
if(r.mate!=null){processRead(r.mate);} |
| 315 |
} |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
if(ros!=null){ |
| 321 |
if(DONT_OUTPUT_BROKEN_READS){removeDiscarded(readlist);} |
| 322 |
for(Read r : readlist){ |
| 323 |
if(r!=null){ |
| 324 |
r.obj=null; |
| 325 |
assert(r.bases!=null); |
| 326 |
if(r.sites!=null && r.sites.isEmpty()){r.sites=null;} |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
ArrayList<Read> out=SPLIT ? split(readlist) : readlist; |
| 332 |
for(Read r : out){ |
| 333 |
if(r!=null){ |
| 334 |
Read r2=r.mate; |
| 335 |
basesOut+=r.length(); |
| 336 |
readsOut++; |
| 337 |
if(r2!=null){ |
| 338 |
basesOut+=r2.length(); |
| 339 |
readsOut++; |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
ros.add(out, ln.id); |
| 344 |
} |
| 345 |
|
| 346 |
cris.returnList(ln.id, readlist.isEmpty()); |
| 347 |
|
| 348 |
|
| 349 |
ln=cris.nextList(); |
| 350 |
readlist=ln.list; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
assert(readlist.isEmpty()); |
| 355 |
cris.returnList(ln.id, readlist.isEmpty()); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
private static ArrayList<Read> split(ArrayList<Read> in) { |
| 363 |
ArrayList<Read> out=new ArrayList<Read>(in.size()); |
| 364 |
for(Read r : in){ |
| 365 |
if(r!=null){ |
| 366 |
|
| 367 |
if(!r.hasAdapter()){out.add(r);} |
| 368 |
else{out.addAll(split(r));} |
| 369 |
Read r2=r.mate; |
| 370 |
if(r2!=null){ |
| 371 |
if(!r2.hasAdapter()){out.add(r2);} |
| 372 |
else{out.addAll(split(r2));} |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
return out; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
private static ArrayList<Read> split(Read r) { |
| 384 |
ArrayList<Read> sections=new ArrayList<Read>(); |
| 385 |
|
| 386 |
int lastX=-1; |
| 387 |
for(int i=0; i<r.length(); i++){ |
| 388 |
if(r.bases[i]=='X'){ |
| 389 |
if(i-lastX>minContig){ |
| 390 |
byte[] b=KillSwitch.copyOfRange(r.bases, lastX+1, i); |
| 391 |
byte[] q=r.quality==null ? null : KillSwitch.copyOfRange(r.quality, lastX+1, i); |
| 392 |
Read r2=new Read(b, q, r.id+"_"+(lastX+1), r.numericID); |
| 393 |
sections.add(r2); |
| 394 |
} |
| 395 |
lastX=i; |
| 396 |
} |
| 397 |
} |
| 398 |
int i=r.length(); |
| 399 |
if(i-lastX>minContig){ |
| 400 |
byte[] b=KillSwitch.copyOfRange(r.bases, lastX+1, i); |
| 401 |
byte[] q=r.quality==null ? null : KillSwitch.copyOfRange(r.quality, lastX+1, i); |
| 402 |
Read r2=new Read(b, q, r.id+"_"+(lastX+1), r.numericID); |
| 403 |
sections.add(r2); |
| 404 |
} |
| 405 |
return sections; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
private int processRead(Read r) { |
| 412 |
|
| 413 |
int begin=0; |
| 414 |
while(begin<r.length() && r.bases[begin]=='N'){begin++;} |
| 415 |
if(begin>=r.length()){return 0;} |
| 416 |
|
| 417 |
basesIn+=r.length(); |
| 418 |
|
| 419 |
final byte[] array=npad(r.bases, npad); |
| 420 |
|
| 421 |
int lim=array.length-npad-stride; |
| 422 |
|
| 423 |
int plusFound=0; |
| 424 |
int minusFound=0; |
| 425 |
|
| 426 |
int lastSuspect=-1; |
| 427 |
int lastConfirmed=-1; |
| 428 |
|
| 429 |
for(int i=begin; i<lim; i+=stride){ |
| 430 |
int j=Tools.min(i+window, array.length-1); |
| 431 |
if(j-i<window){ |
| 432 |
lim=0; |
| 433 |
|
| 434 |
} |
| 435 |
|
| 436 |
if(TRY_MINUS){ |
| 437 |
int[] rvec=msa.fillAndScoreLimited(query2, array, i, j, minSwScoreSuspect); |
| 438 |
if(rvec!=null && rvec[0]>=minSwScoreSuspect){ |
| 439 |
int score=rvec[0]; |
| 440 |
int start=rvec[1]; |
| 441 |
int stop=rvec[2]; |
| 442 |
assert(score>=minSwScoreSuspect); |
| 443 |
if((i==0 || start>i) && (j==array.length-1 || stop<j)){ |
| 444 |
boolean kill=(score>=minSwScore || |
| 445 |
(score>=suspectMidpoint && lastSuspect>0 && start>=lastSuspect && start-lastSuspect<suspectDistance) || |
| 446 |
(lastConfirmed>0 && start>=lastConfirmed && start-lastConfirmed<suspectDistance)); |
| 447 |
|
| 448 |
if(!kill && USE_LOCALITY && array.length-stop>window){ |
| 449 |
rvec=msa.fillAndScoreLimited(query2, array, stop, stop+window, minSwScoreSuspect); |
| 450 |
if(rvec!=null){ |
| 451 |
if(score>=suspectMidpoint && rvec[0]>=minSwScoreSuspect && rvec[1]-stop<suspectDistance){kill=true;} |
| 452 |
else if(score>=minSwScoreSuspect && rvec[0]>=minSwScore && rvec[1]-stop<suspectDistance){kill=true;} |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
if(!kill && USE_ALT_MSA){ |
| 457 |
rvec=msa2.fillAndScoreLimited(query2, array, Tools.max(0, start-4), Tools.min(stop+4, array.length-1), minSwScoreSuspect); |
| 458 |
if(rvec!=null && rvec[0]>=(minSwScore)){kill=true;} |
| 459 |
} |
| 460 |
|
| 461 |
if(kill){ |
| 462 |
|
| 463 |
minusFound++; |
| 464 |
for(int x=Tools.max(0, start); x<=stop; x++){array[x]='X';} |
| 465 |
if(USE_LOCALITY && score>=minSwScore){lastConfirmed=Tools.max(lastConfirmed, stop);} |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
if(USE_LOCALITY){lastSuspect=Tools.max(lastSuspect, stop);} |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
if(TRY_PLUS){ |
| 474 |
int[] rvec=msa.fillAndScoreLimited(query1, array, i, j, minSwScoreSuspect); |
| 475 |
if(rvec!=null && rvec[0]>=minSwScoreSuspect){ |
| 476 |
int score=rvec[0]; |
| 477 |
int start=rvec[1]; |
| 478 |
int stop=rvec[2]; |
| 479 |
if((i==0 || start>i) && (j==array.length-1 || stop<j)){ |
| 480 |
boolean kill=(score>=minSwScore || |
| 481 |
(score>=suspectMidpoint && lastSuspect>0 && start>=lastSuspect && start-lastSuspect<suspectDistance) || |
| 482 |
(lastConfirmed>0 && start>=lastConfirmed && start-lastConfirmed<suspectDistance)); |
| 483 |
|
| 484 |
if(!kill && USE_LOCALITY && array.length-stop>window){ |
| 485 |
rvec=msa.fillAndScoreLimited(query1, array, stop, stop+window, minSwScoreSuspect); |
| 486 |
if(rvec!=null){ |
| 487 |
if(score>=suspectMidpoint && rvec[0]>=minSwScoreSuspect && rvec[1]-stop<suspectDistance){kill=true;} |
| 488 |
else if(score>=minSwScoreSuspect && rvec[0]>=minSwScore && rvec[1]-stop<suspectDistance){kill=true;} |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
if(!kill && USE_ALT_MSA){ |
| 493 |
rvec=msa2.fillAndScoreLimited(query1, array, Tools.max(0, start-4), Tools.min(stop+4, array.length-1), minSwScoreSuspect); |
| 494 |
if(rvec!=null && rvec[0]>=(minSwScore)){kill=true;} |
| 495 |
} |
| 496 |
|
| 497 |
if(kill){ |
| 498 |
|
| 499 |
plusFound++; |
| 500 |
for(int x=Tools.max(0, start); x<=stop; x++){array[x]='X';} |
| 501 |
if(USE_LOCALITY && score>=minSwScore){lastConfirmed=Tools.max(lastConfirmed, stop);} |
| 502 |
} |
| 503 |
} |
| 504 |
|
| 505 |
if(USE_LOCALITY){lastSuspect=Tools.max(lastSuspect, stop);} |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
int found=plusFound+minusFound; |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
if(r.synthetic()){ |
| 531 |
if((r.numericID&3)==0){ |
| 532 |
if(found>0){truepositive++;}else{falsenegative++;} |
| 533 |
if(found>1){falsepositive+=(found-1);} |
| 534 |
expected++; |
| 535 |
}else if((r.numericID&3)==1){ |
| 536 |
if(found>0){truepositive++;}else{falsenegative++;} |
| 537 |
if(found>1){falsepositive+=(found-1);} |
| 538 |
expected++; |
| 539 |
}else{ |
| 540 |
falsepositive+=found; |
| 541 |
if(found==0){truenegative++;} |
| 542 |
unexpected++; |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
plusAdaptersFound+=plusFound; |
| 547 |
minusAdaptersFound+=minusFound; |
| 548 |
if(found>0){ |
| 549 |
for(int i=npad, j=0; j<r.length(); i++, j++){r.bases[j]=array[i];} |
| 550 |
if(DONT_OUTPUT_BROKEN_READS){r.setDiscarded(true);} |
| 551 |
badReadsFound++; |
| 552 |
}else{ |
| 553 |
goodReadsFound++; |
| 554 |
} |
| 555 |
|
| 556 |
r.setHasAdapter(found>0); |
| 557 |
|
| 558 |
return found; |
| 559 |
|
| 560 |
} |
| 561 |
|
| 562 |
private byte[] npad(final byte[] array, final int pad){ |
| 563 |
final int len=array.length+2*pad; |
| 564 |
if(padbuffer==null || padbuffer.length!=len){padbuffer=new byte[len];} |
| 565 |
byte[] r=padbuffer; |
| 566 |
for(int i=0; i<pad; i++){r[i]='N';} |
| 567 |
for(int i=pad, j=0; j<array.length; i++, j++){r[i]=array[j];} |
| 568 |
for(int i=array.length+pad, limit=Tools.min(r.length, len+50); i<limit; i++){r[i]='N';} |
| 569 |
padbuffer=null; |
| 570 |
return r; |
| 571 |
} |
| 572 |
|
| 573 |
private byte[] padbuffer=null; |
| 574 |
private final byte[] query1, query2; |
| 575 |
private final ConcurrentReadInputStream cris; |
| 576 |
private final ConcurrentReadOutputStream ros; |
| 577 |
private final float minRatio; |
| 578 |
private final MultiStateAligner9PacBioAdapter msa; |
| 579 |
private final MultiStateAligner9PacBioAdapter2 msa2; |
| 580 |
private final int ALIGN_ROWS; |
| 581 |
private final int ALIGN_COLUMNS; |
| 582 |
private final int stride; |
| 583 |
private final int window; |
| 584 |
private final boolean SPLIT; |
| 585 |
|
| 586 |
long plusAdaptersFound=0; |
| 587 |
long minusAdaptersFound=0; |
| 588 |
long goodReadsFound=0; |
| 589 |
long badReadsFound=0; |
| 590 |
long truepositive=0; |
| 591 |
long truenegative=0; |
| 592 |
long falsepositive=0; |
| 593 |
long falsenegative=0; |
| 594 |
long expected=0; |
| 595 |
long unexpected=0; |
| 596 |
long basesIn=0; |
| 597 |
long basesOut=0; |
| 598 |
long readsOut=0; |
| 599 |
|
| 600 |
private final int maxSwScore; |
| 601 |
private final int minSwScore; |
| 602 |
private final int minSwScoreSuspect; |
| 603 |
private final int suspectMidpoint; |
| 604 |
private final int maxImperfectSwScore; |
| 605 |
|
| 606 |
long syntheticReads=0; |
| 607 |
|
| 608 |
} |
| 609 |
|
| 610 |
private static int removeDiscarded(ArrayList<Read> list){ |
| 611 |
int removed=0; |
| 612 |
for(int i=0; i<list.size(); i++){ |
| 613 |
Read r=list.get(i); |
| 614 |
if(r.discarded()){ |
| 615 |
if(r.mate==null || r.mate.discarded()){ |
| 616 |
list.set(i, null); |
| 617 |
removed++; |
| 618 |
} |
| 619 |
} |
| 620 |
} |
| 621 |
return removed; |
| 622 |
} |
| 623 |
|
| 624 |
public static boolean DONT_OUTPUT_BROKEN_READS; |
| 625 |
|
| 626 |
private static boolean overwrite=true; |
| 627 |
|
| 628 |
private static boolean append=false; |
| 629 |
private static int THREADS=Shared.LOGICAL_PROCESSORS; |
| 630 |
private static boolean OUTPUT_READS=false; |
| 631 |
private static boolean ordered=false; |
| 632 |
private static boolean PERFECTMODE=false; |
| 633 |
private static float MINIMUM_ALIGNMENT_SCORE_RATIO=0.31f; |
| 634 |
private static float SUSPECT_RATIO=0.85F; |
| 635 |
public static boolean USE_LOCALITY=true; |
| 636 |
public static boolean USE_ALT_MSA=true; |
| 637 |
public static boolean TRY_PLUS=true; |
| 638 |
public static boolean TRY_MINUS=true; |
| 639 |
private static int npad=35; |
| 640 |
public static int minContig=50; |
| 641 |
public static int suspectDistance=100; |
| 642 |
|
| 643 |
public static final String pacbioAdapter="ATCTCTCTCTTTTCCTCCTCCTCCGTTGTTGTTGTTGAGAGAGAT"; |
| 644 |
public static final String pacbioStandard_v1="TCCTCCTCCTCCGTTGTTGTTGTTGAGAGAGAGAAGGCTGGGCAGGCTATGCACCCTGGTCCAGGTCAAA" + |
| 645 |
"AGCTGCGGAACCCGCTAGCGGCCATCTTGGCCACTAGGGGTCCCGCAGATTCATATTGTCGTCTAGCATGCACAATGCTGCAAACCCAGCTTGCAATGCCCACAGCA" + |
| 646 |
"AGCGGCCAATCTTTACGCCACGTTGAATTGTTTATTACCTGTGACTGGCTATGGCTTGCAACGCCACTCGTAAAACTAGTACTTTGCGGTTAGGGGAAGTAGACAAA" + |
| 647 |
"CCCATTACTCCACTTCCCGGAAGTTCAACTCATTCCAACACGAAATAAAAGTAAACTCAACACCCCAAGCAGGCTATGTGGGGGGGTGATAGGGGTGGATTCTATTT" + |
| 648 |
"CCTATCCCATCCCCTAGGATCTCAATTAAGTTACTAGCGAGTTAAATGTCTGTAGCGATCCCGTCAGTCCTATCGCGCGCATCAAGACCTGGTTGGTTGAGCGTGCA" + |
| 649 |
"GTAGATCATCGATAAGCTGCGAGTTAGGTCATCCCAGACCGCATCTGGCGCCTAAACGTTCAGTGGTAGCTAAGGCGTCACCTTCGACTGTCTAAAGGCAATATGTC" + |
| 650 |
"GTCCTTAGCTCCAAGTCCCTAGCAAGCGTGTCGGGTCTCTCTCTTTTCCTCCTCCTCCGTTGTTGTTGTTGAGAGAGACCCGACACGCTTGCTAGGGACTTGGAGCT" + |
| 651 |
"AAGGACGACATATTGCCTTTAGACAGTCGAAGGTGACGCCTTAGCTACCACTGAACGTTTAGGCGCCAGATGCGGTCTGGGATGACCTAACTCGCAGCTTATCGATG" + |
| 652 |
"ATCTACTGCACGCTCAACCAACCAGGTCTTGATGCGCGCGATAGGACTGACGGGATCGCTACAGACATTTAACTCGCTAGTAACTTAATTGAGATCCTAGGGGATGG" + |
| 653 |
"GATAGGAAATAGAATCCACCCCTATCACCCCCCCACATAGCCTGCTTGGGGTGTTGAGTTTACTTTTATTTCGTGTTGGAATGAGTTGAACTTCCGGGAAGTGGAGT" + |
| 654 |
"AATGGGTTTGTCTACTTCCCCTAACCGCAAAGTACTAGTTTTACGAGTGGCGTTGCAAGCCATAGCCAGTCACAGGTAATAAACAATTCAACGTGGCGTAAAGATTG" + |
| 655 |
"GCCGCTTGCTGTGGGCATTGCAAGCTGGGTTTGCAGCATTGTGCATGCTAGACGACAATATGAATCTGCGGGACCCCTAGTGGCCAAGATGGCCGCTAGCGGGTTCC" + |
| 656 |
"GCAGCTTTTGACCTGGACCAGGGTGCATAGCCTGCCCAGCCTTCTCTCTCTCTTT"; |
| 657 |
|
| 658 |
|
| 659 |
} |