| 1 |
package prok; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
import java.util.Collections; |
| 7 |
import java.util.Comparator; |
| 8 |
import java.util.HashMap; |
| 9 |
import java.util.Map.Entry; |
| 10 |
import java.util.concurrent.ConcurrentLinkedQueue; |
| 11 |
import java.util.concurrent.locks.ReadWriteLock; |
| 12 |
import java.util.concurrent.locks.ReentrantReadWriteLock; |
| 13 |
|
| 14 |
import aligner.SingleStateAlignerFlat2; |
| 15 |
import consensus.BaseGraph; |
| 16 |
import fileIO.ByteFile; |
| 17 |
import fileIO.FileFormat; |
| 18 |
import fileIO.ReadWrite; |
| 19 |
import shared.Parse; |
| 20 |
import shared.Parser; |
| 21 |
import shared.PreParser; |
| 22 |
import shared.Shared; |
| 23 |
import shared.Timer; |
| 24 |
import shared.Tools; |
| 25 |
import stream.ConcurrentReadInputStream; |
| 26 |
import stream.ConcurrentReadOutputStream; |
| 27 |
import stream.FASTQ; |
| 28 |
import stream.FastaReadInputStream; |
| 29 |
import stream.Read; |
| 30 |
import structures.IntHashSet; |
| 31 |
import structures.ListNum; |
| 32 |
import tax.GiToTaxid; |
| 33 |
import template.Accumulator; |
| 34 |
import template.ThreadWaiter; |
| 35 |
import tracker.ReadStats; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class MergeRibo implements Accumulator<MergeRibo.ProcessThread> { |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static void main(String[] args){ |
| 55 |
|
| 56 |
Timer t=new Timer(); |
| 57 |
|
| 58 |
|
| 59 |
MergeRibo x=new MergeRibo(args); |
| 60 |
|
| 61 |
|
| 62 |
x.process(t); |
| 63 |
|
| 64 |
|
| 65 |
Shared.closeStream(x.outstream); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public MergeRibo(String[] args){ |
| 73 |
|
| 74 |
{ |
| 75 |
PreParser pp=new PreParser(args, getClass(), false); |
| 76 |
args=pp.args; |
| 77 |
outstream=pp.outstream; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; |
| 82 |
ReadWrite.setZipThreads(Shared.threads()); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
BaseGraph.MAF_sub=0.251f; |
| 87 |
BaseGraph.MAF_del=0.0f; |
| 88 |
BaseGraph.MAF_ins=0.0f; |
| 89 |
BaseGraph.MAF_noref=0.0f; |
| 90 |
BaseGraph.trimDepthFraction=0.3f; |
| 91 |
BaseGraph.trimNs=true; |
| 92 |
|
| 93 |
{ |
| 94 |
final Parser parser=parse(args); |
| 95 |
Parser.processQuality(); |
| 96 |
|
| 97 |
maxReads=parser.maxReads; |
| 98 |
overwrite=ReadStats.overwrite=parser.overwrite; |
| 99 |
append=ReadStats.append=parser.append; |
| 100 |
|
| 101 |
extin=parser.extin; |
| 102 |
|
| 103 |
out1=parser.out1; |
| 104 |
extout=parser.extout; |
| 105 |
} |
| 106 |
|
| 107 |
validateParams(); |
| 108 |
adjustInterleaving(); |
| 109 |
checkFileExistence(); |
| 110 |
checkStatics(); |
| 111 |
|
| 112 |
|
| 113 |
ffout1=FileFormat.testOutput(out1, FileFormat.FASTA, extout, true, overwrite, append, ordered); |
| 114 |
|
| 115 |
|
| 116 |
ffin=new ArrayList<FileFormat>(in.size()); |
| 117 |
ffalt=FileFormat.testInput(alt, FileFormat.FASTA, extin, true, true); |
| 118 |
for(String s : in){ |
| 119 |
FileFormat ff=FileFormat.testInput(s, FileFormat.FASTA, extin, true, true); |
| 120 |
ffin.add(ff); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
threads=Shared.threads(); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
private Parser parse(String[] args){ |
| 133 |
|
| 134 |
|
| 135 |
Parser parser=new Parser(); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
for(int i=0; i<args.length; i++){ |
| 142 |
String arg=args[i]; |
| 143 |
|
| 144 |
|
| 145 |
String[] split=arg.split("="); |
| 146 |
String a=split[0].toLowerCase(); |
| 147 |
String b=split.length>1 ? split[1] : null; |
| 148 |
if(b!=null && b.equalsIgnoreCase("null")){b=null;} |
| 149 |
|
| 150 |
if(a.equals("verbose")){ |
| 151 |
verbose=Parse.parseBoolean(b); |
| 152 |
}else if(a.equals("ordered")){ |
| 153 |
ordered=Parse.parseBoolean(b); |
| 154 |
}else if(a.equals("consensus")){ |
| 155 |
useConsensus=Parse.parseBoolean(b); |
| 156 |
}else if(a.equals("best")){ |
| 157 |
useConsensus=!Parse.parseBoolean(b); |
| 158 |
}else if(a.equals("fast")){ |
| 159 |
fast=Parse.parseBoolean(b); |
| 160 |
}else if(a.equals("minid")){ |
| 161 |
minID=Float.parseFloat(b); |
| 162 |
}else if(a.equals("maxns")){ |
| 163 |
maxns=Integer.parseInt(b); |
| 164 |
}else if(a.equals("minlen")){ |
| 165 |
minlen=Integer.parseInt(b); |
| 166 |
}else if(a.equals("maxlen")){ |
| 167 |
maxlen=Integer.parseInt(b); |
| 168 |
}else if(a.equals("in")){ |
| 169 |
Tools.addFiles(b, in); |
| 170 |
}else if(a.equals("alt")){ |
| 171 |
alt=b; |
| 172 |
}else if(a.equalsIgnoreCase("process16S") || a.equalsIgnoreCase("16S")){ |
| 173 |
process16S=Parse.parseBoolean(b); |
| 174 |
process18S=!process16S; |
| 175 |
}else if(a.equalsIgnoreCase("process18S") || a.equalsIgnoreCase("18S")){ |
| 176 |
process18S=Parse.parseBoolean(b); |
| 177 |
process16S=!process18S; |
| 178 |
}else if(a.equals("parse_flag_goes_here")){ |
| 179 |
long fake_variable=Parse.parseKMG(b); |
| 180 |
|
| 181 |
}else if(parser.parse(arg, a, b)){ |
| 182 |
|
| 183 |
}else if(b==null && new File(arg).exists()){ |
| 184 |
in.add(arg); |
| 185 |
}else{ |
| 186 |
outstream.println("Unknown parameter "+args[i]); |
| 187 |
assert(false) : "Unknown parameter "+args[i]; |
| 188 |
} |
| 189 |
} |
| 190 |
assert(!in.isEmpty()) : "No input file."; |
| 191 |
return parser; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
private void checkFileExistence(){ |
| 196 |
|
| 197 |
if(!Tools.testOutputFiles(overwrite, append, false, out1)){ |
| 198 |
outstream.println((out1==null)+", "+out1); |
| 199 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out1+"\n"); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
if(!Tools.testInputFiles(false, true, in)){ |
| 204 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
private void adjustInterleaving(){ |
| 215 |
FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
private static void checkStatics(){ |
| 220 |
|
| 221 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 222 |
ByteFile.FORCE_MODE_BF2=true; |
| 223 |
} |
| 224 |
|
| 225 |
assert(FastaReadInputStream.settingsOK()); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
private boolean validateParams(){ |
| 230 |
|
| 231 |
|
| 232 |
assert(process16S || process18S) : "16S or 18S must be selected."; |
| 233 |
assert(!process16S || !process18S) : "16S or 18S are both selected; only one may be active."; |
| 234 |
return true; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
void process(Timer t){ |
| 243 |
|
| 244 |
if(process16S){ |
| 245 |
Read[] data=ProkObject.loadConsensusSequenceType("16S", true, true); |
| 246 |
consensus16S=data[0].bases; |
| 247 |
if(verbose){System.err.println("process16S: Loaded 16S consensus, length "+consensus16S.length+": "+new String(consensus16S));} |
| 248 |
} |
| 249 |
if(process18S){ |
| 250 |
Read[] data=ProkObject.loadConsensusSequenceType("18S", true, true); |
| 251 |
consensus18S=data[0].bases; |
| 252 |
if(verbose){System.err.println("process18S: Loaded 18S consensus, length "+consensus18S.length+": "+new String(consensus18S));} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR; |
| 257 |
Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4; |
| 258 |
|
| 259 |
|
| 260 |
readsProcessed=readsOut=0; |
| 261 |
basesProcessed=basesOut=0; |
| 262 |
|
| 263 |
|
| 264 |
for(FileFormat ff : ffin) { |
| 265 |
|
| 266 |
final ConcurrentReadInputStream cris=makeCris(ff); |
| 267 |
|
| 268 |
|
| 269 |
spawnThreads(cris, false); |
| 270 |
errorState|=ReadWrite.closeStream(cris); |
| 271 |
} |
| 272 |
|
| 273 |
if(ffalt!=null){ |
| 274 |
|
| 275 |
final ConcurrentReadInputStream cris=makeCris(ffalt); |
| 276 |
|
| 277 |
|
| 278 |
spawnThreads(cris, true); |
| 279 |
errorState|=ReadWrite.closeStream(cris); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
queue=makeQueue(); |
| 288 |
|
| 289 |
|
| 290 |
spawnThreads(null, false); |
| 291 |
|
| 292 |
|
| 293 |
if(ffout1!=null){ |
| 294 |
|
| 295 |
final ConcurrentReadOutputStream ros=makeCros(); |
| 296 |
long num=0; |
| 297 |
for(Ribo ribo : bestList){ |
| 298 |
Read r=ribo.r; |
| 299 |
readsOut++; |
| 300 |
basesOut+=r.length(); |
| 301 |
ArrayList<Read> list=new ArrayList<Read>(1); |
| 302 |
list.add(r); |
| 303 |
ros.add(list, num); |
| 304 |
num++; |
| 305 |
} |
| 306 |
|
| 307 |
errorState|=ReadWrite.closeStream(ros); |
| 308 |
} |
| 309 |
|
| 310 |
if(verbose){outstream.println("Finished; closing streams.");} |
| 311 |
|
| 312 |
|
| 313 |
errorState|=ReadStats.writeAll(); |
| 314 |
|
| 315 |
|
| 316 |
Read.VALIDATE_IN_CONSTRUCTOR=vic; |
| 317 |
|
| 318 |
|
| 319 |
t.stop(); |
| 320 |
outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8)); |
| 321 |
outstream.println(Tools.readsBasesOut(readsProcessed, basesProcessed, readsOut, basesOut, 8, false)); |
| 322 |
|
| 323 |
|
| 324 |
if(errorState){ |
| 325 |
throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
private ConcurrentLinkedQueue<ArrayList<Ribo>> makeQueue(){ |
| 330 |
ArrayList<ArrayList<Ribo>> listList=new ArrayList<ArrayList<Ribo>>(listMap.size()); |
| 331 |
for(Entry<Integer, ArrayList<Ribo>> e : listMap.entrySet()){ |
| 332 |
listList.add(e.getValue()); |
| 333 |
} |
| 334 |
listMap=null; |
| 335 |
Collections.sort(listList, new ListComparator()); |
| 336 |
assert(listList.isEmpty() || listList.get(0).size()>=listList.get(listList.size()-1).size()); |
| 337 |
ConcurrentLinkedQueue<ArrayList<Ribo>> q=new ConcurrentLinkedQueue<ArrayList<Ribo>>(); |
| 338 |
for(ArrayList<Ribo> x : listList){ |
| 339 |
q.add(x); |
| 340 |
} |
| 341 |
return q; |
| 342 |
} |
| 343 |
|
| 344 |
private ConcurrentReadInputStream makeCris(FileFormat ff){ |
| 345 |
ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ff, null); |
| 346 |
cris.start(); |
| 347 |
if(verbose){outstream.println("Started cris");} |
| 348 |
boolean paired=cris.paired(); |
| 349 |
assert(!paired) : "This should not be paired input."; |
| 350 |
return cris; |
| 351 |
} |
| 352 |
|
| 353 |
private ConcurrentReadOutputStream makeCros(){ |
| 354 |
if(ffout1==null){return null;} |
| 355 |
|
| 356 |
|
| 357 |
final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8); |
| 358 |
|
| 359 |
final ConcurrentReadOutputStream ros=ConcurrentReadOutputStream.getStream(ffout1, null, buff, null, false); |
| 360 |
ros.start(); |
| 361 |
return ros; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
private void spawnThreads(final ConcurrentReadInputStream cris, boolean altData){ |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
if(verbose){System.err.println("Spawning "+threads+" threads.");} |
| 375 |
ArrayList<ProcessThread> alpt=new ArrayList<ProcessThread>(threads); |
| 376 |
for(int i=0; i<threads; i++){ |
| 377 |
alpt.add(new ProcessThread(cris, i, altData)); |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
boolean success=ThreadWaiter.startAndWait(alpt, this); |
| 382 |
if(verbose){System.err.println("Threads finished with success="+success+".");} |
| 383 |
errorState&=!success; |
| 384 |
} |
| 385 |
|
| 386 |
@Override |
| 387 |
public final void accumulate(ProcessThread pt){ |
| 388 |
readsProcessed+=pt.readsProcessedT; |
| 389 |
basesProcessed+=pt.basesProcessedT; |
| 390 |
errorState|=(!pt.success); |
| 391 |
} |
| 392 |
|
| 393 |
@Override |
| 394 |
public final boolean success(){return !errorState;} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
class ProcessThread extends Thread { |
| 407 |
|
| 408 |
|
| 409 |
ProcessThread(final ConcurrentReadInputStream cris_, final int tid_, boolean alt_){ |
| 410 |
cris=cris_; |
| 411 |
tid=tid_; |
| 412 |
processInput=(cris!=null); |
| 413 |
altData=alt_; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
@Override |
| 418 |
public void run(){ |
| 419 |
|
| 420 |
|
| 421 |
if(processInput){ |
| 422 |
|
| 423 |
processInner(); |
| 424 |
}else{ |
| 425 |
pickBest(); |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
success=true; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
void processInner(){ |
| 436 |
if(verbose && tid==0){System.err.println("processInner() for tid="+tid);} |
| 437 |
|
| 438 |
|
| 439 |
ListNum<Read> ln=cris.nextList(); |
| 440 |
|
| 441 |
|
| 442 |
if(ln!=null && !ln.isEmpty()){ |
| 443 |
Read r=ln.get(0); |
| 444 |
|
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
while(ln!=null && ln.size()>0){ |
| 449 |
|
| 450 |
|
| 451 |
processInput(ln); |
| 452 |
|
| 453 |
|
| 454 |
cris.returnList(ln); |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
ln=cris.nextList(); |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
if(ln!=null){ |
| 463 |
cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
void processInput(ListNum<Read> ln){ |
| 468 |
if(verbose && tid==0){System.err.println("processInput() for tid="+tid);} |
| 469 |
|
| 470 |
|
| 471 |
final ArrayList<Read> reads=ln.list; |
| 472 |
|
| 473 |
|
| 474 |
for(int idx=0; idx<reads.size(); idx++){ |
| 475 |
final Read r1=reads.get(idx); |
| 476 |
|
| 477 |
|
| 478 |
if(!r1.validated()){r1.validate(true);} |
| 479 |
|
| 480 |
|
| 481 |
final int initialLength1=r1.length(); |
| 482 |
|
| 483 |
|
| 484 |
readsProcessedT++; |
| 485 |
basesProcessedT+=initialLength1; |
| 486 |
|
| 487 |
processRead(r1); |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
void pickBest(){ |
| 492 |
if(verbose && tid==0){System.err.println("pickBest() for tid="+tid);} |
| 493 |
for(ArrayList<Ribo> list=queue.poll(); list!=null; list=queue.poll()){ |
| 494 |
Ribo best=pickBest(list); |
| 495 |
list.clear(); |
| 496 |
synchronized(bestList){ |
| 497 |
bestList.add(best); |
| 498 |
} |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
Ribo pickBest(ArrayList<Ribo> list){ |
| 503 |
if(verbose && tid==0){System.err.println("pickBest(list[="+list.size()+"]) for tid="+tid);} |
| 504 |
assert(list!=null && list.size()>0); |
| 505 |
if(list.size()==1){return list.get(0);} |
| 506 |
Collections.sort(list); |
| 507 |
Collections.reverse(list); |
| 508 |
assert(list.get(0).product>=list.get(1).product); |
| 509 |
if(list.size()<3 || fast){return list.get(0);} |
| 510 |
|
| 511 |
Ribo base=list.get(0); |
| 512 |
int pad=Tools.max(10, (1600-base.r.length())); |
| 513 |
BaseGraph bg=new BaseGraph(base.r.name(), base.r.bases, base.r.quality, base.r.numericID, pad); |
| 514 |
for(Ribo r : list){ |
| 515 |
bg.alignAndGenerateMatch(r.r, ssa); |
| 516 |
} |
| 517 |
Read consensus=bg.traverse(); |
| 518 |
Ribo best; |
| 519 |
if(useConsensus){ |
| 520 |
best=new Ribo(consensus, base.tid, 1); |
| 521 |
}else{ |
| 522 |
for(Ribo r : list){ |
| 523 |
float id=align(r.r.bases, consensus.bases); |
| 524 |
r.identity=id; |
| 525 |
r.product=score(r.length(), r.identity); |
| 526 |
} |
| 527 |
Collections.sort(list); |
| 528 |
Collections.reverse(list); |
| 529 |
assert(list.get(0).product>=list.get(1).product); |
| 530 |
best=list.get(0); |
| 531 |
} |
| 532 |
return best; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
void processRead(final Read r){ |
| 540 |
if(verbose && tid==0){System.err.println("processRead()");} |
| 541 |
if(r.length()<minlen || r.length()>maxlen){return;} |
| 542 |
if(maxns>=0 && r.countNocalls()>maxns){return;} |
| 543 |
Integer key=GiToTaxid.parseTaxidNumber(r.id, '|'); |
| 544 |
if(verbose && tid==0){System.err.println("key="+key);} |
| 545 |
if(key==null || key==-1 || (altData && seenTaxID.contains(key))){return;} |
| 546 |
float id=align(r); |
| 547 |
if(id<minID){return;} |
| 548 |
Ribo ribo=new Ribo(r, key, id); |
| 549 |
|
| 550 |
synchronized(listMap){ |
| 551 |
ArrayList<Ribo> list=listMap.get(key); |
| 552 |
if(list==null){ |
| 553 |
list=new ArrayList<Ribo>(8); |
| 554 |
listMap.put(key, list); |
| 555 |
} |
| 556 |
list.add(ribo); |
| 557 |
if(!altData){seenTaxID.add(key);} |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
float align(Read r){ |
| 562 |
float a=(process16S ? align(r.bases, consensus16S) : 0); |
| 563 |
float b=(process18S ? align(r.bases, consensus18S) : 0); |
| 564 |
if(verbose && tid==0){System.err.println("Aligned; a="+a+", b="+b);} |
| 565 |
return Tools.max(a, b); |
| 566 |
} |
| 567 |
|
| 568 |
float align(byte[] query, byte[] ref){ |
| 569 |
int a=0, b=ref.length-1; |
| 570 |
int[] max=ssa.fillUnlimited(query, ref, a, b, -9999); |
| 571 |
if(max==null){return 0;} |
| 572 |
|
| 573 |
final int rows=max[0]; |
| 574 |
final int maxCol=max[1]; |
| 575 |
final int maxState=max[2]; |
| 576 |
final float id=ssa.tracebackIdentity(query, ref, a, b, rows, maxCol, maxState, null); |
| 577 |
return id; |
| 578 |
} |
| 579 |
|
| 580 |
SingleStateAlignerFlat2 ssa=new SingleStateAlignerFlat2(); |
| 581 |
|
| 582 |
|
| 583 |
protected long readsProcessedT=0; |
| 584 |
|
| 585 |
protected long basesProcessedT=0; |
| 586 |
|
| 587 |
|
| 588 |
boolean success=false; |
| 589 |
|
| 590 |
|
| 591 |
private final ConcurrentReadInputStream cris; |
| 592 |
|
| 593 |
final int tid; |
| 594 |
|
| 595 |
|
| 596 |
final boolean processInput; |
| 597 |
final boolean altData; |
| 598 |
} |
| 599 |
|
| 600 |
private class Ribo implements Comparable<Ribo>{ |
| 601 |
Ribo(Read r_, int tid_, float identity_){ |
| 602 |
r=r_; |
| 603 |
tid=tid_; |
| 604 |
identity=identity_; |
| 605 |
product=score(r.length(), identity); |
| 606 |
} |
| 607 |
|
| 608 |
@Override |
| 609 |
public int compareTo(Ribo b) { |
| 610 |
if(b.product>product){return -1;} |
| 611 |
else if(b.product<product){return 1;} |
| 612 |
else if(b.r.length()>r.length()){return -1;} |
| 613 |
else if(b.r.length()<r.length()){return 1;} |
| 614 |
return 0; |
| 615 |
} |
| 616 |
|
| 617 |
int length(){return r.length();} |
| 618 |
|
| 619 |
Read r; |
| 620 |
int tid; |
| 621 |
float identity; |
| 622 |
float product; |
| 623 |
} |
| 624 |
|
| 625 |
private class ListComparator implements Comparator<ArrayList<Ribo>> { |
| 626 |
|
| 627 |
@Override |
| 628 |
public int compare(ArrayList<Ribo> a, ArrayList<Ribo> b) { |
| 629 |
return a.size()>b.size() ? -1 : a.size()<b.size() ? 1 : 0; |
| 630 |
} |
| 631 |
|
| 632 |
} |
| 633 |
|
| 634 |
private float lengthMult(int len){ |
| 635 |
int idealLength=idealLength(); |
| 636 |
int max=Tools.max(len, idealLength, 1); |
| 637 |
int min=Tools.min(len, idealLength); |
| 638 |
return min/(float)max; |
| 639 |
} |
| 640 |
|
| 641 |
private float score(int len, float identity){ |
| 642 |
return lengthMult(len)*identity; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
private ArrayList<String> in=new ArrayList<String>(); |
| 651 |
|
| 652 |
|
| 653 |
private String alt=null; |
| 654 |
|
| 655 |
|
| 656 |
private String out1=null; |
| 657 |
|
| 658 |
|
| 659 |
private String extin=null; |
| 660 |
|
| 661 |
private String extout=null; |
| 662 |
|
| 663 |
ArrayList<Ribo> bestList=new ArrayList<Ribo>(); |
| 664 |
HashMap<Integer, ArrayList<Ribo>> listMap=new HashMap<Integer, ArrayList<Ribo>>(100000); |
| 665 |
ConcurrentLinkedQueue<ArrayList<Ribo>> queue; |
| 666 |
|
| 667 |
|
| 668 |
IntHashSet seenTaxID=new IntHashSet(1000000); |
| 669 |
|
| 670 |
byte[] consensus16S; |
| 671 |
byte[] consensus18S; |
| 672 |
|
| 673 |
int idealLength(){ |
| 674 |
if(process16S){return consensus16S.length;} |
| 675 |
return consensus18S.length; |
| 676 |
} |
| 677 |
|
| 678 |
boolean useConsensus=false; |
| 679 |
boolean fast=false; |
| 680 |
int maxns=-1; |
| 681 |
int minlen=1; |
| 682 |
int maxlen=4000; |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
protected long readsProcessed=0; |
| 688 |
|
| 689 |
protected long basesProcessed=0; |
| 690 |
|
| 691 |
|
| 692 |
protected long readsOut=0; |
| 693 |
|
| 694 |
protected long basesOut=0; |
| 695 |
|
| 696 |
|
| 697 |
private long maxReads=-1; |
| 698 |
|
| 699 |
private float minID=0.62f; |
| 700 |
|
| 701 |
private boolean process16S=true; |
| 702 |
private boolean process18S=false; |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
private final ArrayList<FileFormat> ffin; |
| 710 |
private final FileFormat ffalt; |
| 711 |
|
| 712 |
|
| 713 |
private final FileFormat ffout1; |
| 714 |
|
| 715 |
final int threads; |
| 716 |
|
| 717 |
@Override |
| 718 |
public final ReadWriteLock rwlock() {return rwlock;} |
| 719 |
private final ReadWriteLock rwlock=new ReentrantReadWriteLock(); |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
private PrintStream outstream=System.err; |
| 727 |
|
| 728 |
public static boolean verbose=false; |
| 729 |
|
| 730 |
public boolean errorState=false; |
| 731 |
|
| 732 |
private boolean overwrite=true; |
| 733 |
|
| 734 |
private boolean append=false; |
| 735 |
|
| 736 |
private boolean ordered=false; |
| 737 |
|
| 738 |
} |