| 1 |
package assemble; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.util.ArrayList; |
| 5 |
import java.util.Arrays; |
| 6 |
import java.util.BitSet; |
| 7 |
import java.util.HashMap; |
| 8 |
import java.util.concurrent.atomic.AtomicInteger; |
| 9 |
import java.util.concurrent.atomic.AtomicLong; |
| 10 |
|
| 11 |
import dna.AminoAcid; |
| 12 |
import fileIO.ByteFile; |
| 13 |
import fileIO.ByteStreamWriter; |
| 14 |
import fileIO.FileFormat; |
| 15 |
import fileIO.ReadWrite; |
| 16 |
import fileIO.TextStreamWriter; |
| 17 |
import jgi.BBMerge; |
| 18 |
import kmer.AbstractKmerTableSet; |
| 19 |
import kmer.HashBuffer; |
| 20 |
import shared.KillSwitch; |
| 21 |
import shared.Parse; |
| 22 |
import shared.Parser; |
| 23 |
import shared.PreParser; |
| 24 |
import shared.Shared; |
| 25 |
import shared.Timer; |
| 26 |
import shared.Tools; |
| 27 |
import shared.TrimRead; |
| 28 |
import sort.ContigLengthComparator; |
| 29 |
import stream.ConcurrentReadInputStream; |
| 30 |
import stream.ConcurrentReadOutputStream; |
| 31 |
import stream.FastaReadInputStream; |
| 32 |
import stream.Read; |
| 33 |
import structures.ByteBuilder; |
| 34 |
import structures.IntList; |
| 35 |
import structures.ListNum; |
| 36 |
import structures.LongList; |
| 37 |
import tracker.ReadStats; |
| 38 |
import ukmer.Kmer; |
| 39 |
import ukmer.KmerTableSetU; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public abstract class Tadpole extends ShaveObject{ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static void main(String[] args){ |
| 55 |
Timer t=new Timer(), t2=new Timer(); |
| 56 |
t.start(); |
| 57 |
t2.start(); |
| 58 |
|
| 59 |
final Tadpole x=makeTadpole(args, true); |
| 60 |
t2.stop(); |
| 61 |
outstream.println("Initialization Time: \t"+t2); |
| 62 |
|
| 63 |
|
| 64 |
x.process(t); |
| 65 |
|
| 66 |
|
| 67 |
Shared.closeStream(outstream); |
| 68 |
} |
| 69 |
|
| 70 |
public static Tadpole makeTadpole(String[] args, boolean setDefaults){ |
| 71 |
final int k=preparseK(args); |
| 72 |
if(k>31 || FORCE_TADPOLE2){ |
| 73 |
synchronized(Tadpole.class){ |
| 74 |
AbstractKmerTableSet.MASK_CORE=false; |
| 75 |
} |
| 76 |
return new Tadpole2(args, true); |
| 77 |
}else{ |
| 78 |
synchronized(Tadpole.class){ |
| 79 |
AbstractKmerTableSet.MASK_CORE=true; |
| 80 |
} |
| 81 |
Tadpole tad=new Tadpole1(args, true); |
| 82 |
|
| 83 |
|
| 84 |
return tad; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public static final int preparseK(String[] args){ |
| 89 |
int k=31; |
| 90 |
for(int i=0; i<args.length; i++){ |
| 91 |
final String arg=args[i]; |
| 92 |
String[] split=arg.split("="); |
| 93 |
String a=split[0].toLowerCase(); |
| 94 |
String b=split.length>1 ? split[1] : null; |
| 95 |
while(a.charAt(0)=='-'){a=a.substring(1);} |
| 96 |
|
| 97 |
if(a.equals("k")){ |
| 98 |
k=Integer.parseInt(b); |
| 99 |
}else if(a.equals("tad2") || a.equals("tadpole2")){ |
| 100 |
FORCE_TADPOLE2=Parse.parseBoolean(b); |
| 101 |
} |
| 102 |
} |
| 103 |
return Kmer.getMult(k)*Kmer.getK(k); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public Tadpole(String[] args, boolean setDefaults){ |
| 111 |
|
| 112 |
{ |
| 113 |
PreParser pp=new PreParser(args, getClass(), true); |
| 114 |
args=pp.args; |
| 115 |
outstream=pp.outstream; |
| 116 |
} |
| 117 |
kbig=preparseK(args); |
| 118 |
|
| 119 |
if(setDefaults){ |
| 120 |
|
| 121 |
ReadWrite.ZIPLEVEL=2; |
| 122 |
ReadWrite.USE_UNPIGZ=true; |
| 123 |
ReadWrite.USE_PIGZ=true; |
| 124 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 125 |
ByteFile.FORCE_MODE_BF2=true; |
| 126 |
} |
| 127 |
AbstractKmerTableSet.defaultMinprob=0.5; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
Parser parser=new Parser(); |
| 132 |
boolean ecc_=false, ecco_=false, merge_=false, testMerge_=true, vstrict_=false, setEcc_=false; |
| 133 |
boolean useOwnership_=false, setUseOwnership_=false; |
| 134 |
|
| 135 |
int prefilter=0; |
| 136 |
|
| 137 |
|
| 138 |
for(int i=0; i<args.length; i++){ |
| 139 |
|
| 140 |
final String arg=args[i]; |
| 141 |
String[] split=arg.split("="); |
| 142 |
String a=split[0].toLowerCase(); |
| 143 |
String b=split.length>1 ? split[1] : null; |
| 144 |
|
| 145 |
if(a.equals("in") || a.equals("in1") || a.equals("ine") || a.equals("ine1")){ |
| 146 |
in1.clear(); |
| 147 |
if(b!=null){ |
| 148 |
String[] s=b.split(","); |
| 149 |
for(String ss : s){ |
| 150 |
in1.add(ss); |
| 151 |
} |
| 152 |
} |
| 153 |
}else if(a.equals("in2") || a.equals("ine2")){ |
| 154 |
in2.clear(); |
| 155 |
if(b!=null){ |
| 156 |
String[] s=b.split(","); |
| 157 |
for(String ss : s){ |
| 158 |
in2.add(ss); |
| 159 |
} |
| 160 |
} |
| 161 |
}else if(a.equals("extra")){ |
| 162 |
|
| 163 |
}else if(a.equals("out") || a.equals("out1") || a.equals("oute") || a.equals("oute1")){ |
| 164 |
out1.clear(); |
| 165 |
if(b!=null){ |
| 166 |
String[] s=b.split(","); |
| 167 |
for(String ss : s){ |
| 168 |
out1.add(ss); |
| 169 |
} |
| 170 |
} |
| 171 |
}else if(a.equals("out2") || a.equals("oute2")){ |
| 172 |
out2.clear(); |
| 173 |
if(b!=null){ |
| 174 |
String[] s=b.split(","); |
| 175 |
for(String ss : s){ |
| 176 |
out2.add(ss); |
| 177 |
} |
| 178 |
} |
| 179 |
}else if(a.equals("outd") || a.equals("outdiscard") || a.equals("outd1") || a.equals("outdiscard1")){ |
| 180 |
outd1.clear(); |
| 181 |
if(b!=null){ |
| 182 |
String[] s=b.split(","); |
| 183 |
for(String ss : s){ |
| 184 |
outd1.add(ss); |
| 185 |
} |
| 186 |
} |
| 187 |
}else if(a.equals("outd2") || a.equals("outdiscard2")){ |
| 188 |
outd2.clear(); |
| 189 |
if(b!=null){ |
| 190 |
String[] s=b.split(","); |
| 191 |
for(String ss : s){ |
| 192 |
outd2.add(ss); |
| 193 |
} |
| 194 |
} |
| 195 |
}else if(a.equals("dot") || a.equals("outdot")){ |
| 196 |
outDot=b; |
| 197 |
}else if(a.equals("buildthreads") || a.equals("bt")){ |
| 198 |
BUILD_THREADS=Integer.parseInt(b); |
| 199 |
}else if(a.equals("processcontigs")){ |
| 200 |
processContigs=Parse.parseBoolean(b); |
| 201 |
}else if(a.equals("pop") || a.equalsIgnoreCase("popBubbles")){ |
| 202 |
popBubbles=Parse.parseBoolean(b); |
| 203 |
}else if(a.equalsIgnoreCase("bubblePasses")){ |
| 204 |
bubblePasses=Tools.max(1, Integer.parseInt(b)); |
| 205 |
}else if(a.equalsIgnoreCase("popDirect")){ |
| 206 |
BubblePopper.popDirect=Parse.parseBoolean(b); |
| 207 |
}else if(a.equalsIgnoreCase("popIndirect")){ |
| 208 |
BubblePopper.popIndirect=Parse.parseBoolean(b); |
| 209 |
}else if(a.equalsIgnoreCase("debranch")){ |
| 210 |
BubblePopper.debranch=Parse.parseBoolean(b); |
| 211 |
}else if(a.equals("etr") || a.equalsIgnoreCase("expandTandemRepeats")){ |
| 212 |
expandTandemRepeats=Parse.parseBoolean(b); |
| 213 |
assert(false) : "TODO"; |
| 214 |
}else if(a.equals("outkmers") || a.equals("outk") || a.equals("dump")){ |
| 215 |
outKmers=b; |
| 216 |
}else if(a.equals("mincounttodump")){ |
| 217 |
minToDump=Parse.parseIntKMG(b); |
| 218 |
}else if(a.equals("maxcounttodump")){ |
| 219 |
maxToDump=Parse.parseIntKMG(b); |
| 220 |
}else if(a.equals("hist") || a.equals("khist")){ |
| 221 |
outHist=b; |
| 222 |
}else if(a.equals("gchist")){ |
| 223 |
gcHist=Parse.parseBoolean(b); |
| 224 |
}else if(a.equals("ihist") || a.equals("inserthistogram")){ |
| 225 |
outInsert=b; |
| 226 |
}else if(a.equals("append") || a.equals("app")){ |
| 227 |
append=ReadStats.append=Parse.parseBoolean(b); |
| 228 |
}else if(a.equals("overwrite") || a.equals("ow")){ |
| 229 |
overwrite=Parse.parseBoolean(b); |
| 230 |
}else if(a.equals("mode")){ |
| 231 |
assert(b!=null) : "Bad parameter: "+arg; |
| 232 |
if(Tools.isDigit(b.charAt(0))){ |
| 233 |
processingMode=Parse.parseIntKMG(b); |
| 234 |
}else if(b.equalsIgnoreCase("contig")){ |
| 235 |
processingMode=contigMode; |
| 236 |
}else if(b.equalsIgnoreCase("extend")){ |
| 237 |
processingMode=extendMode; |
| 238 |
}else if(b.equalsIgnoreCase("correct") || b.equalsIgnoreCase("ecc") || b.equalsIgnoreCase("ecct")){ |
| 239 |
processingMode=correctMode; |
| 240 |
}else if(b.equalsIgnoreCase("insert")){ |
| 241 |
processingMode=insertMode; |
| 242 |
}else if(b.equalsIgnoreCase("discard") || b.equalsIgnoreCase("toss") || b.equalsIgnoreCase("filter")){ |
| 243 |
processingMode=discardMode; |
| 244 |
}else{ |
| 245 |
assert(false) : "Unknown mode "+b; |
| 246 |
} |
| 247 |
}else if(a.equals("ownership")){ |
| 248 |
if("auto".equalsIgnoreCase(b)){ |
| 249 |
setUseOwnership_=false; |
| 250 |
}else{ |
| 251 |
useOwnership_=Parse.parseBoolean(b); |
| 252 |
setUseOwnership_=true; |
| 253 |
} |
| 254 |
}else if(a.equals("showstats") || a.equals("stats")){ |
| 255 |
showStats=Parse.parseBoolean(b); |
| 256 |
}else if(a.equals("maxextension") || a.equals("maxe")){ |
| 257 |
extendLeft=extendRight=Parse.parseIntKMG(b); |
| 258 |
}else if(a.equals("extendright") || a.equals("er")){ |
| 259 |
extendRight=Parse.parseIntKMG(b); |
| 260 |
}else if(a.equals("extendleft") || a.equals("el")){ |
| 261 |
extendLeft=Parse.parseIntKMG(b); |
| 262 |
}else if(a.equals("extensionrollback") || a.equals("extendrollback")){ |
| 263 |
extensionRollback=Parse.parseIntKMG(b); |
| 264 |
}else if(a.equals("minextension") || a.equals("mine")){ |
| 265 |
minExtension=Parse.parseIntKMG(b); |
| 266 |
}else if(a.equals("maxcontiglength") || a.equals("maxcontig") || a.equals("maxlength") || a.equals("maxlen") || a.equals("maxc")){ |
| 267 |
maxContigLen=Parse.parseIntKMG(b); |
| 268 |
if(maxContigLen<0){maxContigLen=1000000000;} |
| 269 |
}else if(a.equals("mincontiglength") || a.equals("mincontiglen") || a.equals("mincontig") || a.equals("minc")){ |
| 270 |
if("auto".equalsIgnoreCase(b)){ |
| 271 |
minContigLen=-1; |
| 272 |
}else{ |
| 273 |
minContigLen=Parse.parseIntKMG(b); |
| 274 |
} |
| 275 |
}else if(a.equals("mincoverage") || a.equals("mincov")){ |
| 276 |
minCoverage=Float.parseFloat(b); |
| 277 |
}else if(a.equals("maxcoverage") || a.equals("maxcov")){ |
| 278 |
if(b.equalsIgnoreCase("inf")){maxCoverage=Float.MAX_VALUE;} |
| 279 |
else{maxCoverage=Float.parseFloat(b);} |
| 280 |
}else if(a.equals("branchlower") || a.equals("branchlowerconst") || a.equals("blc")){ |
| 281 |
branchLowerConst=Parse.parseIntKMG(b); |
| 282 |
}else if(a.equals("branchmult2") || a.equals("bm2")){ |
| 283 |
branchMult2=Parse.parseIntKMG(b); |
| 284 |
}else if(a.equals("branchmult") || a.equals("branchmult1") || a.equals("bm1")){ |
| 285 |
branchMult1=Parse.parseIntKMG(b); |
| 286 |
}else if(a.equals("mincount") || a.equals("mindepth") || a.equals("min")){ |
| 287 |
minCountSeed=minCountExtend=Parse.parseIntKMG(b); |
| 288 |
}else if(a.equals("mindepthseed") || a.equals("mds") || a.equals("mincountseed") || a.equals("mcs")){ |
| 289 |
minCountSeed=Parse.parseIntKMG(b); |
| 290 |
}else if(a.equals("mindepthextend") || a.equals("mde") || a.equals("mincountextend") || a.equals("mce")){ |
| 291 |
minCountExtend=Parse.parseIntKMG(b); |
| 292 |
}else if(a.equals("mincountretain") || a.equals("mincr") || a.equals("mindepthretain") || a.equals("mindr")){ |
| 293 |
kmerRangeMin=Parse.parseIntKMG(b); |
| 294 |
}else if(a.equals("maxcountretain") || a.equals("maxcr") || a.equals("maxdepthretain") || a.equals("maxdr")){ |
| 295 |
kmerRangeMax=Parse.parseIntKMG(b); |
| 296 |
}else if(a.equals("contigpasses")){ |
| 297 |
contigPasses=Parse.parseIntKMG(b); |
| 298 |
}else if(a.equals("contigpassmult")){ |
| 299 |
contigPassMult=Double.parseDouble(b); |
| 300 |
assert(contigPassMult>=1) : "contigPassMult must be at least 1."; |
| 301 |
}else if(a.equals("threads") || a.equals("t")){ |
| 302 |
Shared.setThreads(b); |
| 303 |
}else if(a.equals("showspeed") || a.equals("ss")){ |
| 304 |
showSpeed=Parse.parseBoolean(b); |
| 305 |
}else if(a.equals("verbose")){ |
| 306 |
|
| 307 |
verbose=Parse.parseBoolean(b); |
| 308 |
}else if(a.equals("verbose2")){ |
| 309 |
|
| 310 |
verbose2=Parse.parseBoolean(b); |
| 311 |
}else if(a.equals("ordered")){ |
| 312 |
ordered=Parse.parseBoolean(b); |
| 313 |
}else if(a.equals("reads") || a.startsWith("maxreads")){ |
| 314 |
maxReads=Parse.parseKMG(b); |
| 315 |
}else if(a.equals("histcolumns")){ |
| 316 |
histColumns=Parse.parseIntKMG(b); |
| 317 |
}else if(a.equals("histmax")){ |
| 318 |
histMax=Parse.parseIntKMG(b); |
| 319 |
}else if(a.equals("histheader")){ |
| 320 |
histHeader=Parse.parseBoolean(b); |
| 321 |
}else if(a.equals("nzo") || a.equals("nonzeroonly")){ |
| 322 |
histZeros=!Parse.parseBoolean(b); |
| 323 |
}else if(a.equals("ilb") || a.equals("ignoreleftbranches") || a.equals("ignoreleftjunctions") || a.equals("ibb") || a.equals("ignorebackbranches")){ |
| 324 |
extendThroughLeftJunctions=Parse.parseBoolean(b); |
| 325 |
}else if(a.equals("ibo") || a.equals("ignorebadowner")){ |
| 326 |
IGNORE_BAD_OWNER=Parse.parseBoolean(b); |
| 327 |
}else if(a.equals("tad2") || a.equals("tadpole2")){ |
| 328 |
FORCE_TADPOLE2=Parse.parseBoolean(b); |
| 329 |
} |
| 330 |
|
| 331 |
else if(a.equals("maskcore") || a.equals("coremask")){ |
| 332 |
AbstractKmerTableSet.MASK_CORE=Kmer.MASK_CORE=Parse.parseBoolean(b); |
| 333 |
}else if(a.equals("fillfast") || a.equals("fastfill")){ |
| 334 |
AbstractKmerTableSet.FAST_FILL=Parse.parseBoolean(b); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
else if(a.equals("shaverinse") || a.equals("shaveandrinse") || a.equals("wash") || a.equals("sr")){ |
| 339 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 340 |
removeDeadEnds=removeBubbles=Parse.parseBoolean(b); |
| 341 |
}else{ |
| 342 |
maxShaveDepth=Integer.parseInt(b); |
| 343 |
removeDeadEnds=removeBubbles=(maxShaveDepth>0); |
| 344 |
} |
| 345 |
setShave=setRinse=true; |
| 346 |
}else if(a.equals("shave") || a.equals("removedeadends")){ |
| 347 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 348 |
removeDeadEnds=Parse.parseBoolean(b); |
| 349 |
}else{ |
| 350 |
maxShaveDepth=Integer.parseInt(b); |
| 351 |
removeDeadEnds=(maxShaveDepth>0); |
| 352 |
} |
| 353 |
setShave=true; |
| 354 |
}else if(a.equals("rinse") || a.equals("shampoo") || a.equals("removebubbles")){ |
| 355 |
removeBubbles=Parse.parseBoolean(b); |
| 356 |
setRinse=true; |
| 357 |
}else if(a.equals("maxshavedepth") || a.equals("shavedepth") || a.equals("msd")){ |
| 358 |
maxShaveDepth=Integer.parseInt(b); |
| 359 |
}else if(a.equals("shavediscardlength") || a.equals("shavelength") || a.equals("discardlength") || a.equals("sdl")){ |
| 360 |
shaveDiscardLen=Integer.parseInt(b); |
| 361 |
}else if(a.equals("shaveexploredistance") || a.equals("shaveexploredist") || a.equals("exploredist") || a.equals("sed")){ |
| 362 |
shaveExploreDist=Integer.parseInt(b); |
| 363 |
}else if(a.equals("printeventcounts")){ |
| 364 |
Shaver.printEventCounts=Parse.parseBoolean(b); |
| 365 |
}else if(a.equalsIgnoreCase("startFromHighCounts")){ |
| 366 |
Shaver.startFromHighCounts=Parse.parseBoolean(b); |
| 367 |
}else if(a.equalsIgnoreCase("shaveFast") || a.equalsIgnoreCase("fastShave")){ |
| 368 |
Shaver.shaveFast=Parse.parseBoolean(b); |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
else if(a.equals("tossjunk") || a.equals("tj")){ |
| 374 |
tossJunk=Parse.parseBoolean(b); |
| 375 |
}else if(a.equals("tossdepth") || a.equals("discarddepth")){ |
| 376 |
discardLowDepthReads=Integer.parseInt(b); |
| 377 |
}else if(a.equals("lowdepthfraction") || a.equals("ldf") || a.equals("lcf") || a.equals("lddf")){ |
| 378 |
lowDepthDiscardFraction=Float.parseFloat(b); |
| 379 |
}else if(a.equals("requirebothbad") || a.equals("rbb")){ |
| 380 |
requireBothBad=Parse.parseBoolean(b); |
| 381 |
}else if(a.equals("tossuncorrectable") || a.equals("tu")){ |
| 382 |
discardUncorrectable=Parse.parseBoolean(b); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
else if(a.equals("ecctail") || a.equals("eccright") || a.equals("tail")){ |
| 387 |
ECC_TAIL=Parse.parseBoolean(b); |
| 388 |
}else if(a.equals("pincer") || a.equals("eccpincer")){ |
| 389 |
ECC_PINCER=Parse.parseBoolean(b); |
| 390 |
}else if(a.equals("reassemble") || a.equals("eccreassemble")){ |
| 391 |
ECC_REASSEMBLE=Parse.parseBoolean(b); |
| 392 |
}else if(a.equals("rollback") || a.equals("eccrollback")){ |
| 393 |
ECC_ROLLBACK=Parse.parseBoolean(b); |
| 394 |
}else if(a.equals("bidirectional") || a.equals("requirebidirectional") || a.equals("eccbidirectional") || a.equals("rbi") || a.equals("rb")){ |
| 395 |
ECC_REQUIRE_BIDIRECTIONAL=Parse.parseBoolean(b); |
| 396 |
}else if(a.equals("eccall") || a.equals("eccfull")){ |
| 397 |
ECC_ALL=Parse.parseBoolean(b); |
| 398 |
}else if(a.equals("aecc") || a.equals("aec") || a.equals("aggressive")){ |
| 399 |
ECC_AGGRESSIVE=Parse.parseBoolean(b); |
| 400 |
if(ECC_AGGRESSIVE){ |
| 401 |
ECC_CONSERVATIVE=false; |
| 402 |
ecc_=setEcc_=true; |
| 403 |
} |
| 404 |
}else if(a.equals("cecc") || a.equals("cec") || a.equals("conservative")){ |
| 405 |
ECC_CONSERVATIVE=Parse.parseBoolean(b); |
| 406 |
if(ECC_CONSERVATIVE){ |
| 407 |
ECC_AGGRESSIVE=false; |
| 408 |
ecc_=setEcc_=true; |
| 409 |
} |
| 410 |
}else if(a.equals("ecc") || a.equals("ecct")){ |
| 411 |
ecc_=Parse.parseBoolean(b); |
| 412 |
setEcc_=true; |
| 413 |
}else if(a.equals("ecco")){ |
| 414 |
ecco_=Parse.parseBoolean(b); |
| 415 |
}else if(a.equals("merge")){ |
| 416 |
merge_=Parse.parseBoolean(b); |
| 417 |
}else if(a.equals("testmerge")){ |
| 418 |
testMerge_=Parse.parseBoolean(b); |
| 419 |
}else if(a.equals("testmergewidth")){ |
| 420 |
testMergeWidth=Integer.parseInt(b); |
| 421 |
}else if(a.equals("testmergethresh")){ |
| 422 |
testMergeThresh=Integer.parseInt(b); |
| 423 |
}else if(a.equals("testmergemult")){ |
| 424 |
testMergeMult=Parse.parseKMG(b); |
| 425 |
}else if(a.equals("vstrict")){ |
| 426 |
vstrict_=Parse.parseBoolean(b); |
| 427 |
}else if(a.equals("ep") || a.equals("errorpath")){ |
| 428 |
errorPath=Integer.parseInt(b); |
| 429 |
}else if(a.equals("em1") || a.equals("errormult1")){ |
| 430 |
errorMult1=Float.parseFloat(b); |
| 431 |
}else if(a.equals("em2") || a.equals("errormult2")){ |
| 432 |
errorMult2=Float.parseFloat(b); |
| 433 |
}else if(a.equals("emq") || a.equals("errormultqfactor")){ |
| 434 |
errorMultQFactor=Float.parseFloat(b); |
| 435 |
}else if(a.equals("elc") || a.equals("errorlowerconst")){ |
| 436 |
errorLowerConst=Integer.parseInt(b); |
| 437 |
}else if(a.equals("mcc") || a.equals("mincountcorrect")){ |
| 438 |
minCountCorrect=Integer.parseInt(b); |
| 439 |
}else if(a.equals("psc") || a.equals("pathsimilarityconstant")){ |
| 440 |
pathSimilarityConstant=Integer.parseInt(b); |
| 441 |
}else if(a.equals("psf") || a.equals("pathsimilarityfraction")){ |
| 442 |
pathSimilarityFraction=Float.parseFloat(b); |
| 443 |
}else if(a.equals("eer") || a.equals("errorextensionreassemble")){ |
| 444 |
errorExtensionReassemble=Integer.parseInt(b); |
| 445 |
}else if(a.equals("eep") || a.equals("errorextensionpincer")){ |
| 446 |
errorExtensionPincer=Integer.parseInt(b); |
| 447 |
}else if(a.equals("eet") || a.equals("errorextensiontail")){ |
| 448 |
errorExtensionTail=Integer.parseInt(b); |
| 449 |
}else if(a.equals("dz") || a.equals("deadzone")){ |
| 450 |
deadZone=Integer.parseInt(b); |
| 451 |
}else if(a.equals("window") || a.equals("windowlen") || a.equals("w")){ |
| 452 |
windowLen=Integer.parseInt(b); |
| 453 |
}else if(a.equals("windowcount") || a.equals("windowlimit") || a.equals("wc")){ |
| 454 |
windowCount=Integer.parseInt(b); |
| 455 |
}else if(a.equals("windowcounthq") || a.equals("windowlimithq") || a.equals("wchq")){ |
| 456 |
windowCountHQ=Integer.parseInt(b); |
| 457 |
}else if(a.equals("hqthresh") || a.equals("windowhqthresh") || a.equals("hqt")){ |
| 458 |
windowHQThresh=(byte)Integer.parseInt(b); |
| 459 |
}else if(a.equals("qualsum") || a.equals("windowqualsum") || a.equals("qs")){ |
| 460 |
windowQualSum=Integer.parseInt(b); |
| 461 |
} |
| 462 |
|
| 463 |
else if(a.equals("mbb") || a.equals("markbad") || a.equals("markbadbases")){ |
| 464 |
if(b==null){b="1";} |
| 465 |
MARK_BAD_BASES=Integer.parseInt(b); |
| 466 |
}else if(a.equals("mdo") || a.equals("markdeltaonly")){ |
| 467 |
MARK_DELTA_ONLY=Parse.parseBoolean(b); |
| 468 |
}else if(a.equals("meo") || a.equals("markerrorreadsonly")){ |
| 469 |
MARK_ERROR_READS_ONLY=Parse.parseBoolean(b); |
| 470 |
}else if(a.equals("mq") || a.equals("markquality")){ |
| 471 |
MARK_QUALITY=(byte)Integer.parseInt(b); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
else if(a.equals("trim") || a.equals("trimends")){ |
| 476 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 477 |
if("auto".equalsIgnoreCase(b)){trimEnds=-1;} |
| 478 |
else{trimEnds=Parse.parseBoolean(b) ? -1 : 0;} |
| 479 |
}else{ |
| 480 |
trimEnds=Integer.parseInt(b); |
| 481 |
} |
| 482 |
}else if(a.equals("trimcircular") || a.equals("trimloop") || a.equals("trimlooploop")){ |
| 483 |
trimCircular=Parse.parseBoolean(b); |
| 484 |
} |
| 485 |
|
| 486 |
else if(a.equalsIgnoreCase("sortbuffers") || a.equalsIgnoreCase("sortbuffer")){ |
| 487 |
HashBuffer.SORT_BUFFERS=Parse.parseBoolean(b); |
| 488 |
} |
| 489 |
|
| 490 |
else if(Parser.parseCommonStatic(arg, a, b)){ |
| 491 |
|
| 492 |
}else if(Parser.parseZip(arg, a, b)){ |
| 493 |
|
| 494 |
}else if(Parser.parseQuality(arg, a, b)){ |
| 495 |
|
| 496 |
}else if(Parser.parseFasta(arg, a, b)){ |
| 497 |
|
| 498 |
}else if(parser.parseInterleaved(arg, a, b)){ |
| 499 |
|
| 500 |
}else if(parser.parseTrim(arg, a, b)){ |
| 501 |
|
| 502 |
} |
| 503 |
|
| 504 |
else if(a.equals("prefilter")){ |
| 505 |
if(b==null){prefilter=2;} |
| 506 |
else if(Character.isLetter(b.charAt(0))){prefilter=Parse.parseBoolean(b) ? 2 : 0;} |
| 507 |
else{prefilter=Integer.parseInt(b);} |
| 508 |
}else if(KmerTableSetU.isValidArgument(a)){ |
| 509 |
|
| 510 |
}else{ |
| 511 |
throw new RuntimeException("Unknown parameter "+args[i]); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
kmerRangeMin=Tools.max(prefilter+1, kmerRangeMin); |
| 516 |
|
| 517 |
if(outDot!=null || popBubbles){processContigs=true;} |
| 518 |
|
| 519 |
if(ECC_AGGRESSIVE){ |
| 520 |
ECC_REQUIRE_BIDIRECTIONAL=false; |
| 521 |
errorExtensionReassemble=0; |
| 522 |
errorExtensionPincer=3; |
| 523 |
errorExtensionTail=4; |
| 524 |
errorMult1=Tools.max(4, errorMult1*0.6f); |
| 525 |
minCountCorrect=Tools.min(minCountCorrect, 3); |
| 526 |
deadZone=0; |
| 527 |
pathSimilarityFraction*=1.4f; |
| 528 |
windowCount=Tools.max(windowCount, 6); |
| 529 |
windowQualSum=Tools.min(windowQualSum, 65); |
| 530 |
windowLen=Tools.min(windowLen, 12); |
| 531 |
|
| 532 |
ECC_REQUIRE_BIDIRECTIONAL=false; |
| 533 |
}else if(ECC_CONSERVATIVE){ |
| 534 |
errorExtensionReassemble+=2; |
| 535 |
errorExtensionPincer+=2; |
| 536 |
errorExtensionTail+=2; |
| 537 |
errorMult1=(errorMult1*1.2f); |
| 538 |
minCountCorrect=Tools.max(minCountCorrect, 4); |
| 539 |
deadZone=Tools.max(deadZone+1, 5); |
| 540 |
pathSimilarityFraction*=0.8f; |
| 541 |
windowLen=Tools.max(windowLen, 12); |
| 542 |
windowCount=Tools.min(windowCount, 4); |
| 543 |
windowQualSum=Tools.min(windowQualSum, 65); |
| 544 |
|
| 545 |
ECC_REQUIRE_BIDIRECTIONAL=true; |
| 546 |
ECC_ROLLBACK=true; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
if(trimEnds<0){ |
| 552 |
trimEnds=kbig/2; |
| 553 |
} |
| 554 |
if(minContigLen<0){ |
| 555 |
minContigLen=Tools.max(124, 2*kbig); |
| 556 |
} |
| 557 |
|
| 558 |
if(verbose){ |
| 559 |
BubblePopper.verbose=true; |
| 560 |
|
| 561 |
|
| 562 |
} |
| 563 |
THREADS=Shared.threads(); |
| 564 |
|
| 565 |
assert(kmerRangeMax>=kmerRangeMin) : "kmerRangeMax must be at least kmerRangeMin: "+kmerRangeMax+", "+kmerRangeMin; |
| 566 |
|
| 567 |
if(processingMode<0){ |
| 568 |
if(ecc_ || discardUncorrectable){ |
| 569 |
processingMode=correctMode; |
| 570 |
outstream.println("Switching to correct mode because ecc=t."); |
| 571 |
}else if(extendLeft>0 || extendRight>0){ |
| 572 |
processingMode=extendMode; |
| 573 |
outstream.println("Switching to extend mode because an extend flag was set."); |
| 574 |
}else if(tossJunk || discardLowDepthReads>0){ |
| 575 |
processingMode=discardMode; |
| 576 |
outstream.println("Switching to discard mode because a discard flag was set."); |
| 577 |
}else{ |
| 578 |
processingMode=contigMode; |
| 579 |
|
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
if(processingMode==extendMode || processingMode==correctMode || processingMode==discardMode){ |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
if(processingMode==extendMode){ |
| 596 |
if(extendLeft==-1){extendLeft=100;} |
| 597 |
if(extendRight==-1){extendRight=100;} |
| 598 |
}else if(processingMode==correctMode){ |
| 599 |
|
| 600 |
if(!setEcc_){ecc_=true;} |
| 601 |
}else if(processingMode==discardMode){ |
| 602 |
extendLeft=extendRight=0; |
| 603 |
if(!setEcc_){ecc_=false;} |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
{ |
| 608 |
Parser.parseQuality("","",""); |
| 609 |
Parser.processQuality(); |
| 610 |
} |
| 611 |
|
| 612 |
if(setUseOwnership_){ |
| 613 |
useOwnership=useOwnership_; |
| 614 |
}else{ |
| 615 |
useOwnership=(processingMode==contigMode || removeBubbles || removeDeadEnds); |
| 616 |
} |
| 617 |
|
| 618 |
final int extraBytesPerKmer; |
| 619 |
{ |
| 620 |
int x=0; |
| 621 |
if(useOwnership){x+=4;} |
| 622 |
if(processingMode==correctMode || processingMode==discardMode){} |
| 623 |
else if(processingMode==contigMode || processingMode==extendMode){x+=1;} |
| 624 |
extraBytesPerKmer=x; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
ecc=ecc_; |
| 630 |
ecco=ecco_; |
| 631 |
merge=merge_; |
| 632 |
testMerge=testMerge_; |
| 633 |
vstrict=vstrict_; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
assert(FastaReadInputStream.settingsOK()); |
| 638 |
|
| 639 |
for(int i=0; i<in1.size(); i++){ |
| 640 |
String s=in1.get(i); |
| 641 |
if(s!=null && s.contains("#") && !new File(s).exists()){ |
| 642 |
int pound=s.lastIndexOf('#'); |
| 643 |
String a=s.substring(0, pound); |
| 644 |
String b=s.substring(pound+1); |
| 645 |
in1.set(i, a+1+b); |
| 646 |
in2.add(a+2+b); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
for(int i=0; i<out1.size(); i++){ |
| 651 |
String s=out1.get(i); |
| 652 |
if(s!=null && s.contains("#")){ |
| 653 |
int pound=s.lastIndexOf('#'); |
| 654 |
String a=s.substring(0, pound); |
| 655 |
String b=s.substring(pound+1); |
| 656 |
out1.set(i, a+1+b); |
| 657 |
out2.add(a+2+b); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
for(int i=0; i<outd1.size(); i++){ |
| 662 |
String s=outd1.get(i); |
| 663 |
if(s!=null && s.contains("#")){ |
| 664 |
int pound=s.lastIndexOf('#'); |
| 665 |
String a=s.substring(0, pound); |
| 666 |
String b=s.substring(pound+1); |
| 667 |
outd1.set(i, a+1+b); |
| 668 |
outd2.add(a+2+b); |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
nextTable=new AtomicInteger[contigPasses]; |
| 673 |
nextVictims=new AtomicInteger[contigPasses]; |
| 674 |
for(int i=0; i<contigPasses; i++){ |
| 675 |
nextTable[i]=new AtomicInteger(0); |
| 676 |
nextVictims[i]=new AtomicInteger(0); |
| 677 |
} |
| 678 |
|
| 679 |
if(!Tools.testOutputFiles(overwrite, append, false, outKmers, outHist)){ |
| 680 |
throw new RuntimeException("\nCan't write to some output files; overwrite="+overwrite+"\n"); |
| 681 |
} |
| 682 |
if(!Tools.testOutputFiles(overwrite, append, false, out1, out2)){ |
| 683 |
throw new RuntimeException("\nCan't write to some output files; overwrite="+overwrite+"\n"); |
| 684 |
} |
| 685 |
in1=Tools.fixExtension(in1); |
| 686 |
in2=Tools.fixExtension(in2); |
| 687 |
assert(!in1.isEmpty()) : "Requires at least one input file."; |
| 688 |
if(!Tools.testInputFiles(true, true, in1, in2)){ |
| 689 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 690 |
} |
| 691 |
assert(THREADS>0); |
| 692 |
outstream.println("Using "+THREADS+" threads."); |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
public final void process(Timer t){ |
| 702 |
|
| 703 |
|
| 704 |
Tools.testOutputFiles(overwrite, append, false, outKmers, outHist); |
| 705 |
|
| 706 |
|
| 707 |
process2(processingMode); |
| 708 |
|
| 709 |
if(THREADS>1 && outHist!=null && outKmers!=null){ |
| 710 |
Timer tout=new Timer(); |
| 711 |
tout.start(); |
| 712 |
Thread a=new DumpKmersThread(); |
| 713 |
Thread b=new MakeKhistThread(); |
| 714 |
a.start(); |
| 715 |
b.start(); |
| 716 |
while(a.getState()!=Thread.State.TERMINATED){ |
| 717 |
try { |
| 718 |
a.join(); |
| 719 |
} catch (InterruptedException e) { |
| 720 |
|
| 721 |
e.printStackTrace(); |
| 722 |
} |
| 723 |
} |
| 724 |
while(b.getState()!=Thread.State.TERMINATED){ |
| 725 |
try { |
| 726 |
b.join(); |
| 727 |
} catch (InterruptedException e) { |
| 728 |
|
| 729 |
e.printStackTrace(); |
| 730 |
} |
| 731 |
} |
| 732 |
tout.stop(); |
| 733 |
outstream.println("Write Time: \t"+tout); |
| 734 |
}else{ |
| 735 |
if(outHist!=null){ |
| 736 |
makeKhist(); |
| 737 |
} |
| 738 |
if(outKmers!=null){ |
| 739 |
dumpKmersAsText(); |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
clearData(); |
| 744 |
|
| 745 |
|
| 746 |
t.stop(); |
| 747 |
|
| 748 |
|
| 749 |
if(showSpeed){ |
| 750 |
outstream.println("\nTotal Time: \t"+t); |
| 751 |
|
| 752 |
if(processingMode==extendMode || processingMode==correctMode || processingMode==discardMode){ |
| 753 |
outstream.println(Tools.readsBasesProcessed(t.elapsed, readsIn, basesIn, 8)); |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
{ |
| 758 |
String outContigs=out1.isEmpty() ? null : out1.get(0); |
| 759 |
if(showStats && outContigs!=null && processingMode==contigMode && FileFormat.isFastaExt(ReadWrite.rawExtension(outContigs)) && !FileFormat.isStdio(outContigs)){ |
| 760 |
outstream.println(); |
| 761 |
jgi.AssemblyStats2.main(new String[] {"in="+outContigs, "printextended"}); |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
if(errorState){ |
| 767 |
throw new RuntimeException(getClass().getSimpleName()+" terminated in an error state; the output may be corrupt."); |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
abstract void makeKhist(); |
| 772 |
abstract void dumpKmersAsText(); |
| 773 |
public abstract long loadKmers(Timer t); |
| 774 |
|
| 775 |
public final void clearData(){ |
| 776 |
allContigs=null; |
| 777 |
tables().clear(); |
| 778 |
} |
| 779 |
|
| 780 |
public final void process2(int mode){ |
| 781 |
|
| 782 |
|
| 783 |
Timer t=new Timer(); |
| 784 |
|
| 785 |
|
| 786 |
outstream.println("\nLoading kmers.\n"); |
| 787 |
loadKmers(t); |
| 788 |
|
| 789 |
t.stop(); |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
t.start(); |
| 796 |
|
| 797 |
if(kmerRangeMin>1 || kmerRangeMax<Integer.MAX_VALUE){ |
| 798 |
AbstractRemoveThread.process(THREADS, kmerRangeMin, kmerRangeMax, tables(), true); |
| 799 |
} |
| 800 |
|
| 801 |
shaveAndRinse(t, removeDeadEnds, removeBubbles, true); |
| 802 |
|
| 803 |
if(mode==extendMode || mode==correctMode || mode==discardMode){ |
| 804 |
outstream.println("\nExtending/error-correcting/discarding.\n"); |
| 805 |
|
| 806 |
final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR; |
| 807 |
Read.VALIDATE_IN_CONSTRUCTOR=false; |
| 808 |
extendReads(); |
| 809 |
Read.VALIDATE_IN_CONSTRUCTOR=vic; |
| 810 |
|
| 811 |
if(DISPLAY_PROGRESS){ |
| 812 |
outstream.println("\nAfter extending reads:"); |
| 813 |
Shared.printMemory(); |
| 814 |
outstream.println(); |
| 815 |
} |
| 816 |
|
| 817 |
t.stop(); |
| 818 |
|
| 819 |
outstream.println("Input: \t"+readsIn+" reads \t\t"+basesIn+" bases."); |
| 820 |
outstream.println("Output: \t"+readsIn+" reads \t\t"+(basesIn+basesExtended)+" bases."); |
| 821 |
if(extendLeft>0 || extendRight>0){ |
| 822 |
outstream.println("Bases extended: \t"+basesExtended); |
| 823 |
outstream.println("Reads extended: \t"+readsExtended+Tools.format(" \t(%.2f%%)", readsExtended*100.0/readsIn)); |
| 824 |
} |
| 825 |
if(ecc){ |
| 826 |
long partial=(readsCorrected-readsFullyCorrected); |
| 827 |
outstream.println("Errors detected: \t"+(basesDetected+basesCorrectedEcco)); |
| 828 |
{ |
| 829 |
final long corrected=(basesCorrectedTail+basesCorrectedPincer+basesCorrectedReassemble+basesCorrectedEcco); |
| 830 |
StringBuilder sb=new StringBuilder(); |
| 831 |
sb.append("Errors corrected: \t"+Tools.padRight(corrected, 7)+" \t("); |
| 832 |
|
| 833 |
String comma=""; |
| 834 |
if(ECC_PINCER){ |
| 835 |
sb.append(comma).append(basesCorrectedPincer+" pincer"); |
| 836 |
comma=", "; |
| 837 |
} |
| 838 |
if(ECC_TAIL || ECC_ALL){ |
| 839 |
sb.append(comma).append(basesCorrectedTail+" tail"); |
| 840 |
comma=", "; |
| 841 |
} |
| 842 |
if(ECC_REASSEMBLE){ |
| 843 |
sb.append(comma).append(basesCorrectedReassemble+" reassemble"); |
| 844 |
comma=", "; |
| 845 |
} |
| 846 |
if(ecco || merge){ |
| 847 |
sb.append(comma).append(basesCorrectedEcco+" overlap"); |
| 848 |
comma=", "; |
| 849 |
} |
| 850 |
|
| 851 |
sb.append(")"); |
| 852 |
outstream.println(sb); |
| 853 |
} |
| 854 |
|
| 855 |
if(ecco || merge){outstream.println("Reads merged: \t"+Tools.padRight(readsMerged, 7)+ |
| 856 |
Tools.format(" \t(%.2f%%)", readsMerged*200.0/readsIn));} |
| 857 |
outstream.println("Reads with errors detected: \t"+Tools.padRight(readsDetected, 7)+ |
| 858 |
Tools.format(" \t(%.2f%%)", readsDetected*100.0/readsIn)); |
| 859 |
outstream.println("Reads fully corrected: \t"+Tools.padRight(readsFullyCorrected, 7)+ |
| 860 |
Tools.format(" \t(%.2f%% of detected)", readsFullyCorrected*100.0/readsDetected)); |
| 861 |
outstream.println("Reads partly corrected: \t"+Tools.padRight(partial, 7)+ |
| 862 |
Tools.format(" \t(%.2f%% of detected)", partial*100.0/readsDetected)); |
| 863 |
if(ECC_ROLLBACK || rollbacks>0){ |
| 864 |
outstream.println("Rollbacks: \t"+Tools.padRight(rollbacks, 7)+ |
| 865 |
Tools.format(" \t(%.2f%% of detected)", rollbacks*100.0/readsDetected)); |
| 866 |
} |
| 867 |
|
| 868 |
} |
| 869 |
if(tossJunk || discardLowDepthReads>=0 || discardUncorrectable){ |
| 870 |
outstream.println("Reads discarded: \t"+readsDiscarded+Tools.format(" \t(%.2f%%)", readsDiscarded*100.0/readsIn)); |
| 871 |
outstream.println("Bases discarded: \t"+basesDiscarded+Tools.format(" \t(%.2f%%)", basesDiscarded*100.0/basesIn)); |
| 872 |
} |
| 873 |
if(MARK_BAD_BASES>0){ |
| 874 |
outstream.println("Reads marked: \t"+readsMarked+Tools.format(" \t(%.2f%%)", readsMarked*100.0/readsIn)); |
| 875 |
outstream.println("Bases marked: \t"+basesMarked+Tools.format(" \t(%.2f%%)", basesMarked*100.0/basesIn)); |
| 876 |
} |
| 877 |
|
| 878 |
outstream.println("Extend/error-correct time: \t"+t); |
| 879 |
}else{ |
| 880 |
|
| 881 |
outstream.println("\nBuilding contigs.\n"); |
| 882 |
buildContigs(mode); |
| 883 |
|
| 884 |
if(DISPLAY_PROGRESS){ |
| 885 |
outstream.println("\nAfter building contigs:"); |
| 886 |
Shared.printMemory(); |
| 887 |
outstream.println(); |
| 888 |
} |
| 889 |
|
| 890 |
t.stop(); |
| 891 |
|
| 892 |
if(readsIn>0){outstream.println("Input: \t"+readsIn+" reads \t\t"+basesIn+" bases.");} |
| 893 |
outstream.println("Bases generated: \t"+basesBuilt); |
| 894 |
outstream.println("Contigs generated: \t"+contigsBuilt); |
| 895 |
outstream.println("Longest contig: \t"+longestContig); |
| 896 |
if(popBubbles){outstream.println("Bubbles popped: \t"+bubblesPopped);} |
| 897 |
|
| 898 |
outstream.println("Contig-building time: \t"+t); |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
public final long shaveAndRinse(Timer t, boolean shave, boolean rinse, boolean print){ |
| 908 |
long removed=0; |
| 909 |
if(shave || rinse){ |
| 910 |
|
| 911 |
if(print){ |
| 912 |
if(rinse && shave){ |
| 913 |
outstream.println("\nRemoving dead ends and error bubbles."); |
| 914 |
}else if(shave){ |
| 915 |
outstream.println("\nRemoving dead ends."); |
| 916 |
}else if(rinse){ |
| 917 |
outstream.println("\nRemoving error bubbles."); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
removed=shave(shave, rinse); |
| 922 |
t.stop(); |
| 923 |
|
| 924 |
if(print){ |
| 925 |
outstream.println("Kmers removed: \t"+removed); |
| 926 |
outstream.println("Removal time: \t"+t); |
| 927 |
} |
| 928 |
|
| 929 |
t.start(); |
| 930 |
} |
| 931 |
return removed; |
| 932 |
} |
| 933 |
|
| 934 |
abstract long shave(boolean shave, boolean rinse); |
| 935 |
abstract void initializeOwnership(); |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
private final void buildContigs(final int mode){ |
| 941 |
|
| 942 |
if(mode==contigMode){ |
| 943 |
allContigs=new ArrayList<Contig>(); |
| 944 |
allInserts=null; |
| 945 |
|
| 946 |
if(useOwnership){ |
| 947 |
Timer t=new Timer(outstream, true); |
| 948 |
t.start("Initializing ownership."); |
| 949 |
initializeOwnership(); |
| 950 |
t.stop("Time: "); |
| 951 |
} |
| 952 |
|
| 953 |
}else if(mode==insertMode){ |
| 954 |
allContigs=null; |
| 955 |
allInserts=new LongList(); |
| 956 |
}else if(mode==extendMode){ |
| 957 |
throw new RuntimeException("extendMode: TODO"); |
| 958 |
}else{ |
| 959 |
throw new RuntimeException("Unknown mode "+mode); |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
final ConcurrentReadInputStream[] crisa=(mode==contigMode ? null : makeCrisArray(in1, in2)); |
| 964 |
|
| 965 |
runBuildThreads(mode, crisa); |
| 966 |
|
| 967 |
|
| 968 |
if(crisa!=null){ |
| 969 |
for(ConcurrentReadInputStream cris : crisa){ |
| 970 |
errorState|=ReadWrite.closeStreams(cris); |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
if(allContigs!=null){ |
| 975 |
ContigLengthComparator.comparator.setAscending(false); |
| 976 |
Shared.sort(allContigs, ContigLengthComparator.comparator); |
| 977 |
if(processContigs){ |
| 978 |
processContigs(); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
if(outInsert!=null){ |
| 983 |
FileFormat ff=FileFormat.testOutput(outInsert, FileFormat.TEXT, 0, 0, true, overwrite, append, false); |
| 984 |
TextStreamWriter tsw=new TextStreamWriter(ff); |
| 985 |
tsw.start(); |
| 986 |
for(int i=0; i<allInserts.size; i++){ |
| 987 |
long count=allInserts.get(i); |
| 988 |
if(count>0 || histZeros){ |
| 989 |
tsw.print(i+"\t"+count+"\n"); |
| 990 |
} |
| 991 |
} |
| 992 |
errorState|=tsw.poisonAndWait(); |
| 993 |
} |
| 994 |
|
| 995 |
String outContigs=out1.isEmpty() ? null : out1.get(0); |
| 996 |
if(outContigs!=null){ |
| 997 |
FileFormat ff=FileFormat.testOutput(outContigs, FileFormat.FA, 0, 0, true, overwrite, append, false); |
| 998 |
|
| 999 |
|
| 1000 |
ByteStreamWriter bsw=new ByteStreamWriter(ff); |
| 1001 |
bsw.start(); |
| 1002 |
if(allContigs!=null){ |
| 1003 |
for(int i=0; i<allContigs.size(); i++){ |
| 1004 |
Contig r=allContigs.get(i); |
| 1005 |
if(r.length()>=minContigLen){ |
| 1006 |
bsw.println(r); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
errorState|=bsw.poisonAndWait(); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
|
| 1014 |
void runBuildThreads(int mode, ConcurrentReadInputStream[] crisa){ |
| 1015 |
Timer t=new Timer(outstream, true); |
| 1016 |
|
| 1017 |
if(BUILD_THREADS<1){BUILD_THREADS=THREADS;} |
| 1018 |
|
| 1019 |
|
| 1020 |
ArrayList<AbstractBuildThread> alpt=new ArrayList<AbstractBuildThread>(BUILD_THREADS); |
| 1021 |
for(int i=0; i<BUILD_THREADS; i++){alpt.add(makeBuildThread(i, mode, crisa));} |
| 1022 |
for(AbstractBuildThread pt : alpt){pt.start();} |
| 1023 |
|
| 1024 |
|
| 1025 |
for(AbstractBuildThread pt : alpt){ |
| 1026 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 1027 |
try { |
| 1028 |
pt.join(); |
| 1029 |
} catch (InterruptedException e) { |
| 1030 |
|
| 1031 |
e.printStackTrace(); |
| 1032 |
} |
| 1033 |
} |
| 1034 |
for(Contig contig : pt.contigs){ |
| 1035 |
allContigs.add(contig); |
| 1036 |
contigsBuilt++; |
| 1037 |
basesBuilt+=contig.length(); |
| 1038 |
longestContig=Tools.max(longestContig, contig.length()); |
| 1039 |
} |
| 1040 |
if(allInserts!=null){ |
| 1041 |
allInserts.incrementBy(pt.insertSizes); |
| 1042 |
} |
| 1043 |
|
| 1044 |
readsIn+=pt.readsInT; |
| 1045 |
basesIn+=pt.basesInT; |
| 1046 |
lowqReads+=pt.lowqReadsT; |
| 1047 |
lowqBases+=pt.lowqBasesT; |
| 1048 |
} |
| 1049 |
t.stop("Time: "); |
| 1050 |
} |
| 1051 |
|
| 1052 |
void processContigs(){ |
| 1053 |
|
| 1054 |
Timer t=new Timer(outstream, true); |
| 1055 |
outstream.println("Making contig graph."); |
| 1056 |
initializeContigs(allContigs); |
| 1057 |
runProcessContigThreads(); |
| 1058 |
outstream.println("Finished contig graph."); |
| 1059 |
t.stop("Time: "); |
| 1060 |
|
| 1061 |
if(popBubbles){ |
| 1062 |
t.start(); |
| 1063 |
for(int popped=1, i=0; popped>0 && i<bubblePasses; i++){ |
| 1064 |
popped=popBubbles(BubblePopper.debranch && (i==bubblePasses-1)); |
| 1065 |
} |
| 1066 |
t.stop("Time: "); |
| 1067 |
} |
| 1068 |
|
| 1069 |
if(outDot!=null){ |
| 1070 |
outstream.println("Writing contig graph."); |
| 1071 |
FileFormat ff=FileFormat.testOutput(outDot, FileFormat.TEXT, null, true, overwrite, append, false); |
| 1072 |
ByteStreamWriter bsw=new ByteStreamWriter(ff); |
| 1073 |
bsw.start(); |
| 1074 |
ByteBuilder bb=new ByteBuilder(1000); |
| 1075 |
bb.append("digraph G {\n"); |
| 1076 |
for(Contig c : allContigs){ |
| 1077 |
bb.tab().append(c.id); |
| 1078 |
bb.append(" [label=\"id=").append(c.id); |
| 1079 |
bb.append("\\nlen=").append(c.bases.length); |
| 1080 |
bb.append("\\ncov=").append(c.coverage, 1); |
| 1081 |
bb.append("\\nleft=").append(codeStrings[c.leftCode]); |
| 1082 |
bb.append("\\nright=").append(codeStrings[c.rightCode]).append("\"]").append('\n'); |
| 1083 |
if(c.leftEdges!=null){ |
| 1084 |
for(Edge e : c.leftEdges){ |
| 1085 |
bb.tab(); |
| 1086 |
e.toDot(bb); |
| 1087 |
} |
| 1088 |
} |
| 1089 |
if(c.rightEdges!=null){ |
| 1090 |
for(Edge e : c.rightEdges){ |
| 1091 |
bb.tab(); |
| 1092 |
e.toDot(bb); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
bsw.print(bb); |
| 1096 |
bb.clear(); |
| 1097 |
} |
| 1098 |
bb.append("}\n"); |
| 1099 |
bsw.print(bb); |
| 1100 |
bsw.poisonAndWait(); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
HashMap<Integer, ArrayList<Edge>> destToEdgeMap(){ |
| 1105 |
HashMap<Integer, ArrayList<Edge>> destToEdgeMap=new HashMap<Integer, ArrayList<Edge>>(); |
| 1106 |
for(Contig c : allContigs){ |
| 1107 |
if(!c.used() && !c.associate()){ |
| 1108 |
if(c.leftEdges!=null){ |
| 1109 |
for(Edge e : c.leftEdges){ |
| 1110 |
Integer d=e.destination; |
| 1111 |
ArrayList<Edge> list=destToEdgeMap.get(d); |
| 1112 |
if(list==null){ |
| 1113 |
list=new ArrayList<Edge>(2); |
| 1114 |
destToEdgeMap.put(d, list); |
| 1115 |
} |
| 1116 |
list.add(e); |
| 1117 |
} |
| 1118 |
} |
| 1119 |
if(c.rightEdges!=null){ |
| 1120 |
for(Edge e : c.rightEdges){ |
| 1121 |
Integer d=e.destination; |
| 1122 |
ArrayList<Edge> list=destToEdgeMap.get(d); |
| 1123 |
if(list==null){ |
| 1124 |
list=new ArrayList<Edge>(2); |
| 1125 |
destToEdgeMap.put(d, list); |
| 1126 |
} |
| 1127 |
list.add(e); |
| 1128 |
} |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
return destToEdgeMap; |
| 1133 |
} |
| 1134 |
|
| 1135 |
int popBubbles(boolean debranch){ |
| 1136 |
outstream.println("Popping bubbles; contigs="+allContigs.size()); |
| 1137 |
HashMap<Integer, ArrayList<Edge>> destToEdgeMap=destToEdgeMap(); |
| 1138 |
|
| 1139 |
int bubblesPoppedThisPass=0; |
| 1140 |
BubblePopper bp=new BubblePopper(allContigs, destToEdgeMap, kbig); |
| 1141 |
|
| 1142 |
if(debranch) { |
| 1143 |
for(Contig c : allContigs){ |
| 1144 |
bp.debranch(c); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
for(Contig c : allContigs){ |
| 1149 |
if(!c.used() && (c.leftForwardBranch() || c.rightForwardBranch())) { |
| 1150 |
bubblesPoppedThisPass+=bp.expand(c); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
ArrayList<Contig> temp=new ArrayList<Contig>(allContigs.size()); |
| 1155 |
|
| 1156 |
basesBuilt=0; |
| 1157 |
contigsBuilt=0; |
| 1158 |
longestContig=0; |
| 1159 |
|
| 1160 |
for(Contig c : allContigs){ |
| 1161 |
if(c.used()){ |
| 1162 |
|
| 1163 |
|
| 1164 |
}else{ |
| 1165 |
bp.removeDeadEdges(c); |
| 1166 |
|
| 1167 |
|
| 1168 |
temp.add(c); |
| 1169 |
final int len=c.length(); |
| 1170 |
if(len>=minContigLen){ |
| 1171 |
basesBuilt+=len; |
| 1172 |
contigsBuilt++; |
| 1173 |
longestContig=Tools.max(len, longestContig); |
| 1174 |
} |
| 1175 |
} |
| 1176 |
} |
| 1177 |
Shared.sort(temp, ContigLengthComparator.comparator); |
| 1178 |
|
| 1179 |
int newID=0; |
| 1180 |
destToEdgeMap=destToEdgeMap(); |
| 1181 |
for(Contig c : temp){ |
| 1182 |
c.renumber(newID, destToEdgeMap.get(c.id)); |
| 1183 |
newID++; |
| 1184 |
} |
| 1185 |
|
| 1186 |
allContigs.clear(); |
| 1187 |
allContigs.addAll(temp); |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
bubblesPopped+=bubblesPoppedThisPass; |
| 1211 |
|
| 1212 |
outstream.println("Popped "+bubblesPoppedThisPass+" bubbles"+(bp.debranch ? "; removed "+bp.branchesRemoved+" branches." : ".")); |
| 1213 |
return bubblesPoppedThisPass; |
| 1214 |
} |
| 1215 |
|
| 1216 |
void runProcessContigThreads(){ |
| 1217 |
|
| 1218 |
AtomicInteger next=new AtomicInteger(0); |
| 1219 |
ArrayList<AbstractProcessContigThread> alpt=new ArrayList<AbstractProcessContigThread>(THREADS); |
| 1220 |
for(int i=0; i<THREADS; i++){alpt.add(makeProcessContigThread(allContigs, next));} |
| 1221 |
for(AbstractProcessContigThread pt : alpt){pt.start();} |
| 1222 |
|
| 1223 |
|
| 1224 |
for(AbstractProcessContigThread pt : alpt){ |
| 1225 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 1226 |
try { |
| 1227 |
pt.join(); |
| 1228 |
} catch (InterruptedException e) { |
| 1229 |
|
| 1230 |
e.printStackTrace(); |
| 1231 |
} |
| 1232 |
} |
| 1233 |
edgesMade+=pt.edgesMadeT; |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|
| 1237 |
abstract void initializeContigs(ArrayList<Contig> contigs); |
| 1238 |
|
| 1239 |
abstract AbstractBuildThread makeBuildThread(int i, int mode, ConcurrentReadInputStream[] crisa); |
| 1240 |
|
| 1241 |
abstract AbstractProcessContigThread makeProcessContigThread(ArrayList<Contig> contigs, AtomicInteger next); |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
private final void extendReads(){ |
| 1247 |
|
| 1248 |
|
| 1249 |
final ConcurrentReadInputStream[] crisa=makeCrisArray(in1, in2); |
| 1250 |
|
| 1251 |
|
| 1252 |
final ConcurrentReadOutputStream[] rosa=makeCrosArray(out1, out2); |
| 1253 |
|
| 1254 |
|
| 1255 |
final ConcurrentReadOutputStream[] rosda=makeCrosArray(outd1, outd2); |
| 1256 |
|
| 1257 |
|
| 1258 |
ArrayList<ExtendThread> alpt=new ArrayList<ExtendThread>(THREADS); |
| 1259 |
for(int i=0; i<THREADS; i++){alpt.add(new ExtendThread(i, crisa, rosa, rosda));} |
| 1260 |
for(ExtendThread pt : alpt){pt.start();} |
| 1261 |
|
| 1262 |
|
| 1263 |
for(ExtendThread pt : alpt){ |
| 1264 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 1265 |
try { |
| 1266 |
pt.join(); |
| 1267 |
} catch (InterruptedException e) { |
| 1268 |
|
| 1269 |
e.printStackTrace(); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
readsIn+=pt.readsInT; |
| 1274 |
basesIn+=pt.basesInT; |
| 1275 |
lowqReads+=pt.lowqReadsT; |
| 1276 |
lowqBases+=pt.lowqBasesT; |
| 1277 |
readsExtended+=pt.readsExtendedT; |
| 1278 |
basesExtended+=pt.basesExtendedT; |
| 1279 |
readsCorrected+=pt.readsCorrectedT; |
| 1280 |
basesCorrectedPincer+=pt.basesCorrectedPincerT; |
| 1281 |
basesCorrectedTail+=pt.basesCorrectedTailT; |
| 1282 |
basesCorrectedReassemble+=pt.basesCorrectedReassembleT; |
| 1283 |
readsFullyCorrected+=pt.readsFullyCorrectedT; |
| 1284 |
rollbacks+=pt.rollbacksT; |
| 1285 |
readsDetected+=pt.readsDetectedT; |
| 1286 |
basesDetected+=pt.basesDetectedT; |
| 1287 |
readsMarked+=pt.readsMarkedT; |
| 1288 |
basesMarked+=pt.basesMarkedT; |
| 1289 |
readsDiscarded+=pt.readsDiscardedT; |
| 1290 |
basesDiscarded+=pt.basesDiscardedT; |
| 1291 |
|
| 1292 |
readsMerged+=pt.readsMergedT; |
| 1293 |
readsCorrectedEcco+=pt.readsCorrectedEccoT; |
| 1294 |
basesCorrectedEcco+=pt.basesCorrectedEccoT; |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
for(ConcurrentReadInputStream cris : crisa){ |
| 1299 |
errorState|=ReadWrite.closeStreams(cris); |
| 1300 |
} |
| 1301 |
|
| 1302 |
if(rosa!=null){ |
| 1303 |
for(ConcurrentReadOutputStream ros : rosa){ |
| 1304 |
errorState|=ReadWrite.closeStream(ros); |
| 1305 |
} |
| 1306 |
} |
| 1307 |
if(rosda!=null){ |
| 1308 |
for(ConcurrentReadOutputStream ros : rosda){ |
| 1309 |
errorState|=ReadWrite.closeStream(ros); |
| 1310 |
} |
| 1311 |
} |
| 1312 |
} |
| 1313 |
|
| 1314 |
private final ConcurrentReadInputStream[] makeCrisArray(ArrayList<String> list1, ArrayList<String> list2){ |
| 1315 |
final ConcurrentReadInputStream[] array; |
| 1316 |
|
| 1317 |
array=new ConcurrentReadInputStream[list1.size()]; |
| 1318 |
for(int i=0; i<list1.size(); i++){ |
| 1319 |
String a=list1.get(i); |
| 1320 |
String b=(list2.size()>i ? list2.get(i): null); |
| 1321 |
if(verbose){outstream.println("Creating cris for "+a);} |
| 1322 |
|
| 1323 |
final ConcurrentReadInputStream cris; |
| 1324 |
{ |
| 1325 |
FileFormat ff1=FileFormat.testInput(a, FileFormat.FASTA, null, true, true); |
| 1326 |
FileFormat ff2=(b==null ? null : FileFormat.testInput(b, FileFormat.FASTA, null, true, true)); |
| 1327 |
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ff1, ff2); |
| 1328 |
} |
| 1329 |
array[i]=cris; |
| 1330 |
} |
| 1331 |
return array; |
| 1332 |
} |
| 1333 |
|
| 1334 |
private final static ConcurrentReadOutputStream[] makeCrosArray(ArrayList<String> list1, ArrayList<String> list2){ |
| 1335 |
final ConcurrentReadOutputStream[] array; |
| 1336 |
|
| 1337 |
array=new ConcurrentReadOutputStream[list1.size()]; |
| 1338 |
for(int i=0; i<list1.size(); i++){ |
| 1339 |
String a=list1.get(i); |
| 1340 |
String b=(list2.size()>i ? list2.get(i): null); |
| 1341 |
if(verbose){outstream.println("Creating cris for "+a);} |
| 1342 |
|
| 1343 |
final ConcurrentReadOutputStream cris; |
| 1344 |
{ |
| 1345 |
final int buff=(!ordered ? 12 : Tools.max(32, 2*Shared.threads())); |
| 1346 |
FileFormat ff1=FileFormat.testOutput(a, FileFormat.FASTQ, null, true, overwrite, append, ordered); |
| 1347 |
FileFormat ff2=(b==null ? null : FileFormat.testOutput(b, FileFormat.FASTQ, null, true, overwrite, append, ordered)); |
| 1348 |
|
| 1349 |
cris=ConcurrentReadOutputStream.getStream(ff1, ff2, null, null, buff, null, false); |
| 1350 |
} |
| 1351 |
array[i]=cris; |
| 1352 |
} |
| 1353 |
return array; |
| 1354 |
} |
| 1355 |
|
| 1356 |
|
| 1357 |
public boolean mergeOK(Read merged, final int len1, final int len2, final BitSet bs, final IntList countList, final Kmer kmer, |
| 1358 |
final int width, final int thresh, final long mult){ |
| 1359 |
final int len=merged.length(); |
| 1360 |
final int overlap=Tools.min(len, len1+len2-len); |
| 1361 |
final byte[] bases=merged.bases; |
| 1362 |
if(len<len1+width+1 || len<len2+width+1 || len<kbig+width){return true;} |
| 1363 |
|
| 1364 |
final int a=len-len2-1; |
| 1365 |
final int b=a+1; |
| 1366 |
final int c=len1-1; |
| 1367 |
final int d=c+1; |
| 1368 |
|
| 1369 |
final int ak=a-kbig+1; |
| 1370 |
final int bk=b; |
| 1371 |
final int ck=c-kbig+1; |
| 1372 |
final int dk=d; |
| 1373 |
|
| 1374 |
|
| 1375 |
bs.clear(); |
| 1376 |
if(ak-width>=0 && ak+width<len){bs.set(ak-width, ak+width+1);} |
| 1377 |
if(bk-width>=0 && ck+width<len){bs.set(bk-width, bk+width+1);} |
| 1378 |
if(ck-width>=0 && bk+width<len){bs.set(ck-width, ck+width+1);} |
| 1379 |
if(dk-width>=0 && dk+width<len){bs.set(dk-width, dk+width+1);} |
| 1380 |
tables().fillSpecificCounts(bases, countList, bs, kmer); |
| 1381 |
|
| 1382 |
if(ak-width>=0 && ak+width<len){ |
| 1383 |
int min=countList.get(ak); |
| 1384 |
for(int i=ak-width+1; i<ak; i++){min=Tools.min(min, countList.get(i));} |
| 1385 |
int min2=countList.get(ak+1); |
| 1386 |
for(int i=ak+2; i<=ak+width; i++){min2=Tools.min(min2, countList.get(i));} |
| 1387 |
assert(min>=0 && min2>=0); |
| 1388 |
if(min>=thresh && min2<=1){return false;} |
| 1389 |
if(min2>0 && min>min2*mult){return false;} |
| 1390 |
} |
| 1391 |
if(ck-width>=0 && ck+width<len){ |
| 1392 |
|
| 1393 |
int min=countList.get(ck); |
| 1394 |
for(int i=ck-width+1; i<ck; i++){min=Tools.min(min, countList.get(i));} |
| 1395 |
int min2=countList.get(ck+1); |
| 1396 |
for(int i=ck+2; i<=ck+width; i++){min2=Tools.min(min2, countList.get(i));} |
| 1397 |
assert(min>=0 && min2>=0); |
| 1398 |
if(min>=thresh && min2<=1){return false;} |
| 1399 |
if(min2>0 && min>min2*mult){return false;} |
| 1400 |
|
| 1401 |
} |
| 1402 |
|
| 1403 |
if(bk-width>=0 && bk+width<len){ |
| 1404 |
|
| 1405 |
int min=countList.get(bk); |
| 1406 |
for(int i=bk+1; i<=bk+width; i++){min=Tools.min(min, countList.get(i));} |
| 1407 |
int min2=countList.get(bk-1); |
| 1408 |
for(int i=bk-width; i<bk-1; i++){min2=Tools.min(min2, countList.get(i));} |
| 1409 |
assert(min>=0 && min2>=0); |
| 1410 |
if(min>=thresh && min2<=1){return false;} |
| 1411 |
if(min2>0 && min>min2*mult){return false;} |
| 1412 |
|
| 1413 |
} |
| 1414 |
if(dk-width>=0 && dk+width<len){ |
| 1415 |
int min=countList.get(dk); |
| 1416 |
for(int i=dk+1; i<=dk+width; i++){min=Tools.min(min, countList.get(i));} |
| 1417 |
int min2=countList.get(dk-1); |
| 1418 |
for(int i=dk-width; i<dk-1; i++){min2=Tools.min(min2, countList.get(i));} |
| 1419 |
assert(min>=0 && min2>=0); |
| 1420 |
if(min>=thresh && min2<=1){return false;} |
| 1421 |
if(min2>0 && min>min2*mult){return false;} |
| 1422 |
} |
| 1423 |
return true; |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
private final class ExtendThread extends Thread{ |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
public ExtendThread(int id_, ConcurrentReadInputStream[] crisa_, ConcurrentReadOutputStream[] rosa_, ConcurrentReadOutputStream[] rosda_){ |
| 1447 |
tid=id_; |
| 1448 |
crisa=crisa_; |
| 1449 |
rosa=rosa_; |
| 1450 |
rosda=rosda_; |
| 1451 |
leftCounts=extendThroughLeftJunctions ? null : KillSwitch.allocInt1D(4); |
| 1452 |
} |
| 1453 |
|
| 1454 |
@Override |
| 1455 |
public void run(){ |
| 1456 |
initializeThreadLocals(); |
| 1457 |
for(int i=0; i<crisa.length; i++){ |
| 1458 |
ConcurrentReadInputStream cris=crisa[i]; |
| 1459 |
ConcurrentReadOutputStream ros=(rosa!=null && rosa.length>i ? rosa[i] : null); |
| 1460 |
ConcurrentReadOutputStream rosd=(rosda!=null && rosda.length>i ? rosda[i] : null); |
| 1461 |
synchronized(crisa){ |
| 1462 |
if(!cris.started()){ |
| 1463 |
cris.start(); |
| 1464 |
} |
| 1465 |
} |
| 1466 |
if(ros!=null){ |
| 1467 |
synchronized(rosa){ |
| 1468 |
if(!ros.started()){ |
| 1469 |
ros.start(); |
| 1470 |
} |
| 1471 |
} |
| 1472 |
} |
| 1473 |
if(rosd!=null){ |
| 1474 |
synchronized(rosda){ |
| 1475 |
if(!rosd.started()){ |
| 1476 |
rosd.start(); |
| 1477 |
} |
| 1478 |
} |
| 1479 |
} |
| 1480 |
run(cris, ros, rosd); |
| 1481 |
} |
| 1482 |
} |
| 1483 |
|
| 1484 |
private void run(ConcurrentReadInputStream cris, ConcurrentReadOutputStream ros, ConcurrentReadOutputStream rosd){ |
| 1485 |
|
| 1486 |
ListNum<Read> ln=cris.nextList(); |
| 1487 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 1488 |
|
| 1489 |
|
| 1490 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 1491 |
|
| 1492 |
final ArrayList<Read> listOut=new ArrayList<Read>(reads.size()); |
| 1493 |
final ArrayList<Read> listOutD=(rosd==null ? null : new ArrayList<Read>(reads.size())); |
| 1494 |
|
| 1495 |
|
| 1496 |
for(int i=0; i<reads.size(); i++){ |
| 1497 |
final Read r1=reads.get(i); |
| 1498 |
final Read r2=r1.mate; |
| 1499 |
|
| 1500 |
processReadPair(r1, r2); |
| 1501 |
if(r1.discarded() && (r2==null || r2.discarded())){ |
| 1502 |
readsDiscardedT+=r1.pairCount(); |
| 1503 |
basesDiscardedT+=r1.pairLength(); |
| 1504 |
if(listOutD!=null){listOutD.add(r1);} |
| 1505 |
}else{ |
| 1506 |
listOut.add(r1); |
| 1507 |
} |
| 1508 |
} |
| 1509 |
if(ros!=null){ros.add(listOut, ln.id);} |
| 1510 |
if(rosd!=null){rosd.add(listOutD, ln.id);} |
| 1511 |
|
| 1512 |
|
| 1513 |
cris.returnList(ln); |
| 1514 |
ln=cris.nextList(); |
| 1515 |
reads=(ln!=null ? ln.list : null); |
| 1516 |
} |
| 1517 |
cris.returnList(ln); |
| 1518 |
} |
| 1519 |
|
| 1520 |
final int findOverlap(Read r1, Read r2, boolean ecc){ |
| 1521 |
if(vstrict){ |
| 1522 |
return BBMerge.findOverlapVStrict(r1, r2, ecc); |
| 1523 |
}else{ |
| 1524 |
return BBMerge.findOverlapStrict(r1, r2, ecc); |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
private void processReadPair(final Read r10, final Read r20){ |
| 1529 |
Read r1=r10, r2=r20; |
| 1530 |
if(verbose){outstream.println("Considering read "+r1.id+" "+new String(r1.bases));} |
| 1531 |
final String r2id=r1.mateId(); |
| 1532 |
final int initialLength1=r1.length(); |
| 1533 |
final int initialLength2=r1.mateLength(); |
| 1534 |
|
| 1535 |
readsInT++; |
| 1536 |
basesInT+=r1.length(); |
| 1537 |
if(r2!=null){ |
| 1538 |
readsInT++; |
| 1539 |
basesInT+=r2.length(); |
| 1540 |
} |
| 1541 |
|
| 1542 |
final Read r1_0=r1, r2_0=r2; |
| 1543 |
if((ecco || merge) && r1!=null && r2!=null && !r1.discarded() && !r2.discarded()){ |
| 1544 |
final int insert=findOverlap(r1, r2, false); |
| 1545 |
if(merge){ |
| 1546 |
if(insert>0){ |
| 1547 |
r2.reverseComplement(); |
| 1548 |
r1=r1.joinRead(insert); |
| 1549 |
r2.reverseComplement(); |
| 1550 |
r2=null; |
| 1551 |
if(testMerge && !mergeOK(r1, initialLength1, initialLength2, mergeOKBitsetT, countList, kmerT, testMergeWidth, testMergeThresh, testMergeMult)){ |
| 1552 |
r1=r1_0; |
| 1553 |
r2=r2_0; |
| 1554 |
}else{ |
| 1555 |
r2_0.reverseComplement(); |
| 1556 |
int errors=BBMerge.countErrors(r1_0, r2_0, r1); |
| 1557 |
r2_0.reverseComplement(); |
| 1558 |
basesCorrectedEccoT+=errors; |
| 1559 |
readsCorrectedEccoT+=(errors>0 ? 1 : 0); |
| 1560 |
readsMergedT++; |
| 1561 |
} |
| 1562 |
} |
| 1563 |
}else if(ecco){ |
| 1564 |
|
| 1565 |
if(insert>0){ |
| 1566 |
r2.reverseComplement(); |
| 1567 |
Read merged=r1.joinRead(insert); |
| 1568 |
if(!testMerge || mergeOK(merged, initialLength1, initialLength2, mergeOKBitsetT, countList, kmerT, testMergeWidth, testMergeThresh, testMergeMult)){ |
| 1569 |
int errors=BBMerge.errorCorrectWithInsert(r1, r2, insert); |
| 1570 |
basesCorrectedEccoT+=errors; |
| 1571 |
readsCorrectedEccoT+=(errors>0 ?1 : 0); |
| 1572 |
readsMergedT++; |
| 1573 |
} |
| 1574 |
r2.reverseComplement(); |
| 1575 |
} |
| 1576 |
} |
| 1577 |
} |
| 1578 |
|
| 1579 |
processRead(r1); |
| 1580 |
processRead(r2); |
| 1581 |
|
| 1582 |
|
| 1583 |
if(merge && r2==null && r2id!=null && !trackerT.rollback){ |
| 1584 |
final int to=r1.length()-1; |
| 1585 |
final int len=Tools.min(r1.length(), initialLength2); |
| 1586 |
r2=r1.subRead(to-len+1, to); |
| 1587 |
r2.setPairnum(1); |
| 1588 |
r2.reverseComplement(); |
| 1589 |
r2.mate=r1; |
| 1590 |
r1.mate=r2; |
| 1591 |
r2.id=r2id; |
| 1592 |
|
| 1593 |
if(r1.length()>initialLength1){ |
| 1594 |
r1.bases=Arrays.copyOf(r1.bases, initialLength1); |
| 1595 |
if(r1.quality!=null){r1.quality=Arrays.copyOf(r1.quality, initialLength1);} |
| 1596 |
} |
| 1597 |
|
| 1598 |
r10.bases=r1.bases; |
| 1599 |
r10.quality=r1.quality; |
| 1600 |
r10.flags=r1.flags; |
| 1601 |
r20.bases=r2.bases; |
| 1602 |
r20.quality=r2.quality; |
| 1603 |
r20.flags=r2.flags; |
| 1604 |
} |
| 1605 |
} |
| 1606 |
|
| 1607 |
private void processRead(Read r){ |
| 1608 |
if(r==null){return;} |
| 1609 |
if(!r.validated()){r.validate(true);} |
| 1610 |
if(r.discarded()){ |
| 1611 |
lowqBasesT+=r.length(); |
| 1612 |
lowqReadsT++; |
| 1613 |
return; |
| 1614 |
} |
| 1615 |
if(ecc || MARK_BAD_BASES>0){ |
| 1616 |
final int corrected=errorCorrect(r, leftCounts, rightCounts, kmerList, countList, countList2, builderT, builderT2, trackerT, bitsetT, kmerT, kmerT2); |
| 1617 |
final int detected=trackerT.detected(); |
| 1618 |
final int correctedPincer=trackerT.correctedPincer; |
| 1619 |
final int correctedTail=trackerT.correctedTail; |
| 1620 |
final int correctedReassemble=trackerT.correctedReassemble(); |
| 1621 |
final int marked=trackerT.marked; |
| 1622 |
assert(corrected==correctedPincer+correctedTail+correctedReassemble) : corrected+", "+trackerT; |
| 1623 |
if(marked>0){ |
| 1624 |
readsMarkedT++; |
| 1625 |
basesMarkedT+=marked; |
| 1626 |
} |
| 1627 |
if(trackerT.rollback){rollbacksT++;} |
| 1628 |
if(detected>0){ |
| 1629 |
readsDetectedT++; |
| 1630 |
basesDetectedT+=detected; |
| 1631 |
if(corrected>0){ |
| 1632 |
readsCorrectedT++; |
| 1633 |
basesCorrectedPincerT+=correctedPincer; |
| 1634 |
basesCorrectedTailT+=correctedTail; |
| 1635 |
basesCorrectedReassembleT+=correctedReassemble; |
| 1636 |
} |
| 1637 |
if(corrected==detected || (corrected>0 && countErrors(countList, r.quality)==0)){ |
| 1638 |
readsFullyCorrectedT++; |
| 1639 |
}else if(discardUncorrectable){ |
| 1640 |
r.setDiscarded(true); |
| 1641 |
if(r.mate!=null && !requireBothBad){ |
| 1642 |
r.mate.setDiscarded(true); |
| 1643 |
return; |
| 1644 |
}else if(r.mate==null){return;} |
| 1645 |
} |
| 1646 |
} |
| 1647 |
} |
| 1648 |
|
| 1649 |
if(tossJunk && isJunk(r, rightCounts, kmerT)){ |
| 1650 |
r.setDiscarded(true); |
| 1651 |
return; |
| 1652 |
} |
| 1653 |
|
| 1654 |
if(discardLowDepthReads>=0 && hasKmersAtOrBelow(r, discardLowDepthReads, lowDepthDiscardFraction, kmerT)){ |
| 1655 |
r.setDiscarded(true); |
| 1656 |
if(r.mate!=null && !requireBothBad){ |
| 1657 |
r.mate.setDiscarded(true); |
| 1658 |
return; |
| 1659 |
}else if(r.mate==null){return;} |
| 1660 |
} |
| 1661 |
|
| 1662 |
int extensionRight=0, extensionLeft=0; |
| 1663 |
if(extendRight>0){ |
| 1664 |
extensionRight=extendRead(r, builderT, leftCounts, rightCounts, extendRight, kmerT); |
| 1665 |
} |
| 1666 |
if(extendLeft>0){ |
| 1667 |
r.reverseComplement(); |
| 1668 |
extensionLeft=extendRead(r, builderT, leftCounts, rightCounts, extendLeft, kmerT); |
| 1669 |
r.reverseComplement(); |
| 1670 |
} |
| 1671 |
if(extensionRollback>0){ |
| 1672 |
int leftMod=0, rightMod=0; |
| 1673 |
if(extensionLeft>0 && extensionLeft<extendLeft){ |
| 1674 |
leftMod=Tools.min(extensionLeft, (int)(r.numericID%(extensionRollback+1))); |
| 1675 |
extensionLeft-=leftMod; |
| 1676 |
} |
| 1677 |
if(extensionRight>0 && extensionRight<extendRight){ |
| 1678 |
rightMod=Tools.min(extensionRight, (int)(r.numericID%(extensionRollback+1))); |
| 1679 |
extensionRight-=rightMod; |
| 1680 |
} |
| 1681 |
if(leftMod>0 || rightMod>0){TrimRead.trimByAmount(r, leftMod, rightMod, 0);} |
| 1682 |
} |
| 1683 |
final int extension=extensionRight+extensionLeft; |
| 1684 |
basesExtendedT+=extension; |
| 1685 |
readsExtendedT+=(extension>0 ? 1 : 0); |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
private final ConcurrentReadInputStream[] crisa; |
| 1692 |
private final ConcurrentReadOutputStream[] rosa; |
| 1693 |
private final ConcurrentReadOutputStream[] rosda; |
| 1694 |
|
| 1695 |
private final int[] leftCounts; |
| 1696 |
private final int[] rightCounts=KillSwitch.allocInt1D(4); |
| 1697 |
private final ErrorTracker trackerT=new ErrorTracker(); |
| 1698 |
private final ByteBuilder builderT=new ByteBuilder(); |
| 1699 |
private final ByteBuilder builderT2=new ByteBuilder(); |
| 1700 |
private final Kmer kmerT=new Kmer(kbig); |
| 1701 |
private final Kmer kmerT2=new Kmer(kbig); |
| 1702 |
private final BitSet bitsetT=new BitSet(300); |
| 1703 |
private final BitSet mergeOKBitsetT=new BitSet(300); |
| 1704 |
private final LongList kmerList=new LongList(); |
| 1705 |
private final IntList countList=new IntList(); |
| 1706 |
private final IntList countList2=new IntList(); |
| 1707 |
|
| 1708 |
long readsInT=0; |
| 1709 |
long basesInT=0; |
| 1710 |
long lowqReadsT=0; |
| 1711 |
long lowqBasesT=0; |
| 1712 |
long readsExtendedT=0; |
| 1713 |
long basesExtendedT=0; |
| 1714 |
long readsCorrectedT=0; |
| 1715 |
long basesCorrectedPincerT=0; |
| 1716 |
long basesCorrectedTailT=0; |
| 1717 |
long basesCorrectedReassembleT=0; |
| 1718 |
long readsFullyCorrectedT=0; |
| 1719 |
long rollbacksT=0; |
| 1720 |
long readsDetectedT=0; |
| 1721 |
long basesDetectedT=0; |
| 1722 |
long readsMarkedT=0; |
| 1723 |
long basesMarkedT=0; |
| 1724 |
long readsDiscardedT=0; |
| 1725 |
long basesDiscardedT=0; |
| 1726 |
|
| 1727 |
long readsMergedT=0; |
| 1728 |
long readsCorrectedEccoT=0; |
| 1729 |
long basesCorrectedEccoT=0; |
| 1730 |
|
| 1731 |
private final int tid; |
| 1732 |
|
| 1733 |
} |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
public abstract int extendRead(Read r, ByteBuilder bb, int[] leftCounts, int[] rightCounts, int distance); |
| 1741 |
public abstract int extendRead(Read r, ByteBuilder bb, int[] leftCounts, int[] rightCounts, int distance, final Kmer kmer); |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
public abstract int extendToRight2(final ByteBuilder bb, final int[] leftCounts, final int[] rightCounts, final int distance, boolean includeJunctionBase); |
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
public int extendToRight2(final ByteBuilder bb, final int[] leftCounts, final int[] rightCounts, final int distance, boolean includeJunctionBase, Kmer kmer){ |
| 1759 |
throw new RuntimeException("Must be overridden."); |
| 1760 |
} |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
public abstract boolean isJunk(Read r); |
| 1769 |
|
| 1770 |
public abstract boolean isJunk(Read r, final int[] localLeftCounts, Kmer kmer); |
| 1771 |
|
| 1772 |
|
| 1773 |
public abstract boolean hasKmersAtOrBelow(Read r, int count, float fraction); |
| 1774 |
|
| 1775 |
|
| 1776 |
public abstract boolean hasKmersAtOrBelow(Read r, int count, float fraction, Kmer kmer); |
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
public final int countErrors(IntList counts, byte[] quals){ |
| 1783 |
int possibleErrors=0; |
| 1784 |
for(int i=1; i<counts.size; i++){ |
| 1785 |
final int a=counts.get(i-1), b=counts.get(i); |
| 1786 |
boolean error; |
| 1787 |
if(quals!=null){ |
| 1788 |
error=isErrorBidirectional(a, b, quals[i-1], quals[i+kbig-1]); |
| 1789 |
}else{ |
| 1790 |
error=isErrorBidirectional(a, b, (byte)20, (byte)20); |
| 1791 |
} |
| 1792 |
if(error){ |
| 1793 |
possibleErrors++; |
| 1794 |
i+=kbig; |
| 1795 |
} |
| 1796 |
} |
| 1797 |
return possibleErrors; |
| 1798 |
} |
| 1799 |
|
| 1800 |
public abstract int errorCorrect(Read r); |
| 1801 |
|
| 1802 |
public abstract int errorCorrect(Read r, final int[] leftCounts, final int[] rightCounts, LongList kmers, IntList counts, IntList counts2, |
| 1803 |
final ByteBuilder bb, final ByteBuilder bb2, final ErrorTracker tracker, final BitSet bs, Kmer kmer, Kmer kmer2); |
| 1804 |
|
| 1805 |
public abstract int reassemble_inner(ByteBuilder bb, byte[] quals, final int[] rightCounts, IntList counts, |
| 1806 |
final int extension, final Kmer kmer, final Kmer kmer2); |
| 1807 |
|
| 1808 |
public final int reassemble(final byte[] bases, final byte[] quals, final int[] rightCounts, final IntList counts, final IntList counts2, |
| 1809 |
final ErrorTracker tracker, final int errorExtension, final ByteBuilder bb, final ByteBuilder bb2, final Kmer kmer, final Kmer regenKmer, BitSet bs){ |
| 1810 |
if(bases.length<kbig+1+deadZone){return 0;} |
| 1811 |
final ByteBuilder fromLeft=new ByteBuilder(bases.length); |
| 1812 |
final ByteBuilder fromRight=new ByteBuilder(bases.length); |
| 1813 |
|
| 1814 |
int detected0=tracker.detectedReassemble; |
| 1815 |
int corrected=reassemble_pass(bases, quals, fromLeft, fromRight, rightCounts, counts, counts2, tracker, errorExtension, kmer, regenKmer, bs); |
| 1816 |
|
| 1817 |
int correctedIncr=corrected; |
| 1818 |
int detectedIncr=tracker.detectedReassemble-detected0; |
| 1819 |
int uncorrected=detectedIncr-correctedIncr; |
| 1820 |
|
| 1821 |
for(int passes=1; passes<6 && correctedIncr>0 && uncorrected>0; passes++){ |
| 1822 |
tracker.detectedReassemble-=uncorrected; |
| 1823 |
detected0=tracker.detectedReassemble; |
| 1824 |
correctedIncr=reassemble_pass(bases, quals, fromLeft, fromRight, rightCounts, counts, counts2, tracker, errorExtension, kmer, regenKmer, bs); |
| 1825 |
|
| 1826 |
corrected+=correctedIncr; |
| 1827 |
detectedIncr=tracker.detectedReassemble-detected0; |
| 1828 |
uncorrected=detectedIncr-correctedIncr; |
| 1829 |
} |
| 1830 |
|
| 1831 |
return corrected; |
| 1832 |
} |
| 1833 |
|
| 1834 |
public final int reassemble_pass(final byte[] bases, final byte[] quals, final ByteBuilder fromLeft, final ByteBuilder fromRight, |
| 1835 |
final int[] rightCounts, final IntList counts, final IntList counts2, final ErrorTracker tracker, final int errorExtension, |
| 1836 |
final Kmer kmer, final Kmer kmer2, final BitSet bs){ |
| 1837 |
if(bases.length<kbig+1+deadZone){return 0;} |
| 1838 |
|
| 1839 |
fromLeft.clear(); |
| 1840 |
fromRight.clear(); |
| 1841 |
for(byte b : bases){ |
| 1842 |
fromLeft.append(b); |
| 1843 |
fromRight.append(b); |
| 1844 |
} |
| 1845 |
|
| 1846 |
assert(counts.size>0) : counts+", "+bases.length; |
| 1847 |
|
| 1848 |
counts2.clear(); |
| 1849 |
counts2.addAll(counts); |
| 1850 |
reassemble_inner(fromLeft, quals, rightCounts, counts2, errorExtension, kmer, kmer2); |
| 1851 |
|
| 1852 |
fromRight.reverseComplementInPlace(); |
| 1853 |
counts2.clear(); |
| 1854 |
counts2.addAll(counts); |
| 1855 |
counts2.reverse(); |
| 1856 |
|
| 1857 |
reassemble_inner(fromRight, quals, rightCounts, counts2, errorExtension, kmer, kmer2); |
| 1858 |
fromRight.reverseComplementInPlace(); |
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
int correctedInner=0; |
| 1865 |
int correctedOuter=0; |
| 1866 |
int detectedInner=0; |
| 1867 |
int detectedOuter=0; |
| 1868 |
boolean rollback=false; |
| 1869 |
|
| 1870 |
for(int i=0; i<bases.length; i++){ |
| 1871 |
byte a=bases[i]; |
| 1872 |
byte b=fromLeft.get(i); |
| 1873 |
byte c=fromRight.get(i); |
| 1874 |
if(a!=b || a!=c){ |
| 1875 |
if(b==c){detectedInner++;} |
| 1876 |
else{ |
| 1877 |
detectedOuter++; |
| 1878 |
if(a!=b && a!=c){ |
| 1879 |
assert(b!=c); |
| 1880 |
rollback=true; |
| 1881 |
} |
| 1882 |
} |
| 1883 |
} |
| 1884 |
if(b==a){fromLeft.set(i, (byte)0);} |
| 1885 |
if(c==a){fromRight.set(i, (byte)0);} |
| 1886 |
} |
| 1887 |
|
| 1888 |
final int detected=detectedInner+detectedOuter; |
| 1889 |
tracker.detectedReassemble+=detected; |
| 1890 |
if(rollback || detected==0){return 0;} |
| 1891 |
bs.clear(); |
| 1892 |
|
| 1893 |
int clearedLeft=clearWindow2(fromLeft, quals, windowLen, windowCount, windowQualSum); |
| 1894 |
fromRight.reverseInPlace(); |
| 1895 |
Tools.reverseInPlace(quals); |
| 1896 |
int clearedRight=clearWindow2(fromRight, quals, windowLen, windowCount, windowQualSum); |
| 1897 |
fromRight.reverseInPlace(); |
| 1898 |
Tools.reverseInPlace(quals); |
| 1899 |
|
| 1900 |
for(int i=0; i<bases.length; i++){ |
| 1901 |
byte a=bases[i]; |
| 1902 |
byte b=fromLeft.get(i); |
| 1903 |
byte c=fromRight.get(i); |
| 1904 |
byte d=a; |
| 1905 |
if(b==0 && c==0){ |
| 1906 |
|
| 1907 |
}else if(b==c){ |
| 1908 |
d=b; |
| 1909 |
}else if(b==0){ |
| 1910 |
d=c; |
| 1911 |
}else if(c==0){ |
| 1912 |
d=b; |
| 1913 |
}else if(b!=c){ |
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
} |
| 1918 |
|
| 1919 |
if(ECC_REQUIRE_BIDIRECTIONAL && b!=c && i>=kbig && i<bases.length-kbig){d=a;} |
| 1920 |
|
| 1921 |
if(d!=a){ |
| 1922 |
byte q=(quals==null ? 30 : quals[i]); |
| 1923 |
if(b==c){ |
| 1924 |
correctedInner++; |
| 1925 |
q=(byte)Tools.mid(q+qIncreasePincer, qMinPincer, qMaxPincer); |
| 1926 |
}else{ |
| 1927 |
correctedOuter++; |
| 1928 |
q=(byte)Tools.mid(q+qIncreaseTail, qMinTail, qMaxTail); |
| 1929 |
} |
| 1930 |
if(!rollback){ |
| 1931 |
bs.set(i); |
| 1932 |
bases[i]=d; |
| 1933 |
if(quals!=null){quals[i]=q;} |
| 1934 |
} |
| 1935 |
} |
| 1936 |
} |
| 1937 |
|
| 1938 |
if(rollback && correctedInner+correctedOuter>0){ |
| 1939 |
tracker.rollback=true; |
| 1940 |
return 0; |
| 1941 |
} |
| 1942 |
|
| 1943 |
{ |
| 1944 |
tracker.correctedReassembleInner+=correctedInner; |
| 1945 |
tracker.correctedReassembleOuter+=correctedOuter; |
| 1946 |
} |
| 1947 |
int corrected=correctedOuter+correctedInner; |
| 1948 |
|
| 1949 |
if(corrected>0){ |
| 1950 |
AbstractKmerTableSet tables=tables(); |
| 1951 |
|
| 1952 |
|
| 1953 |
tables.regenerateCounts(bases, counts, kmer, bs); |
| 1954 |
assert(counts.size>0); |
| 1955 |
} |
| 1956 |
|
| 1957 |
return corrected; |
| 1958 |
} |
| 1959 |
|
| 1960 |
private static int clearWindow2(final ByteBuilder bb, final byte[] quals, final int window, |
| 1961 |
final int limit, final int qsumLimit){ |
| 1962 |
final int len=bb.length; |
| 1963 |
final byte[] array=bb.array; |
| 1964 |
|
| 1965 |
int cleared=0; |
| 1966 |
int count=0, countHQ=0, qsum=0; |
| 1967 |
for(int i=0, prev=-window; i<len; i++, prev++){ |
| 1968 |
byte b=array[i]; |
| 1969 |
|
| 1970 |
if(b!=0 && (quals==null || quals[prev]>0)){ |
| 1971 |
count++; |
| 1972 |
if(quals!=null){ |
| 1973 |
qsum+=quals[i]; |
| 1974 |
|
| 1975 |
} |
| 1976 |
if(count>limit || qsum>qsumLimit ){ |
| 1977 |
for(int j=Tools.max(0, i-window), lim=bb.length(); j<lim; j++){ |
| 1978 |
if(array[j]!=0){ |
| 1979 |
array[j]=0; |
| 1980 |
cleared++; |
| 1981 |
} |
| 1982 |
} |
| 1983 |
return cleared; |
| 1984 |
} |
| 1985 |
} |
| 1986 |
if(prev>=0 && array[prev]>0 && (quals==null || quals[prev]>0)){ |
| 1987 |
count--; |
| 1988 |
if(quals!=null){ |
| 1989 |
countHQ--; |
| 1990 |
|
| 1991 |
} |
| 1992 |
} |
| 1993 |
} |
| 1994 |
return cleared; |
| 1995 |
} |
| 1996 |
|
| 1997 |
|
| 1998 |
public final int markBadBases(final byte[] bases, final byte[] quals, final IntList counts, final BitSet bs, |
| 1999 |
final int minCount, boolean deltaOnly, final byte markQuality){ |
| 2000 |
if(counts.size<1){return 0;} |
| 2001 |
|
| 2002 |
bs.clear(); |
| 2003 |
assert(counts.size==bases.length-kbig+1) : counts.size+", "+bases.length; |
| 2004 |
|
| 2005 |
|
| 2006 |
for(int i=0; i<counts.size;){ |
| 2007 |
final int count=counts.get(i); |
| 2008 |
if(count>=minCount){ |
| 2009 |
bs.set(i, i+kbig); |
| 2010 |
i+=kbig; |
| 2011 |
}else{ |
| 2012 |
|
| 2013 |
i++; |
| 2014 |
} |
| 2015 |
} |
| 2016 |
{ |
| 2017 |
final int i=counts.size-1; |
| 2018 |
final int count=counts.get(i); |
| 2019 |
if(count>=minCount){ |
| 2020 |
bs.set(i, i+kbig); |
| 2021 |
} |
| 2022 |
} |
| 2023 |
|
| 2024 |
final int card=bs.cardinality(); |
| 2025 |
final int toMark=bases.length-card; |
| 2026 |
int marked=0; |
| 2027 |
assert(card<=bases.length); |
| 2028 |
|
| 2029 |
int consecutiveBad=0; |
| 2030 |
for(int i=0; i<bases.length; i++){ |
| 2031 |
if(bs.get(i)){ |
| 2032 |
consecutiveBad=0; |
| 2033 |
}else{ |
| 2034 |
consecutiveBad++; |
| 2035 |
boolean mark=((quals!=null && quals[i]>markQuality) || bases[i]!='N'); |
| 2036 |
if(mark && deltaOnly){ |
| 2037 |
mark=(consecutiveBad>=kbig) || bs.get(i+1) || (i>0 && bs.get(i-1)); |
| 2038 |
} |
| 2039 |
if(mark){ |
| 2040 |
marked++; |
| 2041 |
|
| 2042 |
if(markQuality<1){ |
| 2043 |
bases[i]='N'; |
| 2044 |
} |
| 2045 |
if(quals!=null){ |
| 2046 |
quals[i]=Tools.min(quals[i], (bases[i]=='N' ? 0 : markQuality)); |
| 2047 |
} |
| 2048 |
} |
| 2049 |
if(bases[i]=='N' || (quals!=null && quals[i]<=markQuality)){consecutiveBad=0;} |
| 2050 |
} |
| 2051 |
} |
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
return marked; |
| 2056 |
} |
| 2057 |
|
| 2058 |
protected final boolean isSimilar(final int a, int loc1, int loc2, final IntList counts){ |
| 2059 |
loc1=Tools.max(loc1, 0); |
| 2060 |
loc2=Tools.min(loc2, counts.size-1); |
| 2061 |
for(int i=loc1; i<=loc2; i++){ |
| 2062 |
if(!isSimilar(a, counts.get(i))){return false;} |
| 2063 |
} |
| 2064 |
return true; |
| 2065 |
} |
| 2066 |
|
| 2067 |
protected final boolean isSimilar(final int a, final int b){ |
| 2068 |
int min=Tools.min(a, b); |
| 2069 |
int max=Tools.max(a, b); |
| 2070 |
int dif=max-min; |
| 2071 |
assert(dif>=0); |
| 2072 |
return (dif<pathSimilarityConstant || dif<max*pathSimilarityFraction); |
| 2073 |
} |
| 2074 |
|
| 2075 |
protected final boolean isError(final int a, int loc1, int loc2, final IntList counts){ |
| 2076 |
loc1=Tools.max(loc1, 0); |
| 2077 |
loc2=Tools.min(loc2, counts.size-1); |
| 2078 |
for(int i=loc1; i<=loc2; i++){ |
| 2079 |
if(!isError(a, counts.get(i))){return false;} |
| 2080 |
} |
| 2081 |
return true; |
| 2082 |
} |
| 2083 |
|
| 2084 |
protected final boolean isErrorBidirectional(final int a, final int b, final byte qa, final byte qb){ |
| 2085 |
return (a>=b ? isError(a, b, qb) : isError(b, a, qa)); |
| 2086 |
} |
| 2087 |
|
| 2088 |
protected final boolean isError(final int high, final int low){ |
| 2089 |
float em1; |
| 2090 |
if(errorPath==1){ |
| 2091 |
em1=errorMult1; |
| 2092 |
}else if(errorPath==2){ |
| 2093 |
|
| 2094 |
|
| 2095 |
em1=Tools.mid(errorMult1, 4, low*1.6f-3); |
| 2096 |
|
| 2097 |
}else{throw new RuntimeException(""+errorPath);} |
| 2098 |
|
| 2099 |
return (low*em1<high || (low<=errorLowerConst && high>=Tools.max(minCountCorrect, low*errorMult2))); |
| 2100 |
} |
| 2101 |
|
| 2102 |
protected final boolean isError(final int high, final int low, final byte q){ |
| 2103 |
float em1; |
| 2104 |
if(errorPath==1){ |
| 2105 |
em1=errorMult1*(1+q*errorMultQFactor); |
| 2106 |
}else if(errorPath==2){ |
| 2107 |
if(low<minCountCorrect && high>=minCountCorrect && q<20 && high>2*low){return true;} |
| 2108 |
|
| 2109 |
em1=Tools.mid(errorMult1, 4, low*(q<=10 ? 1.6f : 2f)-3); |
| 2110 |
em1=em1*(1+q*errorMultQFactor); |
| 2111 |
}else{throw new RuntimeException(""+errorPath);} |
| 2112 |
|
| 2113 |
return (low*em1<high || (low<=errorLowerConst && high>=Tools.max(minCountCorrect, low*errorMult2))); |
| 2114 |
} |
| 2115 |
|
| 2116 |
protected final boolean isSubstitution(int ca, int errorExtension, byte qb, IntList counts){ |
| 2117 |
final int cb=ca+1; |
| 2118 |
final int aCount=counts.get(ca); |
| 2119 |
final int bCount=counts.get(cb); |
| 2120 |
if(isError(aCount, bCount, qb) && isSimilar(aCount, ca-errorExtension, ca-1, counts) && |
| 2121 |
isError(aCount, ca+2, ca+kbig, counts)){ |
| 2122 |
final int cc=ca+kbig; |
| 2123 |
final int cd=cc+1; |
| 2124 |
if(cd<counts.size){ |
| 2125 |
final int cCount=counts.get(cc); |
| 2126 |
final int dCount=counts.get(cd); |
| 2127 |
if(isError(aCount, dCount) || isError(dCount, cCount, qb)){ |
| 2128 |
return true; |
| 2129 |
} |
| 2130 |
}else{return true;} |
| 2131 |
} |
| 2132 |
return false; |
| 2133 |
} |
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
protected static final Kmer getKmer(byte[] bases, int loc, Kmer kmer){ |
| 2141 |
kmer.clear(); |
| 2142 |
for(int i=loc, lim=loc+kmer.kbig; i<lim; i++){ |
| 2143 |
byte b=bases[i]; |
| 2144 |
int x=AminoAcid.baseToNumber[b]; |
| 2145 |
if(x<0){return null;} |
| 2146 |
kmer.addRightNumeric(x); |
| 2147 |
} |
| 2148 |
assert(kmer.len==kmer.kbig); |
| 2149 |
return kmer; |
| 2150 |
} |
| 2151 |
|
| 2152 |
protected final boolean isJunction(int rightMax, int rightSecond, int leftMax, int leftSecond){ |
| 2153 |
if(isJunction(rightMax, rightSecond)){return true;} |
| 2154 |
return isJunction(leftMax, leftSecond); |
| 2155 |
} |
| 2156 |
|
| 2157 |
|
| 2158 |
protected final boolean isJunction(int max, int second){ |
| 2159 |
if(second<1 || second*branchMult1<max || (second<=branchLowerConst && max>=Tools.max(minCountExtend, second*branchMult2))){ |
| 2160 |
return false; |
| 2161 |
} |
| 2162 |
if(verbose){outstream.println("Breaking because second-highest was too high:\n" + |
| 2163 |
"max="+max+", second="+second+", branchMult1="+branchMult1+"\n" + |
| 2164 |
"branchLowerConst="+branchLowerConst+", minCountExtend="+minCountExtend+", branchMult2="+branchMult2+"\n" + |
| 2165 |
(second*branchMult1<max)+", "+(second<=branchLowerConst)+", "+(max>=Tools.max(minCountExtend, second*branchMult2)));} |
| 2166 |
return true; |
| 2167 |
} |
| 2168 |
|
| 2169 |
float calcRatio(int[] counts){ |
| 2170 |
int a=0, b=0; |
| 2171 |
for(int i=0; i<counts.length; i++){ |
| 2172 |
int x=counts[i]; |
| 2173 |
if(x>a){ |
| 2174 |
b=a; |
| 2175 |
a=x; |
| 2176 |
}else if(x>b){ |
| 2177 |
b=x; |
| 2178 |
} |
| 2179 |
} |
| 2180 |
return (b<1 ? 99f : ((float)a)/b); |
| 2181 |
} |
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
private final class DumpKmersThread extends Thread { |
| 2188 |
|
| 2189 |
DumpKmersThread(){} |
| 2190 |
|
| 2191 |
@Override |
| 2192 |
public void run(){ |
| 2193 |
dumpKmersAsText(); |
| 2194 |
} |
| 2195 |
|
| 2196 |
} |
| 2197 |
|
| 2198 |
private final class MakeKhistThread extends Thread { |
| 2199 |
|
| 2200 |
MakeKhistThread(){} |
| 2201 |
|
| 2202 |
@Override |
| 2203 |
public void run(){ |
| 2204 |
makeKhist(); |
| 2205 |
} |
| 2206 |
} |
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
public abstract AbstractKmerTableSet tables(); |
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
final int kbig; |
| 2217 |
public final int k(){return kbig;} |
| 2218 |
|
| 2219 |
private ArrayList<Contig> allContigs; |
| 2220 |
private LongList allInserts; |
| 2221 |
private long contigsBuilt=0; |
| 2222 |
private long basesBuilt=0; |
| 2223 |
private long longestContig=0; |
| 2224 |
|
| 2225 |
protected boolean extendThroughLeftJunctions=true; |
| 2226 |
|
| 2227 |
private boolean removeBubbles=false; |
| 2228 |
private boolean removeDeadEnds=false; |
| 2229 |
private boolean setShave=false; |
| 2230 |
private boolean setRinse=false; |
| 2231 |
protected int maxShaveDepth=1; |
| 2232 |
protected int shaveDiscardLen=150; |
| 2233 |
protected int shaveExploreDist=300; |
| 2234 |
|
| 2235 |
protected int kmerRangeMin=0; |
| 2236 |
protected int kmerRangeMax=Integer.MAX_VALUE; |
| 2237 |
|
| 2238 |
protected int processingMode=-1; |
| 2239 |
|
| 2240 |
protected int extendLeft=-1; |
| 2241 |
protected int extendRight=-1; |
| 2242 |
protected int extensionRollback=3; |
| 2243 |
|
| 2244 |
|
| 2245 |
public final boolean useOwnership; |
| 2246 |
|
| 2247 |
public int maxContigLen=1000000000; |
| 2248 |
public int minExtension=2; |
| 2249 |
public int minContigLen=-1; |
| 2250 |
public float minCoverage=1; |
| 2251 |
public float maxCoverage=Float.MAX_VALUE; |
| 2252 |
public boolean joinContigs; |
| 2253 |
|
| 2254 |
int trimEnds=0; |
| 2255 |
boolean trimCircular=true; |
| 2256 |
|
| 2257 |
int minCountSeed=3; |
| 2258 |
|
| 2259 |
protected int minCountExtend=2; |
| 2260 |
protected float branchMult1=20; |
| 2261 |
protected float branchMult2=3; |
| 2262 |
private int branchLowerConst=3; |
| 2263 |
|
| 2264 |
private int errorPath=1; |
| 2265 |
private float errorMult1=16; |
| 2266 |
private float errorMult2=2.6f; |
| 2267 |
private float errorMultQFactor=0.002f; |
| 2268 |
private int errorLowerConst=4; |
| 2269 |
private int minCountCorrect=3; |
| 2270 |
int minCountCorrect(){return minCountCorrect;} |
| 2271 |
private int pathSimilarityConstant=3; |
| 2272 |
private float pathSimilarityFraction=0.45f; |
| 2273 |
protected int errorExtensionReassemble=5; |
| 2274 |
protected int errorExtensionPincer=5; |
| 2275 |
protected int errorExtensionTail=9; |
| 2276 |
protected int deadZone=0; |
| 2277 |
protected int windowLen=12; |
| 2278 |
protected int windowCount=6; |
| 2279 |
protected int windowQualSum=80; |
| 2280 |
protected int windowCountHQ=2; |
| 2281 |
protected byte windowHQThresh=24; |
| 2282 |
|
| 2283 |
protected byte qIncreasePincer=8; |
| 2284 |
protected byte qMinPincer=24; |
| 2285 |
protected byte qMaxPincer=32; |
| 2286 |
|
| 2287 |
protected byte qIncreaseTail=4; |
| 2288 |
protected byte qMinTail=20; |
| 2289 |
protected byte qMaxTail=28; |
| 2290 |
|
| 2291 |
|
| 2292 |
public boolean showStats=true; |
| 2293 |
|
| 2294 |
|
| 2295 |
public boolean errorState=false; |
| 2296 |
|
| 2297 |
|
| 2298 |
private ArrayList<String> in1=new ArrayList<String>(), in2=new ArrayList<String>(); |
| 2299 |
|
| 2300 |
private ArrayList<String> out1=new ArrayList<String>(), out2=new ArrayList<String>(); |
| 2301 |
|
| 2302 |
private ArrayList<String> outd1=new ArrayList<String>(), outd2=new ArrayList<String>(); |
| 2303 |
|
| 2304 |
private String outDot=null; |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
private String outInsert=null; |
| 2313 |
|
| 2314 |
protected String outKmers=null; |
| 2315 |
|
| 2316 |
protected String outHist=null; |
| 2317 |
|
| 2318 |
protected boolean gcHist=false; |
| 2319 |
|
| 2320 |
|
| 2321 |
protected int histColumns=2; |
| 2322 |
|
| 2323 |
protected int histMax=100000; |
| 2324 |
|
| 2325 |
protected boolean histHeader=true; |
| 2326 |
|
| 2327 |
protected boolean histZeros=false; |
| 2328 |
|
| 2329 |
protected boolean smoothHist=false; |
| 2330 |
|
| 2331 |
|
| 2332 |
private long maxReads=-1; |
| 2333 |
|
| 2334 |
long edgesMade=0; |
| 2335 |
long readsIn=0; |
| 2336 |
long basesIn=0; |
| 2337 |
long readsOut=0; |
| 2338 |
long basesOut=0; |
| 2339 |
long lowqReads=0; |
| 2340 |
long lowqBases=0; |
| 2341 |
long basesExtended=0; |
| 2342 |
long readsExtended=0; |
| 2343 |
long readsCorrected=0; |
| 2344 |
long basesCorrectedPincer=0; |
| 2345 |
long basesCorrectedTail=0; |
| 2346 |
long basesCorrectedReassemble=0; |
| 2347 |
long readsFullyCorrected=0; |
| 2348 |
long rollbacks=0; |
| 2349 |
long readsDetected=0; |
| 2350 |
long basesDetected=0; |
| 2351 |
long readsMarked=0; |
| 2352 |
long basesMarked=0; |
| 2353 |
long readsDiscarded=0; |
| 2354 |
long basesDiscarded=0; |
| 2355 |
|
| 2356 |
long readsMerged=0; |
| 2357 |
long readsCorrectedEcco=0; |
| 2358 |
long basesCorrectedEcco=0; |
| 2359 |
|
| 2360 |
protected boolean ECC_PINCER=false; |
| 2361 |
protected boolean ECC_TAIL=false; |
| 2362 |
protected boolean ECC_ALL=false; |
| 2363 |
protected boolean ECC_REASSEMBLE=true; |
| 2364 |
protected boolean ECC_AGGRESSIVE=false; |
| 2365 |
protected boolean ECC_CONSERVATIVE=false; |
| 2366 |
protected boolean ECC_ROLLBACK=true; |
| 2367 |
protected boolean ECC_REQUIRE_BIDIRECTIONAL=true; |
| 2368 |
|
| 2369 |
|
| 2370 |
protected int MARK_BAD_BASES=0; |
| 2371 |
|
| 2372 |
protected boolean MARK_DELTA_ONLY=true; |
| 2373 |
|
| 2374 |
protected boolean MARK_ERROR_READS_ONLY=true; |
| 2375 |
|
| 2376 |
protected byte MARK_QUALITY=0; |
| 2377 |
|
| 2378 |
|
| 2379 |
protected boolean tossJunk=false; |
| 2380 |
|
| 2381 |
|
| 2382 |
protected int discardLowDepthReads=-1; |
| 2383 |
|
| 2384 |
|
| 2385 |
protected float lowDepthDiscardFraction=0f; |
| 2386 |
|
| 2387 |
|
| 2388 |
protected boolean requireBothBad=false; |
| 2389 |
|
| 2390 |
|
| 2391 |
protected boolean discardUncorrectable=false; |
| 2392 |
|
| 2393 |
|
| 2394 |
boolean processContigs=false; |
| 2395 |
|
| 2396 |
|
| 2397 |
boolean popBubbles=true; |
| 2398 |
|
| 2399 |
int bubblePasses=1; |
| 2400 |
|
| 2401 |
|
| 2402 |
boolean expandTandemRepeats=false; |
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
protected final void initializeThreadLocals(){ |
| 2409 |
if(localLeftCounts.get()!=null){return;} |
| 2410 |
localLeftCounts.set(new int[4]); |
| 2411 |
localRightCounts.set(new int[4]); |
| 2412 |
localExtraCounts.set(new int[4]); |
| 2413 |
localLongList.set(new LongList()); |
| 2414 |
localIntList.set(new IntList()); |
| 2415 |
localIntList2.set(new IntList()); |
| 2416 |
localByteBuilder.set(new ByteBuilder()); |
| 2417 |
localByteBuilder2.set(new ByteBuilder()); |
| 2418 |
localBitSet.set(new BitSet(300)); |
| 2419 |
localKmer.set(new Kmer(kbig)); |
| 2420 |
localKmer2.set(new Kmer(kbig)); |
| 2421 |
localTracker.set(new ErrorTracker()); |
| 2422 |
} |
| 2423 |
|
| 2424 |
protected ThreadLocal<int[]> localLeftCounts=new ThreadLocal<int[]>(); |
| 2425 |
protected ThreadLocal<int[]> localRightCounts=new ThreadLocal<int[]>(); |
| 2426 |
protected ThreadLocal<int[]> localExtraCounts=new ThreadLocal<int[]>(); |
| 2427 |
protected ThreadLocal<LongList> localLongList=new ThreadLocal<LongList>(); |
| 2428 |
protected ThreadLocal<IntList> localIntList=new ThreadLocal<IntList>(); |
| 2429 |
protected ThreadLocal<IntList> localIntList2=new ThreadLocal<IntList>(); |
| 2430 |
protected ThreadLocal<ByteBuilder> localByteBuilder=new ThreadLocal<ByteBuilder>(); |
| 2431 |
protected ThreadLocal<ByteBuilder> localByteBuilder2=new ThreadLocal<ByteBuilder>(); |
| 2432 |
protected ThreadLocal<BitSet> localBitSet=new ThreadLocal<BitSet>(); |
| 2433 |
private ThreadLocal<Kmer> localKmer=new ThreadLocal<Kmer>(); |
| 2434 |
private ThreadLocal<Kmer> localKmer2=new ThreadLocal<Kmer>(); |
| 2435 |
protected ThreadLocal<ErrorTracker> localTracker=new ThreadLocal<ErrorTracker>(); |
| 2436 |
|
| 2437 |
protected Kmer getLocalKmer(){ |
| 2438 |
Kmer local=localKmer.get(); |
| 2439 |
local.clearFast(); |
| 2440 |
return local; |
| 2441 |
} |
| 2442 |
|
| 2443 |
protected Kmer getLocalKmer2(){ |
| 2444 |
Kmer local=localKmer2.get(); |
| 2445 |
local.clearFast(); |
| 2446 |
return local; |
| 2447 |
} |
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
protected int minToDump=1; |
| 2455 |
|
| 2456 |
|
| 2457 |
protected int maxToDump=Integer.MAX_VALUE; |
| 2458 |
|
| 2459 |
|
| 2460 |
final boolean ecc; |
| 2461 |
|
| 2462 |
|
| 2463 |
final boolean ecco; |
| 2464 |
|
| 2465 |
|
| 2466 |
final boolean vstrict; |
| 2467 |
|
| 2468 |
|
| 2469 |
final boolean merge; |
| 2470 |
|
| 2471 |
|
| 2472 |
final boolean testMerge; |
| 2473 |
int testMergeWidth=4; |
| 2474 |
long testMergeMult=80L; |
| 2475 |
int testMergeThresh=3; |
| 2476 |
|
| 2477 |
|
| 2478 |
final AtomicLong contigNum=new AtomicLong(0); |
| 2479 |
|
| 2480 |
int bubblesPopped=0; |
| 2481 |
|
| 2482 |
int contigPasses=16; |
| 2483 |
double contigPassMult=1.7; |
| 2484 |
|
| 2485 |
|
| 2486 |
final AtomicInteger nextTable[]; |
| 2487 |
|
| 2488 |
|
| 2489 |
final AtomicInteger nextVictims[]; |
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
public static boolean overwrite=true; |
| 2497 |
|
| 2498 |
public static boolean append=false; |
| 2499 |
|
| 2500 |
public static boolean ordered=false; |
| 2501 |
|
| 2502 |
public static boolean showSpeed=true; |
| 2503 |
|
| 2504 |
public static boolean DISPLAY_PROGRESS=true; |
| 2505 |
|
| 2506 |
public static int THREADS=Shared.threads(); |
| 2507 |
|
| 2508 |
public static int BUILD_THREADS=-1; |
| 2509 |
|
| 2510 |
private static final boolean GC_BEFORE_PRINT_MEMORY=false; |
| 2511 |
|
| 2512 |
static boolean IGNORE_BAD_OWNER=false; |
| 2513 |
static boolean FORCE_TADPOLE2=false; |
| 2514 |
|
| 2515 |
} |