| 1 |
package tax; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
import java.util.Arrays; |
| 7 |
import java.util.Collections; |
| 8 |
import java.util.HashMap; |
| 9 |
import java.util.concurrent.atomic.AtomicLongArray; |
| 10 |
|
| 11 |
import fileIO.ByteFile; |
| 12 |
import fileIO.ByteFile1; |
| 13 |
import fileIO.ByteFile2; |
| 14 |
import fileIO.FileFormat; |
| 15 |
import fileIO.ReadWrite; |
| 16 |
import kmer.HashBuffer; |
| 17 |
import kmer.KmerTableSet; |
| 18 |
import shared.Parse; |
| 19 |
import shared.Parser; |
| 20 |
import shared.PreParser; |
| 21 |
import shared.Shared; |
| 22 |
import shared.Timer; |
| 23 |
import shared.Tools; |
| 24 |
import stream.ConcurrentGenericReadInputStream; |
| 25 |
import stream.FastaReadInputStream; |
| 26 |
import structures.StringNum; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class AccessionToTaxid_old { |
| 34 |
|
| 35 |
public static void load(String files){ |
| 36 |
final boolean oldBf2=ByteFile.FORCE_MODE_BF2; |
| 37 |
final boolean oldBf1=ByteFile.FORCE_MODE_BF1; |
| 38 |
final boolean oldUnpigz=ReadWrite.USE_UNPIGZ; |
| 39 |
final boolean oldGunzip=ReadWrite.USE_UNPIGZ; |
| 40 |
|
| 41 |
main(new String[] {"in="+files, "unpigz="+ReadWrite.USE_UNPIGZ, "gunzip="+ReadWrite.USE_GUNZIP}); |
| 42 |
|
| 43 |
ByteFile.FORCE_MODE_BF2=oldBf2; |
| 44 |
ByteFile.FORCE_MODE_BF1=oldBf1; |
| 45 |
ReadWrite.USE_UNPIGZ=oldUnpigz; |
| 46 |
ReadWrite.USE_UNPIGZ=oldGunzip; |
| 47 |
} |
| 48 |
|
| 49 |
public static void main(String[] args){ |
| 50 |
Timer t=new Timer(); |
| 51 |
AccessionToTaxid_old x=new AccessionToTaxid_old(args); |
| 52 |
x.process(t); |
| 53 |
|
| 54 |
|
| 55 |
Shared.closeStream(x.outstream); |
| 56 |
} |
| 57 |
|
| 58 |
public AccessionToTaxid_old(String[] args){ |
| 59 |
|
| 60 |
{ |
| 61 |
PreParser pp=new PreParser(args, getClass(), false); |
| 62 |
args=pp.args; |
| 63 |
outstream=pp.outstream; |
| 64 |
} |
| 65 |
|
| 66 |
ReadWrite.USE_UNPIGZ=true; |
| 67 |
|
| 68 |
Parser parser=new Parser(); |
| 69 |
for(int i=0; i<args.length; i++){ |
| 70 |
String arg=args[i]; |
| 71 |
String[] split=arg.split("="); |
| 72 |
String a=split[0].toLowerCase(); |
| 73 |
String b=split.length>1 ? split[1] : null; |
| 74 |
|
| 75 |
if(a.equals("verbose")){ |
| 76 |
verbose=Parse.parseBoolean(b); |
| 77 |
ByteFile1.verbose=verbose; |
| 78 |
ByteFile2.verbose=verbose; |
| 79 |
stream.FastaReadInputStream.verbose=verbose; |
| 80 |
ConcurrentGenericReadInputStream.verbose=verbose; |
| 81 |
stream.FastqReadInputStream.verbose=verbose; |
| 82 |
ReadWrite.verbose=verbose; |
| 83 |
}else if(a.equals("stripunderscore")){ |
| 84 |
|
| 85 |
assert(false) : "stripunderscore is disabled."; |
| 86 |
}else if(a.equals("usetables")){ |
| 87 |
|
| 88 |
}else if(a.equals("usetables")){ |
| 89 |
|
| 90 |
}else if(a.equals("skipparse")){ |
| 91 |
skipParse=Parse.parseBoolean(b); |
| 92 |
}else if(a.equals("skiphash")){ |
| 93 |
skipHash=Parse.parseBoolean(b); |
| 94 |
}else if(a.equals("prealloc")){ |
| 95 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 96 |
if(Parse.parseBoolean(b)){ |
| 97 |
prealloc=0.78f; |
| 98 |
}else{ |
| 99 |
prealloc=0; |
| 100 |
} |
| 101 |
}else{ |
| 102 |
prealloc=Float.parseFloat(b); |
| 103 |
} |
| 104 |
}else if(a.equals("maxpigzprocesses")){ |
| 105 |
maxPigzProcesses=Integer.parseInt(b); |
| 106 |
}else if(a.equals("in")){ |
| 107 |
assert(b!=null) : "Bad parameter: "+arg; |
| 108 |
String[] temp=b.split(","); |
| 109 |
for(String s : temp){in.add(s);} |
| 110 |
}else if(parser.parse(arg, a, b)){ |
| 111 |
|
| 112 |
}else if(b==null){ |
| 113 |
if(new File(arg).exists()){ |
| 114 |
in.add(arg); |
| 115 |
} |
| 116 |
}else{ |
| 117 |
outstream.println("Unknown parameter "+args[i]); |
| 118 |
assert(false) : "Unknown parameter "+args[i]; |
| 119 |
|
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
{ |
| 124 |
overwrite=parser.overwrite; |
| 125 |
|
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
assert(FastaReadInputStream.settingsOK()); |
| 130 |
|
| 131 |
if(in==null || in.size()==0){throw new RuntimeException("Error - at least one input file is required.");} |
| 132 |
|
| 133 |
if(ReadWrite.USE_UNPIGZ && !ByteFile.FORCE_MODE_BF2){ |
| 134 |
ByteFile.FORCE_MODE_BF2=false; |
| 135 |
ByteFile.FORCE_MODE_BF1=true; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
{ |
| 146 |
ArrayList<StringNum> list=new ArrayList<StringNum>(); |
| 147 |
for(String s : in){ |
| 148 |
list.add(new StringNum(s, new File(s).length())); |
| 149 |
} |
| 150 |
Collections.sort(list); |
| 151 |
in.clear(); |
| 152 |
for(StringNum sn : list){ |
| 153 |
in.add(sn.s); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
ffin=new FileFormat[in.size()]; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
int processes=0; |
| 166 |
for(int i=0; i<in.size(); i++){ |
| 167 |
String s=in.get(i); |
| 168 |
if(!new File(s).exists()){ |
| 169 |
if(s.startsWith("shrunk.") && new File(s.substring(7)).exists()){ |
| 170 |
s=s.substring(7); |
| 171 |
} |
| 172 |
} |
| 173 |
FileFormat ff=FileFormat.testInput(s, FileFormat.TXT, null, true, false); |
| 174 |
if(ff.gzip() && processes>maxPigzProcesses){ |
| 175 |
processes++; |
| 176 |
|
| 177 |
ff=FileFormat.testInput(s, FileFormat.TXT, null, false, false); |
| 178 |
|
| 179 |
} |
| 180 |
ffin[i]=ff; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
@SuppressWarnings("unchecked") |
| 185 |
void process(Timer t){ |
| 186 |
|
| 187 |
|
| 188 |
assert(maps==null); |
| 189 |
maps=new HashMap[128]; |
| 190 |
for(int i=0; i<maps.length; i++){ |
| 191 |
maps[i]=new HashMap<String, Integer>(); |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
assert(tables==null); |
| 196 |
if(USE_TABLES){ |
| 197 |
tables=new KmerTableSet(new String[] {"ways=31",("prealloc="+(prealloc>0 ? prealloc : "f"))}, 12); |
| 198 |
tables.allocateTables(); |
| 199 |
} |
| 200 |
|
| 201 |
if(ffin.length>4){ |
| 202 |
FileFormat[] ffa1=Arrays.copyOf(ffin, 2); |
| 203 |
FileFormat[] ffa2=Arrays.copyOfRange(ffin, 2, ffin.length); |
| 204 |
spawnThreads(ffa1); |
| 205 |
spawnThreads(ffa2); |
| 206 |
}else{ |
| 207 |
spawnThreads(ffin); |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
System.gc(); |
| 212 |
|
| 213 |
t.stop(); |
| 214 |
outstream.println(Tools.timeLinesBytesProcessed(t, linesProcessed, bytesProcessed, 8)); |
| 215 |
|
| 216 |
outstream.println(); |
| 217 |
outstream.println("Valid Lines: \t"+linesValid); |
| 218 |
outstream.println("Invalid Lines: \t"+(linesProcessed-linesValid)); |
| 219 |
|
| 220 |
if(lengthCounts!=null){ |
| 221 |
outstream.println(); |
| 222 |
outstream.println("Length counts:"); |
| 223 |
|
| 224 |
for(int i=0; i<lengthCounts.length(); i++){ |
| 225 |
long count=lengthCounts.get(i); |
| 226 |
if(count>0){outstream.println(i+"\t"+count);} |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
if(symbolCounts!=null){ |
| 231 |
outstream.println(); |
| 232 |
outstream.println("Symbols:"); |
| 233 |
|
| 234 |
String comma=""; |
| 235 |
for(int i=0; i<symbolCounts.length(); i++){ |
| 236 |
long count=symbolCounts.get(i); |
| 237 |
if(count>0){ |
| 238 |
outstream.print(comma+i); |
| 239 |
comma=","; |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
if(counts_underscore!=null){ |
| 245 |
outstream.println(); |
| 246 |
outstream.println("Length_underscore counts:"); |
| 247 |
|
| 248 |
for(int i=0; i<counts_underscore.length(); i++){ |
| 249 |
long count=counts_underscore.get(i); |
| 250 |
if(count>0){outstream.println(i+"\t"+count);} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
if(counts_underscore2!=null){ |
| 255 |
outstream.println(); |
| 256 |
outstream.println("Length_underscore2 counts:"); |
| 257 |
|
| 258 |
for(int i=0; i<counts_underscore2.length(); i++){ |
| 259 |
long count=counts_underscore2.get(i); |
| 260 |
if(count>0){outstream.println(i+"\t"+count);} |
| 261 |
} |
| 262 |
} |
| 263 |
outstream.println(); |
| 264 |
Shared.printMemory(); |
| 265 |
|
| 266 |
if(errorState){ |
| 267 |
throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); |
| 268 |
} |
| 269 |
|
| 270 |
LOADED=true; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
private void spawnThreads(FileFormat[] ffa){ |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
ArrayList<HashThread> alht=new ArrayList<HashThread>(ffa.length); |
| 280 |
for(FileFormat ff : ffa){ |
| 281 |
if(ff!=null){ |
| 282 |
System.err.println("Loading "+ff.name()); |
| 283 |
alht.add(new HashThread(ff)); |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
for(HashThread pt : alht){ |
| 289 |
pt.start(); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
boolean success=true; |
| 294 |
for(HashThread pt : alht){ |
| 295 |
|
| 296 |
|
| 297 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 298 |
try { |
| 299 |
|
| 300 |
pt.join(); |
| 301 |
} catch (InterruptedException e) { |
| 302 |
|
| 303 |
e.printStackTrace(); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
linesProcessed+=pt.linesProcessedT; |
| 308 |
linesValid+=pt.linesValidT; |
| 309 |
bytesProcessed+=pt.bytesProcessedT; |
| 310 |
|
| 311 |
accumulate(lengthCounts, pt.lengthCountsT); |
| 312 |
accumulate(symbolCounts, pt.symbolCountsT); |
| 313 |
accumulate(counts_underscore, pt.counts_underscoreT); |
| 314 |
accumulate(counts_underscore2, pt.counts_underscore2T); |
| 315 |
|
| 316 |
success&=pt.success; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
if(!success){errorState=true;} |
| 321 |
} |
| 322 |
|
| 323 |
private static void accumulate(AtomicLongArray a, long[] b){ |
| 324 |
if(a==null || b==null){return;} |
| 325 |
for(int i=0; i<b.length; i++){ |
| 326 |
a.getAndAdd(i, b[i]); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
public static int get(String accession){ |
| 333 |
if(accession==null){return -1;} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
int dot=accession.indexOf('.'); |
| 339 |
int len=(dot<0 ? accession.length() : dot); |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
if(USE_TABLES){ |
| 344 |
if(AnalyzeAccession.codeMap!=null){ |
| 345 |
|
| 346 |
final long number=AnalyzeAccession.digitize(accession); |
| 347 |
if(number>=0){ |
| 348 |
int value=tables.getCount(number); |
| 349 |
return value<0 ? -1 : value; |
| 350 |
} |
| 351 |
}else if(len<=12){ |
| 352 |
long number=hash(accession); |
| 353 |
|
| 354 |
int value=tables.getCount(number); |
| 355 |
return value<1 ? -1 : value; |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
if(dot>-1){accession=accession.substring(0, dot);} |
| 360 |
if(accession.length()<1){return -1;} |
| 361 |
int way=accession.charAt(0); |
| 362 |
Integer value=maps[way].get(accession); |
| 363 |
return value==null ? -1 : value.intValue(); |
| 364 |
} |
| 365 |
|
| 366 |
public static boolean isValidAccession(String s){ |
| 367 |
if(s==null || s.length()<4){return false;} |
| 368 |
for(int i=0; i<s.length(); i++){ |
| 369 |
char c=s.charAt(i); |
| 370 |
if((c>='0' && c<='9') || (c>='A' && c<='Z') || c=='.' || c=='_' || c=='-'){ |
| 371 |
|
| 372 |
}else{ |
| 373 |
return false; |
| 374 |
} |
| 375 |
} |
| 376 |
return true; |
| 377 |
} |
| 378 |
|
| 379 |
static long hash(String accession){ |
| 380 |
long number=0; |
| 381 |
for(int i=0, max=accession.length(); i<max; i++){ |
| 382 |
long c=accession.charAt(i); |
| 383 |
if(c=='.'){break;} |
| 384 |
if(c>='0' && c<='9'){c=c-'0';} |
| 385 |
else if(c>='A' && c<='Z'){c=c+offset;} |
| 386 |
else if(c=='_' || c=='-'){c=10;} |
| 387 |
else if(c>='a' && c<='z'){c=c+offsetLower;} |
| 388 |
else{ |
| 389 |
assert(false) : accession; |
| 390 |
} |
| 391 |
number=(number*37)+c; |
| 392 |
} |
| 393 |
return number; |
| 394 |
} |
| 395 |
|
| 396 |
static long hash(final byte[] line, final int limit){ |
| 397 |
long number=0; |
| 398 |
for(int i=0; i<limit; i++){ |
| 399 |
long c=line[i]; |
| 400 |
if(c=='.'){break;} |
| 401 |
if(c>='0' && c<='9'){c=c-'0';} |
| 402 |
else if(c>='A' && c<='Z'){c=c+offset;} |
| 403 |
else if(c=='_' || c=='-'){c=10;} |
| 404 |
else if(c>='a' && c<='z'){c=c+offsetLower;} |
| 405 |
else{ |
| 406 |
assert(false) : new String(line); |
| 407 |
} |
| 408 |
number=(number*37)+c; |
| 409 |
} |
| 410 |
return number; |
| 411 |
} |
| 412 |
|
| 413 |
public static int parseLineToTaxid(final byte[] line, final byte delimiter){ |
| 414 |
int a=0, b=0; |
| 415 |
|
| 416 |
final int ncbi; |
| 417 |
|
| 418 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 419 |
assert(b>a) : "Missing field 0: "+new String(line); |
| 420 |
b++; |
| 421 |
a=b; |
| 422 |
|
| 423 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 424 |
|
| 425 |
assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b; |
| 426 |
|
| 427 |
b++; |
| 428 |
a=b; |
| 429 |
|
| 430 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 431 |
assert(b>a) : "Missing field 2: "+new String(line); |
| 432 |
ncbi=Parse.parseInt(line, a, b); |
| 433 |
b++; |
| 434 |
a=b; |
| 435 |
|
| 436 |
return ncbi; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
public static class HashThread extends Thread { |
| 442 |
|
| 443 |
@SuppressWarnings("unchecked") |
| 444 |
public HashThread(FileFormat ff_){ |
| 445 |
|
| 446 |
mapsT=new HashMap[128]; |
| 447 |
for(int i=0; i<mapsT.length; i++){ |
| 448 |
mapsT[i]=new HashMap<String, Integer>(); |
| 449 |
} |
| 450 |
|
| 451 |
if(USE_TABLES){ |
| 452 |
table=new HashBuffer(tables.tables(), 1000, 31, true, true); |
| 453 |
} |
| 454 |
ff=ff_; |
| 455 |
} |
| 456 |
|
| 457 |
@Override |
| 458 |
public void run(){ |
| 459 |
|
| 460 |
ByteFile bf=ByteFile.makeByteFile(ff, 1); |
| 461 |
|
| 462 |
byte[] line=bf.nextLine(); |
| 463 |
while(line!=null && Tools.startsWith(line, "accession")){line=bf.nextLine();} |
| 464 |
|
| 465 |
while(line!=null){ |
| 466 |
if(line.length>0){ |
| 467 |
linesProcessedT++; |
| 468 |
bytesProcessedT+=line.length; |
| 469 |
|
| 470 |
|
| 471 |
final boolean valid=(!Tools.startsWith(line, "accession")) & !skipParse; |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
if(valid){ |
| 480 |
boolean b=parseLine2(line, (byte)'\t'); |
| 481 |
if(b){linesValidT++;} |
| 482 |
} |
| 483 |
} |
| 484 |
line=bf.nextLine(); |
| 485 |
} |
| 486 |
|
| 487 |
boolean closedError=bf.close(); |
| 488 |
|
| 489 |
|
| 490 |
for(int i=0; i<mapsT.length; i++){ |
| 491 |
if(mapsT[i].size()>0){ |
| 492 |
synchronized(maps[i]){ |
| 493 |
maps[i].putAll(mapsT[i]); |
| 494 |
} |
| 495 |
} |
| 496 |
mapsT[i]=null; |
| 497 |
} |
| 498 |
|
| 499 |
if(USE_TABLES){ |
| 500 |
long temp=table.flush(); |
| 501 |
} |
| 502 |
|
| 503 |
success=!closedError; |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
public boolean parseLine(final byte[] line, final byte delimiter){ |
| 558 |
int a=0, b=0; |
| 559 |
|
| 560 |
String accession; |
| 561 |
final int ncbi, gi; |
| 562 |
|
| 563 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 564 |
assert(b>a) : "Missing field 0: "+new String(line); |
| 565 |
accession=new String(line, a, b-a); |
| 566 |
final int dot=accession.indexOf('.'); |
| 567 |
if(dot>=0){ |
| 568 |
|
| 569 |
|
| 570 |
accession=accession.substring(0, dot); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
if(lengthCountsT!=null){lengthCountsT[b-a]++;} |
| 576 |
if(symbolCountsT!=null){ |
| 577 |
for(int i=a; i<b; i++){symbolCountsT[line[i]]++;} |
| 578 |
} |
| 579 |
final int underscore=accession.indexOf('_'); |
| 580 |
if(underscore>=0){ |
| 581 |
if(counts_underscoreT!=null){counts_underscoreT[b-a]++;} |
| 582 |
if(counts_underscore2T!=null && underscore==2){counts_underscore2T[b-a]++;} |
| 583 |
} |
| 584 |
b++; |
| 585 |
a=b; |
| 586 |
|
| 587 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 588 |
|
| 589 |
assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b; |
| 590 |
|
| 591 |
b++; |
| 592 |
a=b; |
| 593 |
|
| 594 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 595 |
assert(b>a) : "Missing field 2: "+new String(line); |
| 596 |
ncbi=Parse.parseInt(line, a, b); |
| 597 |
b++; |
| 598 |
a=b; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
if(ncbi<1){return false;} |
| 607 |
|
| 608 |
if(tree!=null){ |
| 609 |
if(ncbi>=tree.nodes.length){return false;} |
| 610 |
TaxNode tn=tree.getNode(ncbi); |
| 611 |
if(tn==null || tn.levelExtended==TaxTree.NO_RANK_E || tn.levelExtended==TaxTree.LIFE_E || tn.levelExtended==TaxTree.DOMAIN_E){return false;} |
| 612 |
if(tn.pid>=tree.nodes.length){return false;} |
| 613 |
tn=tree.getNode(tn.pid); |
| 614 |
if(tn==null || tn.levelExtended==TaxTree.NO_RANK_E || tn.levelExtended==TaxTree.LIFE_E){return false;} |
| 615 |
} |
| 616 |
|
| 617 |
if(accession.length()<13 && USE_TABLES){ |
| 618 |
long number=hash(accession); |
| 619 |
assert(number>=0) : new String(line); |
| 620 |
table.set(number, ncbi); |
| 621 |
return true; |
| 622 |
} |
| 623 |
|
| 624 |
int way=accession.charAt(0); |
| 625 |
mapsT[way].put(accession, ncbi); |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
return true; |
| 631 |
} |
| 632 |
|
| 633 |
public boolean parseLine2(final byte[] line, final byte delimiter){ |
| 634 |
int a=0, b=0; |
| 635 |
|
| 636 |
final int ncbi, gi; |
| 637 |
|
| 638 |
while(b<line.length && line[b]!=delimiter && line[b]!='.'){b++;} |
| 639 |
final int dot=b; |
| 640 |
assert(b>a) : "Missing field 0: "+new String(line); |
| 641 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
{ |
| 647 |
if(lengthCountsT!=null){lengthCountsT[dot]++;} |
| 648 |
if(symbolCountsT!=null){ |
| 649 |
for(int i=0; i<dot; i++){symbolCountsT[line[i]]++;} |
| 650 |
} |
| 651 |
if(counts_underscoreT!=null || counts_underscore2T!=null){ |
| 652 |
int underscore=-1; |
| 653 |
for(int i=0; i<dot; i++){ |
| 654 |
if(line[i]=='_'){ |
| 655 |
underscore=i; |
| 656 |
break; |
| 657 |
} |
| 658 |
} |
| 659 |
if(underscore>=0){ |
| 660 |
if(counts_underscoreT!=null){counts_underscoreT[dot]++;} |
| 661 |
if(counts_underscore2T!=null && underscore==2){counts_underscore2T[dot]++;} |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
b++; |
| 666 |
a=b; |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 671 |
|
| 672 |
assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b; |
| 673 |
|
| 674 |
b++; |
| 675 |
a=b; |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
while(b<line.length && line[b]!=delimiter){b++;} |
| 680 |
assert(b>a) : "Missing field 2: "+new String(line); |
| 681 |
ncbi=Parse.parseInt(line, a, b); |
| 682 |
|
| 683 |
b++; |
| 684 |
a=b; |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
if(ncbi<1){return false;} |
| 693 |
|
| 694 |
if(skipHash){return false;} |
| 695 |
|
| 696 |
|
| 697 |
if(tree!=null){ |
| 698 |
if(ncbi>=tree.nodes.length){return false;} |
| 699 |
|
| 700 |
TaxNode tn=tree.getNode(ncbi); |
| 701 |
if(tn==null || tn.levelExtended==TaxTree.LIFE_E || tn.levelExtended==TaxTree.DOMAIN_E){return false;} |
| 702 |
|
| 703 |
if(tn.pid>=tree.nodes.length){return false;} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
} |
| 710 |
|
| 711 |
if(USE_TABLES){ |
| 712 |
if(AnalyzeAccession.codeMap!=null){ |
| 713 |
|
| 714 |
final long number=AnalyzeAccession.digitize(line); |
| 715 |
if(number>=0){ |
| 716 |
table.set(number, ncbi); |
| 717 |
return true; |
| 718 |
} |
| 719 |
assert(number==-1) : number+", "+new String(line); |
| 720 |
}else{ |
| 721 |
if(dot<13){ |
| 722 |
|
| 723 |
final long number=hash(line, dot); |
| 724 |
assert(number>=0) : new String(line); |
| 725 |
table.set(number, ncbi); |
| 726 |
return true; |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
String accession=new String(line, 0, dot); |
| 732 |
int way=accession.charAt(0); |
| 733 |
mapsT[way].put(accession, ncbi); |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
return true; |
| 739 |
} |
| 740 |
|
| 741 |
private long linesProcessedT=0; |
| 742 |
private long linesValidT=0; |
| 743 |
private long bytesProcessedT=0; |
| 744 |
|
| 745 |
final FileFormat ff; |
| 746 |
HashMap<String, Integer>[] mapsT; |
| 747 |
HashBuffer table; |
| 748 |
boolean success=false; |
| 749 |
|
| 750 |
private long[] lengthCountsT=null; |
| 751 |
private long[] symbolCountsT=null; |
| 752 |
private long[] counts_underscoreT=null; |
| 753 |
private long[] counts_underscore2T=null; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
private ArrayList<String> in=new ArrayList<String>(); |
| 762 |
|
| 763 |
|
| 764 |
static int maxPigzProcesses=12; |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
private long linesProcessed=0; |
| 769 |
private long linesValid=0; |
| 770 |
private long bytesProcessed=0; |
| 771 |
|
| 772 |
private AtomicLongArray lengthCounts=null; |
| 773 |
private AtomicLongArray symbolCounts=null; |
| 774 |
private AtomicLongArray counts_underscore=null; |
| 775 |
private AtomicLongArray counts_underscore2=null; |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
private final FileFormat ffin[]; |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
public static boolean LOADED(){return LOADED;} |
| 786 |
|
| 787 |
private static boolean LOADED=false; |
| 788 |
private static HashMap<String, Integer>[] maps=null; |
| 789 |
private static KmerTableSet tables; |
| 790 |
public static TaxTree tree=null; |
| 791 |
|
| 792 |
public static final boolean USE_TABLES=true; |
| 793 |
|
| 794 |
public static boolean skipParse=false; |
| 795 |
public static boolean skipHash=false; |
| 796 |
public static float prealloc=0; |
| 797 |
private static final long offset=-'A'+11; |
| 798 |
private static final long offsetLower=-'a'+11; |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
private PrintStream outstream=System.err; |
| 803 |
public static boolean verbose=false; |
| 804 |
public boolean errorState=false; |
| 805 |
private boolean overwrite=true; |
| 806 |
|
| 807 |
} |