| 1 |
package sketch; |
| 2 |
|
| 3 |
import java.io.PrintStream; |
| 4 |
import java.util.ArrayList; |
| 5 |
import java.util.Arrays; |
| 6 |
import java.util.Collections; |
| 7 |
import java.util.Random; |
| 8 |
|
| 9 |
import aligner.SingleStateAlignerFlat2; |
| 10 |
import aligner.SingleStateAlignerFlatFloat; |
| 11 |
import dna.AminoAcid; |
| 12 |
import dna.Data; |
| 13 |
import prok.GeneCaller; |
| 14 |
import prok.GeneModel; |
| 15 |
import prok.GeneModelParser; |
| 16 |
import prok.ProkObject; |
| 17 |
import shared.Parse; |
| 18 |
import shared.Shared; |
| 19 |
import shared.Timer; |
| 20 |
import shared.Tools; |
| 21 |
import stream.Read; |
| 22 |
import structures.IntList3; |
| 23 |
import tax.TaxTree; |
| 24 |
import tracker.EntropyTracker; |
| 25 |
|
| 26 |
public class SketchObject { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public static void main(String[] args){ |
| 33 |
Timer t=new Timer(); |
| 34 |
for(int i=0; i<1000000; i++){ |
| 35 |
wkidToAniExact(0.5, 32, 23, 0.000005); |
| 36 |
} |
| 37 |
t.stop(); |
| 38 |
System.out.println(t); |
| 39 |
} |
| 40 |
|
| 41 |
public static boolean parseSketchFlags(String arg, String a, String b){ |
| 42 |
|
| 43 |
if(parseCoding(arg, a, b)){ |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
else if(a.equalsIgnoreCase("k")){ |
| 48 |
if(b.indexOf(',')>=0){ |
| 49 |
String[] split=b.split(","); |
| 50 |
assert(split.length==2) : "Bad argument "+arg; |
| 51 |
int x=Integer.parseInt(split[0]); |
| 52 |
int y=Integer.parseInt(split[1]); |
| 53 |
k=Tools.max(x, y); |
| 54 |
k2=Tools.min(x, y); |
| 55 |
if(k==k2){k2=0;} |
| 56 |
}else{ |
| 57 |
k=Integer.parseInt(b); |
| 58 |
k2=0; |
| 59 |
} |
| 60 |
setK=true; |
| 61 |
}else if(a.equalsIgnoreCase("rcomp")){ |
| 62 |
rcomp=Parse.parseBoolean(b); |
| 63 |
}else if(a.equalsIgnoreCase("minfakeid")){ |
| 64 |
minFakeID=Integer.parseInt(b); |
| 65 |
}else if(a.equalsIgnoreCase("hashNames")){ |
| 66 |
hashNames=Parse.parseBoolean(b); |
| 67 |
}else if(a.equalsIgnoreCase("preferSSUMap")){ |
| 68 |
preferSSUMap=Parse.parseBoolean(b); |
| 69 |
}else if(a.equalsIgnoreCase("preferSSUMapForEuks") || a.equalsIgnoreCase("preferSSUMapEuks")){ |
| 70 |
preferSSUMapForEuks=Parse.parseBoolean(b); |
| 71 |
}else if(a.equalsIgnoreCase("useSSUMapOnly")){ |
| 72 |
useSSUMapOnly=Parse.parseBoolean(b); |
| 73 |
}else if(a.equalsIgnoreCase("useSSUMapOnlyForEuks") || a.equalsIgnoreCase("SSUMapOnlyEuks")){ |
| 74 |
useSSUMapOnlyForEuks=Parse.parseBoolean(b); |
| 75 |
}else if(a.equalsIgnoreCase("skipNonCanonical")){ |
| 76 |
skipNonCanonical=Parse.parseBoolean(b); |
| 77 |
}else if(a.equalsIgnoreCase("useSizeEstimateInScore") || a.equalsIgnoreCase("useSizeEstimate")){ |
| 78 |
useSizeEstimate=Parse.parseBoolean(b); |
| 79 |
}else if(a.equalsIgnoreCase("blacklist") || a.equalsIgnoreCase("bl")){ |
| 80 |
blacklist=b; |
| 81 |
}else if(a.equalsIgnoreCase("whitelist") || a.equalsIgnoreCase("usewhitelist")){ |
| 82 |
useWhitelist=Parse.parseBoolean(b); |
| 83 |
} |
| 84 |
|
| 85 |
else if(a.equalsIgnoreCase("sampleseed")){ |
| 86 |
sampleseed=Long.parseLong(b); |
| 87 |
} |
| 88 |
|
| 89 |
else if(a.equalsIgnoreCase("size") || a.equalsIgnoreCase("sketchsize")){ |
| 90 |
if("auto".equalsIgnoreCase(b)){ |
| 91 |
AUTOSIZE=true; |
| 92 |
AUTOSIZE_LINEAR=false; |
| 93 |
SET_AUTOSIZE=true; |
| 94 |
}else if("linear".equalsIgnoreCase(b)){ |
| 95 |
AUTOSIZE=false; |
| 96 |
AUTOSIZE_LINEAR=true; |
| 97 |
SET_AUTOSIZE=true; |
| 98 |
}else{ |
| 99 |
AUTOSIZE=false; |
| 100 |
AUTOSIZE_LINEAR=false; |
| 101 |
targetSketchSize=Parse.parseIntKMG(b); |
| 102 |
SET_TARGET_SIZE=true; |
| 103 |
} |
| 104 |
}else if(a.equalsIgnoreCase("maxfraction") || a.equalsIgnoreCase("maxgenomefraction") || a.equalsIgnoreCase("mgf")){ |
| 105 |
maxGenomeFraction=Float.parseFloat(b); |
| 106 |
}else if(a.equalsIgnoreCase("smallsketchsize")){ |
| 107 |
smallSketchSize=Integer.parseInt(b); |
| 108 |
}else if(a.equalsIgnoreCase("minSketchSize")){ |
| 109 |
minSketchSize=Tools.max(1, Integer.parseInt(b)); |
| 110 |
}else if(a.equalsIgnoreCase("autosize")){ |
| 111 |
AUTOSIZE=Parse.parseBoolean(b); |
| 112 |
if(AUTOSIZE){AUTOSIZE_LINEAR=false;} |
| 113 |
SET_AUTOSIZE=true; |
| 114 |
}else if(a.equalsIgnoreCase("autosizefactor") || a.equalsIgnoreCase("autosizefraction") || a.equalsIgnoreCase("autosizemult") || a.equalsIgnoreCase("sizemult")){ |
| 115 |
AUTOSIZE_FACTOR=Float.parseFloat(b); |
| 116 |
SET_AUTOSIZE_FACTOR=true; |
| 117 |
AUTOSIZE_LINEAR=false; |
| 118 |
SET_AUTOSIZE=true; |
| 119 |
}else if(a.equalsIgnoreCase("linear") || a.equalsIgnoreCase("lineardensity") || a.equalsIgnoreCase("density")){ |
| 120 |
if(Tools.isNumeric(b)){ |
| 121 |
AUTOSIZE_LINEAR_DENSITY=Double.parseDouble(b); |
| 122 |
AUTOSIZE_LINEAR=true; |
| 123 |
AUTOSIZE=false; |
| 124 |
SET_AUTOSIZE=true; |
| 125 |
}else{ |
| 126 |
AUTOSIZE_LINEAR=Parse.parseBoolean(b); |
| 127 |
if(AUTOSIZE_LINEAR){AUTOSIZE=false;} |
| 128 |
SET_AUTOSIZE=true; |
| 129 |
} |
| 130 |
}else if(a.equalsIgnoreCase("maxGenomeFractionSmall")){ |
| 131 |
maxGenomeFractionSmall=Float.parseFloat(b); |
| 132 |
}else if(a.equalsIgnoreCase("keyFraction")){ |
| 133 |
double d=Double.parseDouble(b); |
| 134 |
setKeyFraction(d); |
| 135 |
}else if(a.equalsIgnoreCase("prealloc")){ |
| 136 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 137 |
if(Parse.parseBoolean(b)){ |
| 138 |
prealloc=1.0f; |
| 139 |
}else{ |
| 140 |
prealloc=0; |
| 141 |
} |
| 142 |
}else{ |
| 143 |
prealloc=Float.parseFloat(b); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
else if(a.equalsIgnoreCase("intmap")){ |
| 148 |
SketchIndex.useIntMap=Parse.parseBoolean(b); |
| 149 |
}else if(a.equalsIgnoreCase("intmapsize")){ |
| 150 |
SketchIndex.intMapSize=Parse.parseIntKMG(b); |
| 151 |
}else if(a.equalsIgnoreCase("bitsetbits")){ |
| 152 |
assert(false) : "bitsetbits should be 2."; |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
else if(a.equalsIgnoreCase("sketchHeapFactor")){ |
| 160 |
sketchHeapFactor=Tools.max(1.0, Double.parseDouble(b)); |
| 161 |
} |
| 162 |
|
| 163 |
else if(a.equalsIgnoreCase("killok")){ |
| 164 |
KILL_OK=Parse.parseBoolean(b); |
| 165 |
}else if(a.equalsIgnoreCase("ssa") || a.equalsIgnoreCase("usessa")){ |
| 166 |
useSSA=Parse.parseBoolean(b); |
| 167 |
}else if(a.equalsIgnoreCase("ssa3") || a.equalsIgnoreCase("usessa3")){ |
| 168 |
useSSA3=Parse.parseBoolean(b); |
| 169 |
}else if(a.equalsIgnoreCase("exactani")){ |
| 170 |
EXACT_ANI=Parse.parseBoolean(b); |
| 171 |
}else if(a.equalsIgnoreCase("translate") || a.equalsIgnoreCase("callgenes")){ |
| 172 |
translate=Parse.parseBoolean(b); |
| 173 |
defaultParams.translate=translate; |
| 174 |
}else if(a.equalsIgnoreCase("sixframes") || a.equalsIgnoreCase("6frames")){ |
| 175 |
sixframes=Parse.parseBoolean(b); |
| 176 |
defaultParams.sixframes=sixframes; |
| 177 |
if(sixframes){ |
| 178 |
translate=defaultParams.translate=true; |
| 179 |
} |
| 180 |
}else if(a.equalsIgnoreCase("processSSU") || a.equalsIgnoreCase("process16S") || a.equalsIgnoreCase("16S") || a.equalsIgnoreCase("SSU")){ |
| 181 |
processSSU=Parse.parseBoolean(b); |
| 182 |
}else if(a.equalsIgnoreCase("hashSeed")){ |
| 183 |
hashSeed=Long.parseLong(b); |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
else if(a.equalsIgnoreCase("forceDisableMultithreadedFastq")){ |
| 188 |
forceDisableMultithreadedFastq=Parse.parseBoolean(b); |
| 189 |
} |
| 190 |
|
| 191 |
else if(a.equalsIgnoreCase("verifyentropy")){ |
| 192 |
EntropyTracker.verify=Parse.parseBoolean(b); |
| 193 |
}else if(a.equalsIgnoreCase("entropyK")){ |
| 194 |
entropyK=Integer.parseInt(b); |
| 195 |
}else if(a.equalsIgnoreCase("fastentropy") || a.equalsIgnoreCase("fentropy")){ |
| 196 |
if(Parse.parseBoolean(b)){EntropyTracker.speed=EntropyTracker.FAST;} |
| 197 |
}else if(a.equalsIgnoreCase("mediumentropy") || a.equalsIgnoreCase("mentropy")){ |
| 198 |
if(Parse.parseBoolean(b)){EntropyTracker.speed=EntropyTracker.MEDIUM;} |
| 199 |
}else if(a.equalsIgnoreCase("slowentropy") || a.equalsIgnoreCase("sentropy")){ |
| 200 |
if(Parse.parseBoolean(b)){EntropyTracker.speed=EntropyTracker.SLOW;} |
| 201 |
}else if(a.equalsIgnoreCase("superslowentropy") || a.equalsIgnoreCase("ssentropy")){ |
| 202 |
if(Parse.parseBoolean(b)){EntropyTracker.speed=EntropyTracker.SUPERSLOW;} |
| 203 |
}else if(a.equalsIgnoreCase("verbose2")){ |
| 204 |
verbose2=Parse.parseBoolean(b); |
| 205 |
}else if(a.equalsIgnoreCase("loadSketchesFromSketchFile2")){ |
| 206 |
LOADER2=Parse.parseBoolean(b); |
| 207 |
} |
| 208 |
|
| 209 |
else if(a.equalsIgnoreCase("useToValue2") || a.equalsIgnoreCase("ToValue2")){ |
| 210 |
useToValue2=Parse.parseBoolean(b); |
| 211 |
}else if(a.equals("ssu") || a.equals("ssufile")){ |
| 212 |
assert(false) : "ssufile is deprecated; please specify 16Sfile and/or 18Sfile independently"; |
| 213 |
}else if(a.equalsIgnoreCase("16Sfile")){ |
| 214 |
SSUMap.r16SFile=b; |
| 215 |
if("auto".equalsIgnoreCase(SSUMap.r16SFile)){SSUMap.r16SFile=TaxTree.default16SFile();} |
| 216 |
assert(SSUMap.r16SMap==null); |
| 217 |
}else if(a.equalsIgnoreCase("18Sfile")){ |
| 218 |
SSUMap.r18SFile=b; |
| 219 |
if("auto".equalsIgnoreCase(SSUMap.r18SFile)){SSUMap.r18SFile=TaxTree.default18SFile();} |
| 220 |
assert(SSUMap.r18SMap==null); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
else{ |
| 228 |
return false; |
| 229 |
} |
| 230 |
return true; |
| 231 |
} |
| 232 |
|
| 233 |
private static boolean parseCoding(String arg, String a, String b){ |
| 234 |
if(a.equalsIgnoreCase("deltaout") || a.equalsIgnoreCase("delta")){ |
| 235 |
deltaOut=Parse.parseBoolean(b); |
| 236 |
}else if(a.equalsIgnoreCase("a33") || a.equalsIgnoreCase("a48")){ |
| 237 |
boolean x=Parse.parseBoolean(b); |
| 238 |
if(x){CODING=A48;} |
| 239 |
else if(CODING==A48){CODING=HEX;} |
| 240 |
}else if(a.equalsIgnoreCase("hex")){ |
| 241 |
boolean x=Parse.parseBoolean(b); |
| 242 |
if(x){CODING=HEX;} |
| 243 |
else if(CODING==HEX){CODING=A48;} |
| 244 |
}else if(a.equalsIgnoreCase("raw")){ |
| 245 |
boolean x=Parse.parseBoolean(b); |
| 246 |
if(x){CODING=RAW;} |
| 247 |
else if(CODING==RAW){CODING=A48;} |
| 248 |
}else{ |
| 249 |
return false; |
| 250 |
} |
| 251 |
return true; |
| 252 |
} |
| 253 |
|
| 254 |
static int parseMode(String[] args){ |
| 255 |
int mode=defaultParams.mode; |
| 256 |
for(String arg : args){ |
| 257 |
String[] split=arg.split("="); |
| 258 |
String a=split[0].toLowerCase(); |
| 259 |
String b=split.length>1 ? split[1] : null; |
| 260 |
int x=parseMode(arg, a, b); |
| 261 |
if(x>-1){mode=x;} |
| 262 |
} |
| 263 |
return mode; |
| 264 |
} |
| 265 |
|
| 266 |
static int parseMode(String arg, String a, String b){ |
| 267 |
int mode_=-1; |
| 268 |
if(a.equalsIgnoreCase("mode")){ |
| 269 |
assert(b!=null) : "Bad parameter: "+arg; |
| 270 |
if(Tools.isDigit(b.charAt(0))){ |
| 271 |
mode_=Integer.parseInt(b); |
| 272 |
}else if(b.equalsIgnoreCase("single") || b.equalsIgnoreCase("onesketch")){ |
| 273 |
mode_=ONE_SKETCH; |
| 274 |
}else if(b.equalsIgnoreCase("taxa") || b.equalsIgnoreCase("pertaxa")){ |
| 275 |
mode_=PER_TAXA; |
| 276 |
}else if(b.equalsIgnoreCase("sequence") || b.equalsIgnoreCase("persequence") || b.equalsIgnoreCase("header") || b.equalsIgnoreCase("perheader")){ |
| 277 |
mode_=PER_SEQUENCE; |
| 278 |
|
| 279 |
|
| 280 |
}else if(b.equalsIgnoreCase("img")){ |
| 281 |
mode_=PER_IMG; |
| 282 |
}else if(b.equalsIgnoreCase("perfile") || b.equalsIgnoreCase("file")){ |
| 283 |
mode_=PER_FILE; |
| 284 |
}else{ |
| 285 |
assert(false) : "Bad parameter: "+arg; |
| 286 |
} |
| 287 |
}else if(a.equalsIgnoreCase("single") || a.equalsIgnoreCase("onesketch")){ |
| 288 |
mode_=ONE_SKETCH; |
| 289 |
}else if(a.equalsIgnoreCase("taxa") || a.equalsIgnoreCase("pertaxa")){ |
| 290 |
mode_=PER_TAXA; |
| 291 |
}else if(a.equalsIgnoreCase("sequence") || a.equalsIgnoreCase("persequence") || a.equalsIgnoreCase("header") || a.equalsIgnoreCase("perheader")){ |
| 292 |
mode_=PER_SEQUENCE; |
| 293 |
|
| 294 |
|
| 295 |
}else if(a.equalsIgnoreCase("perfile") || a.equalsIgnoreCase("file")){ |
| 296 |
mode_=PER_FILE; |
| 297 |
} |
| 298 |
return mode_; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
static synchronized void setTaxtree(String taxTreeFile, PrintStream outstream){ |
| 306 |
if(taxTreeFile==null){ |
| 307 |
taxtree=null; |
| 308 |
return; |
| 309 |
} |
| 310 |
if(treefile!=null){ |
| 311 |
assert(!treefile.equals(taxTreeFile)); |
| 312 |
if(treefile.equals(taxTreeFile)){return;} |
| 313 |
treefile=taxTreeFile; |
| 314 |
} |
| 315 |
taxtree=TaxTree.loadTaxTree(taxTreeFile, outstream, hashNames, false); |
| 316 |
} |
| 317 |
|
| 318 |
public static void reset(){ |
| 319 |
postparsed=false; |
| 320 |
blacklist=null; |
| 321 |
useWhitelist=false; |
| 322 |
defaultParams=new DisplayParams(); |
| 323 |
amino=false; |
| 324 |
translate=false; |
| 325 |
sixframes=false; |
| 326 |
} |
| 327 |
|
| 328 |
public static void postParse(){ |
| 329 |
if(postparsed){return;} |
| 330 |
postparsed=true; |
| 331 |
IntList3.defaultMode=IntList3.UNIQUE; |
| 332 |
|
| 333 |
if(defaultParams.amino()){amino=true;} |
| 334 |
if(amino){Shared.AMINO_IN=true;} |
| 335 |
|
| 336 |
if(amino8){ |
| 337 |
AminoAcid.AMINO_SHIFT=3; |
| 338 |
System.err.println("Set AMINO_SHIFT to "+AminoAcid.AMINO_SHIFT); |
| 339 |
} |
| 340 |
|
| 341 |
if(amino || translate){ |
| 342 |
rcomp=false; |
| 343 |
if(k>12){ |
| 344 |
int oldk=k; |
| 345 |
int oldk2=k2; |
| 346 |
|
| 347 |
|
| 348 |
k=defaultKAmino; |
| 349 |
k2=defaultK2Amino; |
| 350 |
if(k==k2){k2=0;} |
| 351 |
if(k!=oldk || k2!=oldk2){System.err.println("Set k to "+k+(k2>0 ? ","+k2 : ""));} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
} |
| 356 |
|
| 357 |
if(aminoOrTranslate()){ |
| 358 |
bitsPerBase=5; |
| 359 |
bitsPerCycle=10; |
| 360 |
}else{ |
| 361 |
bitsPerBase=2; |
| 362 |
bitsPerCycle=8; |
| 363 |
} |
| 364 |
basesPerCycle=bitsPerCycle/bitsPerBase; |
| 365 |
hashCycles=((k*bitsPerBase)+bitsPerCycle-1)/bitsPerCycle; |
| 366 |
|
| 367 |
cycleMask=~((-1L)<<bitsPerCycle); |
| 368 |
maxCycles=(64+bitsPerCycle-1)/bitsPerCycle; |
| 369 |
codeIncrement=(int)(cycleMask+1); |
| 370 |
codes=makeCodes(maxCycles, codeIncrement, hashSeed, false); |
| 371 |
codes1D=makeCodes1D(codes); |
| 372 |
|
| 373 |
if(k2>0){ |
| 374 |
assert(k2<k) : "k2 must be less than k."; |
| 375 |
|
| 376 |
|
| 377 |
k2mask=~((-1L)<<(bitsPerBase*k2)); |
| 378 |
k2submask=~((-1L)<<(bitsPerBase*(k2%basesPerCycle))); |
| 379 |
k2shift=(k-k2); |
| 380 |
k2midmask=(k2mask<<((k2shift*bitsPerBase)/2)); |
| 381 |
hashCycles2=k2/basesPerCycle; |
| 382 |
}else{ |
| 383 |
useToValue2=false; |
| 384 |
} |
| 385 |
codeMax=hashCycles*codeIncrement; |
| 386 |
codeMax2=hashCycles2*codeIncrement; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
if(translate || processSSU){ |
| 391 |
if(pgmFile==null){ |
| 392 |
pgmFile=Data.findPath("?model.pgm"); |
| 393 |
} |
| 394 |
pgm=GeneModelParser.loadModel(pgmFile); |
| 395 |
GeneCaller.call16S=processSSU; |
| 396 |
GeneCaller.call18S=false; |
| 397 |
GeneCaller.call23S=false; |
| 398 |
GeneCaller.call5S=false; |
| 399 |
GeneCaller.calltRNA=false; |
| 400 |
GeneCaller.callCDS=translate; |
| 401 |
|
| 402 |
if(GeneCaller.call16S || GeneCaller.call18S || GeneCaller.call23S){ |
| 403 |
ProkObject.loadLongKmers(); |
| 404 |
ProkObject.loadConsensusSequenceFromFile(true, true); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
if(blacklist!=null){Blacklist.addFiles(blacklist);} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
alignerPool=new AlignmentThreadPool(Shared.threads()); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
private static void remakeCodes(long hashSeed){ |
| 426 |
long[][] codes2=makeCodes(maxCycles, codeIncrement, hashSeed, false); |
| 427 |
long[] codes1D2=makeCodes1D(codes2); |
| 428 |
for(int i=0; i<codes2.length; i++){ |
| 429 |
for(int j=0; j<codes2[i].length; j++){ |
| 430 |
codes[i][j]=codes2[i][j]; |
| 431 |
} |
| 432 |
} |
| 433 |
for(int i=0; i<codes1D2.length; i++){ |
| 434 |
codes1D[i]=codes1D2[i]; |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
public static long[][] makeCodes(int symbols, int modes, long seed, boolean positive){ |
| 439 |
Random randy=new Random(seed); |
| 440 |
long mask=positive ? Long.MAX_VALUE : -1L; |
| 441 |
long[][] r=new long[symbols][modes]; |
| 442 |
for(int i=0; i<symbols; i++){ |
| 443 |
for(int j=0; j<modes; j++){ |
| 444 |
r[i][j]=randy.nextLong()&mask; |
| 445 |
} |
| 446 |
} |
| 447 |
for(int i=0; i<3; i++) { |
| 448 |
antialias(r, randy); |
| 449 |
} |
| 450 |
return r; |
| 451 |
} |
| 452 |
|
| 453 |
private static void antialias(long[][] matrix, Random randy){ |
| 454 |
for(long[] array : matrix){ |
| 455 |
antialias(array, randy); |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
private static void antialias(long[] array, Random randy){ |
| 460 |
for(int i=0; i<64; i++){ |
| 461 |
antialiasNumbers(array, randy); |
| 462 |
antialiasBit(array, randy, i); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
private static void antialiasBit(long[] array, Random randy, int bit){ |
| 467 |
int half=array.length/2; |
| 468 |
long ones=0; |
| 469 |
for(int i=0; i<array.length; i++){ |
| 470 |
ones+=(array[i]>>bit)&1L; |
| 471 |
} |
| 472 |
final long orMask=1L<<bit; |
| 473 |
final long andMask=~orMask; |
| 474 |
while(ones<half-1){ |
| 475 |
int loc=randy.nextInt(array.length); |
| 476 |
while((array[loc]&orMask)!=0){ |
| 477 |
loc=randy.nextInt(array.length); |
| 478 |
} |
| 479 |
array[loc]|=orMask; |
| 480 |
ones++; |
| 481 |
} |
| 482 |
while(ones>half+1){ |
| 483 |
int loc=randy.nextInt(array.length); |
| 484 |
while((array[loc]&orMask)==0){ |
| 485 |
loc=randy.nextInt(array.length); |
| 486 |
} |
| 487 |
array[loc]&=andMask; |
| 488 |
ones--; |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
private static void antialiasNumbers(long[] array, Random randy){ |
| 493 |
for(int i=0; i<array.length; i++){ |
| 494 |
array[i]=antialiasNumber(array[i], randy); |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
private static long antialiasNumber(long number, Random randy){ |
| 499 |
int ones=Long.bitCount(number); |
| 500 |
while(Long.bitCount(number)<31){ |
| 501 |
number=number|(1L<<randy.nextInt(64)); |
| 502 |
} |
| 503 |
while(Long.bitCount(number)>33){ |
| 504 |
number=number&~(1L<<randy.nextInt(64)); |
| 505 |
} |
| 506 |
return number; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static long[] makeCodes1D(long[][] codes2D){ |
| 520 |
final int len=codes2D.length*codes2D[0].length; |
| 521 |
long[] codes1D=new long[len]; |
| 522 |
int k=0; |
| 523 |
for(long[] array : codes2D){ |
| 524 |
for(long x : array){ |
| 525 |
codes1D[k]=x; |
| 526 |
k++; |
| 527 |
} |
| 528 |
} |
| 529 |
return codes1D; |
| 530 |
} |
| 531 |
|
| 532 |
public static final long hash(long kmer){ |
| 533 |
return rcomp ? hash(kmer, AminoAcid.reverseComplementBinaryFast(kmer, k), rcomp) : |
| 534 |
hash(kmer, kmer, rcomp); |
| 535 |
} |
| 536 |
|
| 537 |
public static final long hash(long kmer, long rkmer){ |
| 538 |
assert(postparsed); |
| 539 |
if(useToValue2){return hashToValue2(kmer, rkmer, rcomp);} |
| 540 |
final long key=toValue(kmer, rkmer); |
| 541 |
return k2<1 ? hash1(key) : k2submask==0 ? hash2(key) : hash3(key); |
| 542 |
} |
| 543 |
|
| 544 |
public static final long hash(long kmer, long rkmer, boolean rcomp){ |
| 545 |
assert(postparsed); |
| 546 |
if(useToValue2){return hashToValue2(kmer, rkmer, rcomp);} |
| 547 |
final long key=rcomp ? toValue(kmer, rkmer) : kmer; |
| 548 |
return k2<1 ? hash1(key) : k2submask==0 ? hash2(key) : hash3(key); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
private static final long hashToValue2(final long kmer0, final long rkmer0, final boolean rcomp){ |
| 558 |
|
| 559 |
long kmer=kmer0, rkmer=rkmer0; |
| 560 |
final long key; |
| 561 |
final boolean useK1; |
| 562 |
if(rcomp){ |
| 563 |
assert(!amino && !translate); |
| 564 |
final long kmer2=((kmer&k2midmask)>>>k2shift); |
| 565 |
final long rkmer2=((rkmer&k2midmask)>>>k2shift); |
| 566 |
final long max2=Tools.max(kmer2, rkmer2); |
| 567 |
|
| 568 |
|
| 569 |
useK1=((max2%4999L)&1L)==0L; |
| 570 |
key=useK1 ? Tools.max(kmer, rkmer) : max2; |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
}else if(amino || translate){ |
| 578 |
assert(amino || translate); |
| 579 |
final long kmer2=(kmer&k2mask); |
| 580 |
useK1=((kmer2%4999)&1L)==0L; |
| 581 |
key=useK1 ? kmer : kmer2; |
| 582 |
}else{ |
| 583 |
final long kmer2=((kmer&k2midmask)>>>k2shift); |
| 584 |
useK1=((kmer2%4999L)&1L)==0L; |
| 585 |
key=useK1 ? kmer : kmer2; |
| 586 |
} |
| 587 |
|
| 588 |
final long bit=useK1 ? 0 : 1; |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
long hashcode=key, data=key; |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
{ |
| 605 |
int i=0; |
| 606 |
do{ |
| 607 |
int x=(int)(data&cycleMask); |
| 608 |
data>>>=bitsPerCycle; |
| 609 |
hashcode^=codes1D[i+x]; |
| 610 |
i+=codeIncrement; |
| 611 |
}while(data!=0); |
| 612 |
} |
| 613 |
hashcode=(hashcode&(-2L))|bit; |
| 614 |
|
| 615 |
return hashcode; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
private static final long hash1(long kmer){ |
| 625 |
|
| 626 |
long code=kmer; |
| 627 |
for(int i=0; i<codeMax; i+=codeIncrement){ |
| 628 |
int x=(int)(kmer&cycleMask); |
| 629 |
kmer>>=bitsPerCycle; |
| 630 |
code^=codes1D[i+x]; |
| 631 |
} |
| 632 |
|
| 633 |
return code; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
private static final long hash2(final long kmer0){ |
| 643 |
|
| 644 |
long kmer=kmer0; |
| 645 |
long code=0; |
| 646 |
|
| 647 |
for(int i=0; i<codeMax2; i+=codeIncrement){ |
| 648 |
int x=(int)(kmer&cycleMask); |
| 649 |
kmer>>=bitsPerCycle; |
| 650 |
code^=codes1D[i+x]; |
| 651 |
} |
| 652 |
final long code2=code^(k2mask&kmer0); |
| 653 |
for(int i=codeMax2; i<codeMax; i+=codeIncrement){ |
| 654 |
int x=(int)(kmer&cycleMask); |
| 655 |
kmer>>=bitsPerCycle; |
| 656 |
code^=codes1D[i+x]; |
| 657 |
} |
| 658 |
return ((code&1)==1) ? code2 : code^kmer0; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
private static final long hash3(final long kmer0){ |
| 669 |
|
| 670 |
|
| 671 |
long kmer=kmer0; |
| 672 |
long code=0; |
| 673 |
assert(k2submask!=0); |
| 674 |
|
| 675 |
int i=0; |
| 676 |
for(; i<codeMax2; i+=codeIncrement){ |
| 677 |
int x=(int)(kmer&cycleMask); |
| 678 |
kmer>>=bitsPerCycle; |
| 679 |
code^=codes1D[i+x]; |
| 680 |
} |
| 681 |
final int residual=(int)(kmer&k2submask); |
| 682 |
final long code2=code^(k2mask&kmer0)^codes1D[i+residual]; |
| 683 |
for(; i<codeMax; i+=codeIncrement){ |
| 684 |
int x=(int)(kmer&cycleMask); |
| 685 |
kmer>>=bitsPerCycle; |
| 686 |
code^=codes1D[i+x]; |
| 687 |
} |
| 688 |
return ((code&1)==1) ? code2 : code^kmer0; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
public static final float align(byte[] query, byte[] ref){ |
| 697 |
SingleStateAlignerFlat2 ssa=GeneCaller.getSSA(); |
| 698 |
int a=0, b=ref.length-1; |
| 699 |
int[] max=ssa.fillUnlimited(query, ref, a, b, -9999); |
| 700 |
if(max==null){return 0;} |
| 701 |
|
| 702 |
final int rows=max[0]; |
| 703 |
final int maxCol=max[1]; |
| 704 |
final int maxState=max[2]; |
| 705 |
final float id=ssa.tracebackIdentity(query, ref, a, b, rows, maxCol, maxState, null); |
| 706 |
return id; |
| 707 |
} |
| 708 |
|
| 709 |
public static final float alignAndMakeMatch(Read r, byte[] ref){ |
| 710 |
byte[] query=r.bases; |
| 711 |
SingleStateAlignerFlat2 ssa=GeneCaller.getSSA(); |
| 712 |
int a=0, b=ref.length-1; |
| 713 |
int[] max=ssa.fillUnlimited(query, ref, a, b, -9999); |
| 714 |
if(max==null){return 0;} |
| 715 |
|
| 716 |
final int rows=max[0]; |
| 717 |
final int maxCol=max[1]; |
| 718 |
final int maxState=max[2]; |
| 719 |
byte[] match=ssa.traceback(query, ref, a, b, rows, maxCol, 0); |
| 720 |
int[] score=ssa.score(query, ref, a, b, rows, maxCol, 0); |
| 721 |
final float id=Read.identity(match); |
| 722 |
r.match=match; |
| 723 |
r.start=score[1]; |
| 724 |
r.stop=score[2]; |
| 725 |
r.setMapped(true); |
| 726 |
return id; |
| 727 |
} |
| 728 |
|
| 729 |
public static final float alignAndMakeMatch(Read r, byte[] ref, float[] refWeights){ |
| 730 |
byte[] query=r.bases; |
| 731 |
SingleStateAlignerFlatFloat ssa=GeneCaller.getSSAF(); |
| 732 |
|
| 733 |
ssa.setWeights(refWeights); |
| 734 |
int a=0, b=ref.length-1; |
| 735 |
int[] max=ssa.fillUnlimited(query, ref, a, b, -9999); |
| 736 |
if(max==null){return 0;} |
| 737 |
|
| 738 |
final int rows=max[0]; |
| 739 |
final int maxCol=max[1]; |
| 740 |
final int maxState=max[2]; |
| 741 |
byte[] match=ssa.traceback(query, ref, a, b, rows, maxCol, 0); |
| 742 |
int[] score=ssa.score(query, ref, a, b, rows, maxCol, 0); |
| 743 |
final float id=Read.identity(match); |
| 744 |
r.match=match; |
| 745 |
r.start=score[1]; |
| 746 |
r.stop=score[2]; |
| 747 |
r.setMapped(true); |
| 748 |
return id; |
| 749 |
} |
| 750 |
|
| 751 |
static String fixMeta(String s){ |
| 752 |
if(s==null){return null;} |
| 753 |
int colon=s.indexOf(':'); |
| 754 |
assert(colon>=0); |
| 755 |
if(s.length()==colon+5 && s.endsWith(":null")){return null;} |
| 756 |
return s.replace('\t', ' '); |
| 757 |
} |
| 758 |
|
| 759 |
static ArrayList<String> fixMeta(ArrayList<String> list){ |
| 760 |
if(list==null || list.isEmpty()){return null;} |
| 761 |
for(int i=0; i<list.size(); i++){ |
| 762 |
String s=list.get(i); |
| 763 |
s=fixMeta(s); |
| 764 |
if(s==null){ |
| 765 |
list.remove(i); |
| 766 |
i--; |
| 767 |
}else{ |
| 768 |
list.set(i, s); |
| 769 |
} |
| 770 |
} |
| 771 |
if(list.isEmpty()){return null;} |
| 772 |
list.trimToSize(); |
| 773 |
Collections.sort(list); |
| 774 |
return list; |
| 775 |
} |
| 776 |
|
| 777 |
public static final float aniToWkid(final double ani){ |
| 778 |
final float wkid; |
| 779 |
if(ani<=0){ |
| 780 |
wkid=0; |
| 781 |
}else if(k2<1){ |
| 782 |
wkid=(float)Math.pow(ani, k); |
| 783 |
}else{ |
| 784 |
wkid=0.5f*(float)(Math.pow(ani, k)+Math.pow(ani, k2)); |
| 785 |
} |
| 786 |
return wkid; |
| 787 |
} |
| 788 |
|
| 789 |
public static final float wkidToAniExact(final double wkid, final int A, final int B, final double maxDeviation){ |
| 790 |
assert(A>B); |
| 791 |
assert(maxDeviation>0); |
| 792 |
final double logWkid=Math.log(wkid); |
| 793 |
final double invA=1.0/A; |
| 794 |
final double invB=1.0/B; |
| 795 |
|
| 796 |
double aniUpper=Math.exp(logWkid*invA); |
| 797 |
double aniLower=Math.exp(logWkid*invB); |
| 798 |
assert(aniLower<=aniUpper); |
| 799 |
double aniEst=(aniLower+aniUpper)*0.5f; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
double wkidEst=aniToWkid(aniEst, A, B); |
| 806 |
int iters=1; |
| 807 |
|
| 808 |
while(Math.abs(wkidEst-wkid)>maxDeviation && iters<40){ |
| 809 |
if(wkidEst<wkid){aniLower=aniEst;} |
| 810 |
else{aniUpper=aniEst;} |
| 811 |
aniEst=(aniLower+aniUpper)*0.5f; |
| 812 |
wkidEst=aniToWkid(aniEst, A, B); |
| 813 |
|
| 814 |
iters++; |
| 815 |
} |
| 816 |
|
| 817 |
return (float)aniEst; |
| 818 |
} |
| 819 |
|
| 820 |
public static double aniToWkid(double ani, int A, int B){ |
| 821 |
if(A<B){int C=A; A=B; B=C;} |
| 822 |
double aPow=Math.pow(ani, A); |
| 823 |
double bPow=Math.pow(ani, B); |
| 824 |
|
| 825 |
return useToValue2 ? 0.5*(aPow+bPow) : 0.5*(aPow+(bPow*0.4+aPow*0.6)); |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
public static double aniToWkid(double ani, int A){ |
| 837 |
return Math.pow(ani, A); |
| 838 |
} |
| 839 |
|
| 840 |
public static final float wkidToAniExact(final double wkid, final int k){ |
| 841 |
return (float)Math.exp(Math.log(wkid)/(k)); |
| 842 |
} |
| 843 |
|
| 844 |
public static final float wkidToAni(final double wkid){ |
| 845 |
final float ani; |
| 846 |
if(wkid<=0){ |
| 847 |
ani=0; |
| 848 |
}else if(k2<1){ |
| 849 |
ani=(float)Math.exp(Math.log(wkid)/k); |
| 850 |
}else{ |
| 851 |
if(EXACT_ANI){return wkidToAniExact(wkid, k, k2, 0.00005);} |
| 852 |
|
| 853 |
|
| 854 |
final double log=Math.log(wkid); |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
ani=(float)Math.exp(2*log/(1.2*k+.8*k2)); |
| 863 |
} |
| 864 |
return ani; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
public static void hashArrayToSketchArray(long[] keys){ |
| 879 |
for(int i=0; i<keys.length; i++){ |
| 880 |
long hash=keys[i]; |
| 881 |
assert(hash>=minHashValue); |
| 882 |
hash=Long.MAX_VALUE-hash; |
| 883 |
keys[i]=hash; |
| 884 |
} |
| 885 |
Shared.sort(keys); |
| 886 |
} |
| 887 |
|
| 888 |
public static final long genomeSizeEstimate(long min, int length) { |
| 889 |
if(length==0){return 0;} |
| 890 |
double est=((double)Long.MAX_VALUE)*2*length/(Tools.max(min, 1)); |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
return (long)Math.ceil(est); |
| 895 |
} |
| 896 |
|
| 897 |
public static final int toSketchSize(long genomeSizeBases, long genomeSizeKmers, long genomeSizeEstimate, int maxSketchSize){ |
| 898 |
|
| 899 |
if(genomeSizeEstimate>0 && useSizeEstimate){ |
| 900 |
return toSketchSizeKmers(genomeSizeEstimate, maxSketchSize); |
| 901 |
} |
| 902 |
if(genomeSizeKmers>0){ |
| 903 |
return toSketchSizeKmers(genomeSizeKmers, maxSketchSize); |
| 904 |
} |
| 905 |
assert(genomeSizeBases>0) : "BBSketch does not currently support empty files.\n" |
| 906 |
+genomeSizeBases+", "+genomeSizeKmers+", "+genomeSizeEstimate+", "+maxSketchSize+", "+useSizeEstimate; |
| 907 |
return toSketchSizeBases(genomeSizeBases, maxSketchSize); |
| 908 |
} |
| 909 |
|
| 910 |
private static final int toSketchSizeBases(long genomeSizeBases, int maxSketchSize) { |
| 911 |
return toSketchSizeKmers(Tools.max(0, genomeSizeBases-k+1), maxSketchSize); |
| 912 |
} |
| 913 |
|
| 914 |
private static final int toSketchSizeKmers(long genomeSizeKmers, int maxSketchSize) { |
| 915 |
|
| 916 |
|
| 917 |
if(AUTOSIZE){ |
| 918 |
if(aminoOrTranslate()){ |
| 919 |
float linear1=Tools.min(60+0.5f*(float)Math.sqrt(genomeSizeKmers), |
| 920 |
maxGenomeFractionSmall*genomeSizeKmers*2); |
| 921 |
float linear2=genomeSizeKmers*maxGenomeFraction*2; |
| 922 |
float poly=0+1f*(float)Math.sqrt(genomeSizeKmers)+90f*(float)Math.pow(genomeSizeKmers, 0.3); |
| 923 |
float log=Tools.max(1000, -4000+3500*(float)Math.log(Tools.max(1, genomeSizeKmers))); |
| 924 |
float min=Tools.min(Tools.max(linear1, linear2), poly, log); |
| 925 |
assert(min>=Integer.MIN_VALUE && min<=Integer.MAX_VALUE) : min; |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
return (int)Tools.min(genomeSizeKmers*keyFraction2, min*AUTOSIZE_FACTOR); |
| 930 |
|
| 931 |
}else{ |
| 932 |
float linear1=Tools.min(smallSketchSize+0.5f*(float)Math.sqrt(genomeSizeKmers), |
| 933 |
maxGenomeFractionSmall*genomeSizeKmers-10); |
| 934 |
float linear2=genomeSizeKmers*maxGenomeFraction; |
| 935 |
float poly=0+1f*(float)Math.sqrt(genomeSizeKmers)+90f*(float)Math.pow(genomeSizeKmers, 0.3); |
| 936 |
float log=Tools.max(1000, -4000+3500*(float)Math.log(Tools.max(1, genomeSizeKmers))+8f*(float)Math.pow(genomeSizeKmers, 0.3)); |
| 937 |
float min=Tools.min(Tools.max(linear1, linear2), poly, log); |
| 938 |
assert(min>=Integer.MIN_VALUE && min<=Integer.MAX_VALUE) : min; |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
int result=(int)Tools.min(genomeSizeKmers*keyFraction2, min*AUTOSIZE_FACTOR); |
| 943 |
|
| 944 |
return result; |
| 945 |
|
| 946 |
} |
| 947 |
}else if(AUTOSIZE_LINEAR){ |
| 948 |
if(aminoOrTranslate()){ |
| 949 |
return (int)(Tools.min(10000000, Tools.min(maxGenomeFractionSmall, AUTOSIZE_LINEAR_DENSITY)*genomeSizeKmers)); |
| 950 |
}else{ |
| 951 |
return (int)(Tools.min(10000000, Tools.min(maxGenomeFractionSmall, AUTOSIZE_LINEAR_DENSITY)*genomeSizeKmers)); |
| 952 |
} |
| 953 |
}else{ |
| 954 |
if(aminoOrTranslate()){ |
| 955 |
return Tools.min((int)(2+3*maxGenomeFraction*genomeSizeKmers), maxSketchSize); |
| 956 |
}else{ |
| 957 |
return Tools.min((int)(2+maxGenomeFraction*genomeSizeKmers), maxSketchSize); |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
private static final long toValue(long kmer, long rkmer){ |
| 1007 |
|
| 1008 |
assert(!useToValue2); |
| 1009 |
|
| 1010 |
long value=(rcomp ? Tools.max(kmer, rkmer) : kmer); |
| 1011 |
return value; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
public static final int RAW=0; |
| 1020 |
|
| 1021 |
public static final int HEX=1; |
| 1022 |
|
| 1023 |
public static final int A48=2; |
| 1024 |
|
| 1025 |
public static final char[] codingArray={'R', 'H', 'A'}; |
| 1026 |
|
| 1027 |
static final byte[] hexTable=new byte[128]; |
| 1028 |
static { |
| 1029 |
Arrays.fill(hexTable, (byte)-1); |
| 1030 |
for(int i='0'; i<='9'; i++){ |
| 1031 |
hexTable[i]=(byte)(i-'0'); |
| 1032 |
} |
| 1033 |
for(int i='A'; i<='F'; i++){ |
| 1034 |
hexTable[i]=hexTable[i+'a'-'A']=(byte)(i-'A'+10); |
| 1035 |
} |
| 1036 |
hexTable['x']=hexTable['X']=hexTable['-']=hexTable['+']=0; |
| 1037 |
} |
| 1038 |
|
| 1039 |
public static final int ONE_SKETCH=1, PER_SEQUENCE=2, PER_TAXA=3, PER_IMG=4, PER_FILE=6; |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
private static ArrayList<String> makePaths(String pattern, int files){ |
| 1052 |
ArrayList<String> list=new ArrayList<String>(files); |
| 1053 |
for(int i=0; i<files; i++){ |
| 1054 |
list.add(pattern.replace("#", ""+i)); |
| 1055 |
} |
| 1056 |
return list; |
| 1057 |
} |
| 1058 |
|
| 1059 |
private static final String IMG_PATH="/global/cfs/cdirs/bbtools/img/current/img#.sketch"; |
| 1060 |
private static final String NT_PATH="/global/cfs/cdirs/bbtools/nt/current/taxa#.sketch"; |
| 1061 |
private static final String NR_PATH="/global/cfs/cdirs/bbtools/nr/current/taxa#.sketch"; |
| 1062 |
private static final String REFSEQ_PATH="/global/cfs/cdirs/bbtools/refseq/current/taxa#.sketch"; |
| 1063 |
private static final String REFSEQ_PATH_BIG="/global/cfs/cdirs/bbtools/refseq/current/big#.sketch"; |
| 1064 |
private static final String SILVA_PATH="/global/cfs/cdirs/bbtools/silva/latest/both_taxa#.sketch"; |
| 1065 |
private static final String PROKPROT_PATH="/global/cfs/cdirs/bbtools/refseq/current/prot/taxa#.sketch"; |
| 1066 |
private static final String PROKPROT_PATH_BIG="/global/cfs/cdirs/bbtools/refseq/current/prot/big#.sketch"; |
| 1067 |
private static final String MITO_PATH="/global/cfs/cdirs/bbtools/mito2/taxa#.sketch"; |
| 1068 |
private static final String FUNGI_PATH="/global/cfs/cdirs/bbtools/mito2/fungi#.sketch"; |
| 1069 |
|
| 1070 |
private static final String IMG_PATH_IGBVM="/data/sketch/img/current/img#.sketch"; |
| 1071 |
private static final String NT_PATH_IGBVM="/data/sketch/nt/current/taxa#.sketch"; |
| 1072 |
private static final String NR_PATH_IGBVM="/data/sketch/nr/current/taxa#.sketch"; |
| 1073 |
private static final String REFSEQ_PATH_IGBVM="/data/sketch/refseq/current/taxa#.sketch"; |
| 1074 |
private static final String REFSEQ_PATH_BIG_IGBVM="/data/sketch/refseq/current/big#.sketch"; |
| 1075 |
private static final String SILVA_PATH_IGBVM="/data/sketch/silva/current/both_taxa#.sketch"; |
| 1076 |
private static final String PROKPROT_PATH_IGBVM="/data/sketch/refseq/current/prot/taxa#.sketch"; |
| 1077 |
private static final String PROKPROT_PATH_BIG_IGBVM="/data/sketch/refseq/current/prot/big#.sketch"; |
| 1078 |
private static final String MITO_PATH_IGBVM="/data/sketch/mito2/taxa#.sketch"; |
| 1079 |
private static final String FUNGI_PATH_IGBVM="/data/sketch/mito2/fungi#.sketch"; |
| 1080 |
|
| 1081 |
private static final String IMG_PATH_AWS=null; |
| 1082 |
private static final String NT_PATH_AWS="/test1/sketch/latest/nt/taxa#.sketch"; |
| 1083 |
private static final String NR_PATH_AWS=null; |
| 1084 |
private static final String REFSEQ_PATH_AWS="/test1/sketch/latest/refseq/taxa#.sketch"; |
| 1085 |
private static final String SILVA_PATH_AWS="/test1/sketch/latest/ribo/both_taxa#.sketch"; |
| 1086 |
private static final String PROKPROT_PATH_AWS="/test1/sketch/latest/protein/taxa#.sketch"; |
| 1087 |
private static final String MITO_PATH_AWS=null; |
| 1088 |
private static final String FUNGI_PATH_AWS=null; |
| 1089 |
|
| 1090 |
public static final String IMG_PATH(){return Shared.IGBVM ? IMG_PATH_IGBVM : Shared.AWS ? IMG_PATH_AWS : IMG_PATH;} |
| 1091 |
public static final String NT_PATH(){return Shared.IGBVM ? NT_PATH_IGBVM : Shared.AWS ? NT_PATH_AWS : NT_PATH;} |
| 1092 |
public static final String NR_PATH(){return Shared.IGBVM ? NR_PATH_IGBVM : Shared.AWS ? NR_PATH_AWS : NR_PATH;} |
| 1093 |
public static final String REFSEQ_PATH(){return Shared.IGBVM ? REFSEQ_PATH_IGBVM : Shared.AWS ? REFSEQ_PATH_AWS : REFSEQ_PATH;} |
| 1094 |
public static final String REFSEQ_PATH_BIG(){return Shared.IGBVM ? REFSEQ_PATH_BIG_IGBVM : REFSEQ_PATH_BIG;} |
| 1095 |
public static final String SILVA_PATH(){return Shared.IGBVM ? SILVA_PATH_IGBVM : Shared.AWS ? SILVA_PATH_AWS : SILVA_PATH;} |
| 1096 |
public static final String PROKPROT_PATH(){return Shared.IGBVM ? PROKPROT_PATH_IGBVM : Shared.AWS ? PROKPROT_PATH_AWS : PROKPROT_PATH;} |
| 1097 |
public static final String PROKPROT_PATH_BIG(){return Shared.IGBVM ? PROKPROT_PATH_BIG_IGBVM : PROKPROT_PATH_BIG;} |
| 1098 |
public static final String MITO_PATH(){return Shared.IGBVM ? MITO_PATH_IGBVM : Shared.AWS ? MITO_PATH_AWS : MITO_PATH;} |
| 1099 |
public static final String FUNGI_PATH(){return Shared.IGBVM ? FUNGI_PATH_IGBVM : Shared.AWS ? FUNGI_PATH_AWS : FUNGI_PATH;} |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
public static boolean useWhitelist() {return useWhitelist;} |
| 1106 |
public static String blacklist() {return blacklist;} |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
public static int CODING=A48; |
| 1113 |
public static boolean deltaOut=true; |
| 1114 |
public static boolean rcomp=true; |
| 1115 |
|
| 1116 |
public static final int defaultK=32; |
| 1117 |
public static final int defaultK2=24; |
| 1118 |
public static final int defaultKAmino=12; |
| 1119 |
public static final int defaultK2Amino=9; |
| 1120 |
public static int k=defaultK; |
| 1121 |
public static int k2=defaultK2; |
| 1122 |
public static int entropyK=3; |
| 1123 |
public static boolean setK=false; |
| 1124 |
public static boolean amino=false; |
| 1125 |
public static boolean amino8=false; |
| 1126 |
public static boolean translate=false; |
| 1127 |
public static boolean sixframes=false; |
| 1128 |
public static boolean processSSU=true; |
| 1129 |
public static int min_SSU_len=1000; |
| 1130 |
public static int HASH_VERSION=2; |
| 1131 |
public static String pgmFile=null; |
| 1132 |
public static GeneModel pgm=null; |
| 1133 |
|
| 1134 |
static boolean aminoOrTranslate(){return amino | translate;} |
| 1135 |
|
| 1136 |
private static int bitsPerCycle=8; |
| 1137 |
private static long cycleMask=~((-1L)<<bitsPerCycle); |
| 1138 |
private static final long codeOrMask=1L; |
| 1139 |
private static final long codeAndMask=~1L; |
| 1140 |
private static int maxCycles=(64+bitsPerCycle-1)/bitsPerCycle; |
| 1141 |
private static int codeIncrement=(int)(cycleMask+1); |
| 1142 |
private static int codeMax; |
| 1143 |
private static int codeMax2; |
| 1144 |
|
| 1145 |
private static long hashSeed=12345; |
| 1146 |
private static long[][] codes; |
| 1147 |
private static long[] codes1D; |
| 1148 |
static boolean useToValue2=true; |
| 1149 |
|
| 1150 |
|
| 1151 |
private static int bitsPerBase=2; |
| 1152 |
private static int basesPerCycle=bitsPerCycle/bitsPerBase; |
| 1153 |
private static int hashCycles=64/bitsPerCycle; |
| 1154 |
private static int hashCycles2; |
| 1155 |
private static long k2mask; |
| 1156 |
private static long k2submask; |
| 1157 |
|
| 1158 |
private static int k2shift; |
| 1159 |
private static long k2midmask; |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
public static double sketchHeapFactor=8; |
| 1166 |
|
| 1167 |
|
| 1168 |
public static int minSketchSize=3; |
| 1169 |
public static int targetSketchSize=10000; |
| 1170 |
public static boolean AUTOSIZE=true; |
| 1171 |
public static float AUTOSIZE_FACTOR=1; |
| 1172 |
public static boolean SET_AUTOSIZE_FACTOR=false; |
| 1173 |
public static boolean SET_AUTOSIZE=false; |
| 1174 |
public static boolean SET_TARGET_SIZE=false; |
| 1175 |
public static boolean AUTOSIZE_LINEAR=false; |
| 1176 |
public static double AUTOSIZE_LINEAR_DENSITY=0.001; |
| 1177 |
public static float maxGenomeFraction=0.04f; |
| 1178 |
public static float maxGenomeFractionSmall=0.10f; |
| 1179 |
public static int smallSketchSize=150; |
| 1180 |
public static boolean makeIndex=true; |
| 1181 |
public static float prealloc=0; |
| 1182 |
public static boolean allToAll=false; |
| 1183 |
public static boolean compareSelf=false; |
| 1184 |
public static boolean skipCompare=false; |
| 1185 |
public static final int bitSetBits=2; |
| 1186 |
|
| 1187 |
private static double keyFraction=0.16; |
| 1188 |
private static double keyFraction2=keyFraction*1.2; |
| 1189 |
public static long minHashValue=setMinHashValue(); |
| 1190 |
public static double keyFraction(){return keyFraction;} |
| 1191 |
public static void setKeyFraction(double d){ |
| 1192 |
assert(d>0); |
| 1193 |
keyFraction=Tools.mid(0.0001, d, 0.5); |
| 1194 |
keyFraction2=Tools.mid(0.0001, keyFraction*1.2, 0.5); |
| 1195 |
} |
| 1196 |
public static long setMinHashValue(){ |
| 1197 |
double mult=1-2*keyFraction; |
| 1198 |
minHashValue=(long)(mult*Long.MAX_VALUE); |
| 1199 |
assert(minHashValue>=0 && minHashValue<Long.MAX_VALUE); |
| 1200 |
return minHashValue; |
| 1201 |
} |
| 1202 |
|
| 1203 |
public static int minFakeID=1900000000; |
| 1204 |
static boolean hashNames=false; |
| 1205 |
static boolean skipNonCanonical=true; |
| 1206 |
static boolean useSizeEstimate=true; |
| 1207 |
public static boolean allowMultithreadedFastq=false; |
| 1208 |
static boolean forceDisableMultithreadedFastq=false; |
| 1209 |
|
| 1210 |
static boolean preferSSUMap=false; |
| 1211 |
static boolean preferSSUMapForEuks=true; |
| 1212 |
static boolean useSSUMapOnly=false; |
| 1213 |
static boolean useSSUMapOnlyForEuks=false; |
| 1214 |
static boolean ban18SForProks=true; |
| 1215 |
static boolean ban16SForEuks=true; |
| 1216 |
|
| 1217 |
public static long sampleseed=-1L; |
| 1218 |
|
| 1219 |
public static TaxTree taxtree=null; |
| 1220 |
private static String treefile=null; |
| 1221 |
static String blacklist=null; |
| 1222 |
static boolean useWhitelist=false; |
| 1223 |
private static boolean postparsed=false; |
| 1224 |
public static boolean KILL_OK=false; |
| 1225 |
public static boolean EXACT_ANI=true; |
| 1226 |
public static boolean useSSA=true; |
| 1227 |
public static boolean useSSA3=false; |
| 1228 |
|
| 1229 |
|
| 1230 |
public static DisplayParams defaultParams=new DisplayParams(); |
| 1231 |
|
| 1232 |
static AlignmentThreadPool alignerPool=null; |
| 1233 |
|
| 1234 |
public static boolean verbose2=false; |
| 1235 |
public static boolean LOADER2=true; |
| 1236 |
|
| 1237 |
} |