Debian Codegraph @

current/tax/AccessionToTaxid_old.java

raw symbols SCIP
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 * @author Brian Bushnell
30 * @date December 16, 2016
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 //Close the print stream if it was redirected
55 Shared.closeStream(x.outstream);
56 }
57
58 public AccessionToTaxid_old(String[] args){
59
60 {//Preparse block for help, config files, and outstream
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 // STRIP_UNDERSCORE=Parse.parseBoolean(b);
85 assert(false) : "stripunderscore is disabled.";
86 }else if(a.equals("usetables")){
87 // USE_TABLES=Parse.parseBoolean(b);
88 }else if(a.equals("usetables")){
89 // USE_TABLES=Parse.parseBoolean(b);
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 //do nothing
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 // throw new RuntimeException("Unknown parameter "+args[i]);
120 }
121 }
122
123 {//Process parser fields
124 overwrite=parser.overwrite;
125
126 // out=parser.out1;
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 // if(out!=null && out.equalsIgnoreCase("null")){out=null;}
139
140 // if(!Tools.testOutputFiles(overwrite, false, false, out)){
141 // outstream.println((out==null)+", "+out);
142 // throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out+"\n");
143 // }
144
145 {//Reorder by size, ascending
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 // ffout=FileFormat.testOutput(out, FileFormat.TXT, null, true, overwrite, false, false);
158 ffin=new FileFormat[in.size()];
159
160 /* Note */
161 /* Java 1.7 works fine here (54 seconds skipping parsing). */
162 /* Java 1.8 has immense speed-downs if pigz is used (80-100s normally, >1000s with unpigz). */
163 /* Java 1.8_144 is unpredictable and incredibly slow (80-900s normally, 500-1800 with unpigz) */
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 // if(processes>maxPigzProcesses){
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 // if(USE_MAPS){
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){//Addresses a multithreaded read bug in Java
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 //Do anything necessary after processing
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 /** Spawn process threads */
274 private void spawnThreads(FileFormat[] ffa){
275
276 //Do anything necessary prior to processing
277
278 //Fill a list with ProcessThreads
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 //Start the threads
288 for(HashThread pt : alht){
289 pt.start();
290 }
291
292 //Wait for completion of all threads
293 boolean success=true;
294 for(HashThread pt : alht){
295
296 //Wait until this thread has terminated
297 while(pt.getState()!=Thread.State.TERMINATED){
298 try {
299 //Attempt a join operation
300 pt.join();
301 } catch (InterruptedException e) {
302 //Potentially handle this, if it is expected to occur
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 //Track whether any threads failed
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 // if(STRIP_UNDERSCORE){
335 // accession=accession.replaceAll("[_-]", "");
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 // if(dot>AnalyzeAccession.longestPattern){return false;}
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>='a' && c<='z')*/ || c=='.' || c=='_' || c=='-'){
371 //do nothing
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;}//Collision, but should be OK
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;}//Collision, but should be OK
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 // assert(b>a) : "Missing field 1: "+new String(line);
425 assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b;
426 //accession2=new String(line, a, b-a);
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 // if(USE_MAPS){
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 // final boolean valid=(!Tools.startsWith(line, "accession\t")) & !skipParse;
471 final boolean valid=(!Tools.startsWith(line, "accession")) & !skipParse;
472 // assert(valid); //Not true if concatenated
473
474 // if(Tools.startsWith(line, "NZ_LM994619")){
475 // boolean b=parseLine2(line, (byte)'\t');
476 // assert(false) : b+", "+new String(line);
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 // if(USE_MAPS){
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 // public boolean parseLineNumeric(final byte[] line, final byte delimiter){
507 // int a=0, b=0;
508 //
509 // long accession=0;
510 // final int ncbi, gi;
511 //
512 // while(b<line.length && line[b]!=delimiter){b++;}
513 // assert(b>a) : "Missing field 0: "+new String(line);
514 // for(int i=a; i<b; i++){
515 // long c=line[i];
516 // if(c=='.'){break;}
517 // if(c<='9'){c=c-'0';}
518 // else{c=c-'A'+10;}
519 // accession=(accession*36)+c;
520 // }
521 // b++;
522 // a=b;
523 //
524 // while(b<line.length && line[b]!=delimiter){b++;}
525 // assert(b>a) : "Missing field 1: "+new String(line);
526 // //accession2=new String(line, a, b-a);
527 // b++;
528 // a=b;
529 //
530 // while(b<line.length && line[b]!=delimiter){b++;}
531 // assert(b>a) : "Missing field 2: "+new String(line);
532 // ncbi=Parse.parseInt(line, a, b);
533 // b++;
534 // a=b;
535 //
536 //// while(b<line.length && line[b]!=delimiter){b++;}
537 //// assert(b>a) : "Missing field 3: "+new String(line);
538 ////// gi=Parse.parseInt(line, a, b);
539 //// b++;
540 //// a=b;
541 //
542 // if(ncbi<1){return false;}
543 //
544 // if(tree!=null){
545 // if(ncbi>=tree.nodes.length){return false;}
546 // TaxNode tn=tree.getNode(ncbi);
547 // if(tn==null || tn.level==TaxTree.NO_RANK || tn.level==TaxTree.LIFE || tn.level==TaxTree.DOMAIN){return false;}
548 // if(tn.pid>=tree.nodes.length){return false;}
549 // tn=tree.getNode(tn.pid);
550 // if(tn==null || tn.level==TaxTree.NO_RANK || tn.level==TaxTree.LIFE){return false;}
551 // }
552 // assert(accession>=0) : new String(line);
553 // table.set(accession, ncbi);
554 // return true;
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){//Should never happen
568 // System.err.println(accession);
569 // assert(dot==accession.length()-2) : accession;
570 accession=accession.substring(0, dot);
571 }
572 // if(STRIP_UNDERSCORE){
573 // accession=accession.replaceAll("[_-]", "");
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 // assert(b>a) : "Missing field 1: "+new String(line);
589 assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b;
590 //accession2=new String(line, a, b-a);
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 // while(b<line.length && line[b]!=delimiter){b++;}
601 // assert(b>a) : "Missing field 3: "+new String(line);
602 //// gi=Parse.parseInt(line, a, b);
603 // b++;
604 // a=b;
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 // Integer old=mapsT[way].put(accession, ncbi);
627 // assert(old==null || old==ncbi) : "'"+accession+"': "+old+" -> "+ncbi;
628 // System.err.println("'"+accession+"': "+old+" -> "+ncbi);
629 // assert(dot==-1) : "'"+accession+"': "+old+" -> "+ncbi;
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++;}//parse unique part of accession
639 final int dot=b;
640 assert(b>a) : "Missing field 0: "+new String(line);
641 while(b<line.length && line[b]!=delimiter){b++;}//skip the rest of the accession
642
643 //System.err.println("Line: "+new String(line)+"\n"+Arrays.toString(line));
644 //System.err.println("A: dot="+dot+", a="+a+", b="+b);
645
646 {//Optional block
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 //System.err.println("B: a="+a+", b="+b);
669
670 while(b<line.length && line[b]!=delimiter){b++;}
671 // assert(b>a) : "Missing field 1: "+new String(line);
672 assert(b>=a) : "Missing field 1: "+new String(line)+"\n"+a+", "+b;
673 //accession2=new String(line, a, b-a);
674 b++;
675 a=b;
676
677 //System.err.println("C: a="+a+", b="+b);
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 //System.err.println("D: a="+a+", b="+b+", ncbi="+ncbi+", '"+(new String(line, a, b-a))+"'");
683 b++;
684 a=b;
685
686 // while(b<line.length && line[b]!=delimiter){b++;}
687 // assert(b>a) : "Missing field 3: "+new String(line);
688 //// gi=Parse.parseInt(line, a, b);
689 // b++;
690 // a=b;
691
692 if(ncbi<1){return false;}
693 //System.err.println("E: a="+a+", b="+b);
694 if(skipHash){return false;}//123
695 //System.err.println("F: a="+a+", b="+b);
696
697 if(tree!=null){
698 if(ncbi>=tree.nodes.length){return false;}
699 //System.err.println("G");
700 TaxNode tn=tree.getNode(ncbi);
701 if(tn==null || /*tn.levelExtended==TaxTree.NO_RANK_E ||*/ tn.levelExtended==TaxTree.LIFE_E || tn.levelExtended==TaxTree.DOMAIN_E){return false;}
702 //System.err.println("H: "+tn);
703 if(tn.pid>=tree.nodes.length){return false;}
704 //System.err.println("I: "+tn);
705 // TaxNode parent=tree.getNode(tn.pid);
706 // System.err.println("J: "+tn);
707 // if(tn==null || tn.levelExtended==TaxTree.NO_RANK_E || tn.levelExtended==TaxTree.LIFE_E){return false;}
708 // System.err.println("K");
709 }
710
711 if(USE_TABLES){
712 if(AnalyzeAccession.codeMap!=null){
713 // if(dot>AnalyzeAccession.longestPattern){return false;}
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 // long number=hash(accession);
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 // Integer old=mapsT[way].put(accession, ncbi);
735 // assert(old==null || old==ncbi) : "'"+accession+"': "+old+" -> "+ncbi;
736 // System.err.println("'"+accession+"': "+old+" -> "+ncbi);
737 // assert(dot==-1) : "'"+accession+"': "+old+" -> "+ncbi;
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;//new AtomicLongArray(20);
751 private long[] symbolCountsT=null;//new AtomicLongArray(255);
752 private long[] counts_underscoreT=null;//new AtomicLongArray(20);
753 private long[] counts_underscore2T=null;//new AtomicLongArray(20);
754 }
755
756 /*--------------------------------------------------------------*/
757
758
759 /*--------------------------------------------------------------*/
760
761 private ArrayList<String> in=new ArrayList<String>();
762 // private String out=null;
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;//new AtomicLongArray(20);
773 private AtomicLongArray symbolCounts=null;//new AtomicLongArray(255);
774 private AtomicLongArray counts_underscore=null;//new AtomicLongArray(20);
775 private AtomicLongArray counts_underscore2=null;//new AtomicLongArray(20);
776
777 /*--------------------------------------------------------------*/
778
779 private final FileFormat ffin[];
780 // private final FileFormat ffout;
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 // public static final boolean USE_MAPS=true;
792 public static final boolean USE_TABLES=true;
793 // public static boolean STRIP_UNDERSCORE=false;
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 }