jpayne@68: package sketch; jpayne@68: jpayne@68: import java.io.PrintStream; jpayne@68: import java.util.HashMap; jpayne@68: jpayne@68: import fileIO.FileFormat; jpayne@68: import fileIO.ReadWrite; jpayne@68: import shared.Shared; jpayne@68: import stream.ConcurrentReadInputStream; jpayne@68: import stream.FASTQ; jpayne@68: import stream.Read; jpayne@68: import structures.ListNum; jpayne@68: import tax.GiToTaxid; jpayne@68: import tax.TaxTree; jpayne@68: jpayne@68: public class SSUMap { jpayne@68: jpayne@68: public static synchronized void load(PrintStream outstream){ jpayne@68: if(r16SFile!=null && r16SMap==null){ jpayne@68: r16SMap=load(r16SFile, TaxTree.default16SFile(), outstream); jpayne@68: } jpayne@68: if(r18SFile!=null && r18SMap==null){ jpayne@68: r18SMap=load(r18SFile, TaxTree.default18SFile(), outstream); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: private static synchronized HashMap load(String ssuFile, String defaultFile, PrintStream outstream){ jpayne@68: HashMap map=null; jpayne@68: if(ssuFile!=null){ jpayne@68: final boolean oldAminoIn=Shared.AMINO_IN; jpayne@68: final boolean oldInterleaved=FASTQ.FORCE_INTERLEAVED; jpayne@68: Shared.AMINO_IN=false;//SSUs are nucleotide, which can cause a crash, esp. with IUPAC symbols jpayne@68: FASTQ.FORCE_INTERLEAVED=false; jpayne@68: jpayne@68: String fname=ssuFile; jpayne@68: if("auto".equalsIgnoreCase(fname)){fname=defaultFile;} jpayne@68: final FileFormat ffssu=FileFormat.testInput(fname, FileFormat.FA, null, true, false); jpayne@68: map=loadSSU(ffssu, outstream); jpayne@68: jpayne@68: Shared.AMINO_IN=oldAminoIn; jpayne@68: FASTQ.FORCE_INTERLEAVED=oldInterleaved; jpayne@68: } jpayne@68: return map; jpayne@68: } jpayne@68: jpayne@68: private static HashMap loadSSU(FileFormat ff, PrintStream outstream){ jpayne@68: ConcurrentReadInputStream cris=makeCris(ff, outstream); jpayne@68: HashMap map=new HashMap(1000000); jpayne@68: jpayne@68: //Grab the first ListNum of reads jpayne@68: ListNum ln=cris.nextList(); jpayne@68: jpayne@68: //Check to ensure pairing is as expected jpayne@68: if(ln!=null && !ln.isEmpty()){ jpayne@68: // if(verbose){outstream.println("Fetched "+ln.size()+" reads.");} jpayne@68: Read r=ln.get(0); jpayne@68: assert(ff.samOrBam() || (r.mate!=null)==cris.paired()); jpayne@68: } jpayne@68: jpayne@68: //As long as there is a nonempty read list... jpayne@68: while(ln!=null && ln.size()>0){ jpayne@68: if(verbose){outstream.println("Fetched "+ln.size()+" reads.");} jpayne@68: for(Read r : ln){ jpayne@68: final int tid=GiToTaxid.getID(r.id); jpayne@68: if(tid>=0 && r.length()>1000){ jpayne@68: byte[] old=map.get(tid); jpayne@68: if(old==null || old.length r16SMap=null; jpayne@68: public static HashMap r18SMap=null; jpayne@68: static boolean verbose=false; jpayne@68: static boolean errorState=false; jpayne@68: jpayne@68: }