jpayne@68: package sketch; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.HashMap; jpayne@68: jpayne@68: import fileIO.ByteStreamWriter; jpayne@68: import fileIO.ReadWrite; jpayne@68: import shared.Parse; jpayne@68: import shared.Tools; jpayne@68: import structures.FloatList; jpayne@68: import tax.TaxNode; jpayne@68: import tax.TaxTree; jpayne@68: jpayne@68: class ResultLineParser { jpayne@68: jpayne@68: ResultLineParser(int mode_, TaxTree tree_, ByteStreamWriter bswBad_, ArrayList recordSets_, boolean keepText_){ jpayne@68: mode=mode_; jpayne@68: tree=tree_; jpayne@68: bswBad=bswBad_; jpayne@68: recordSets=recordSets_; jpayne@68: keepText=keepText_ || bswBad!=null; jpayne@68: for(int i=0; i split=Tools.split(line, 0, (byte)'\t'); jpayne@68: for(int col=0; col split=Tools.split(line, 0, (byte)'\t'); jpayne@68: qTaxID=Parse.parseInt(split.get(qTaxIDColumn), 0); jpayne@68: rTaxID=Parse.parseInt(split.get(rTaxIDColumn), 0); jpayne@68: qBases=Parse.parseLong(split.get(qBasesColumn), 0); jpayne@68: rBases=Parse.parseLong(split.get(rBasesColumn), 0); jpayne@68: qSize=Parse.parseLong(split.get(qSizeColumn), 0); jpayne@68: rSize=Parse.parseLong(split.get(rSizeColumn), 0); jpayne@68: ani=Parse.parseDouble(split.get(aniColumn), 0); jpayne@68: byte[] ssuArray=split.get(ssuColumn); jpayne@68: ssu=ssuArray.length==1 && ssuArray[0]=='.' ? -1 : Parse.parseDouble(ssuArray, 0); jpayne@68: taxLevelExtended=TaxTree.stringToLevelExtended(new String(split.get(caLevelColumn))); jpayne@68: if(taxLevelExtended<0) { jpayne@68: System.err.println(new String(split.get(caLevelColumn))); jpayne@68: taxLevelExtended=0; jpayne@68: } jpayne@68: processed=false; jpayne@68: } jpayne@68: jpayne@68: private TaxNode getTaxNode(String fname){ jpayne@68: String name=ReadWrite.stripToCore(fname); jpayne@68: if(name.startsWith("tid_")){ jpayne@68: int idx2=fname.indexOf('_', 4); jpayne@68: int x=Parse.parseInt(fname, 4, idx2); jpayne@68: return x>0 ? tree.getNode(x) : null; jpayne@68: //name=name.substring(idx2+1); //This would allow fall-through to name parsing jpayne@68: } jpayne@68: try { jpayne@68: return tree.getNodeByName(name); jpayne@68: } catch (Throwable e) { jpayne@68: return null; jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: private void parseDataMash(byte[] line){ jpayne@68: ///dev/shm/tid_123_Zymomonas_mobilis.fna.gz /dev/shm/tid_456_bacterium_endosymbiont_of_Bathymodiolus_sp._5_South.fna.gz 0.43859 0.00515848 1/20000 jpayne@68: jpayne@68: String[] split=new String(line).split("\t"); jpayne@68: jpayne@68: String fraction=split[split.length-1]; jpayne@68: int numerator=Integer.parseInt(fraction.split("/")[0]); jpayne@68: if(numerator map, boolean saveRecord){ jpayne@68: RecordSet old=null; jpayne@68: if(processed){return null;} jpayne@68: levelAniSums[taxLevelExtended]+=ani; jpayne@68: levelCounts[taxLevelExtended]++; jpayne@68: aniLists[taxLevelExtended].add((float)ani); jpayne@68: jpayne@68: if(ssu>0){ jpayne@68: levelSSUSums[taxLevelExtended]+=ssu; jpayne@68: levelCountsSSU[taxLevelExtended]++; jpayne@68: ssuLists[taxLevelExtended].add((float)ssu); jpayne@68: } jpayne@68: if(map!=null){ jpayne@68: long key=(((long)qTaxID)<<32)|rTaxID; jpayne@68: map.put(key, (float)ani); jpayne@68: } jpayne@68: if(saveRecord){ jpayne@68: if(currentSet==null || currentSet.qID!=qTaxID){ jpayne@68: old=currentSet; jpayne@68: currentSet=new RecordSet(qTaxID); jpayne@68: if(recordSets!=null){ jpayne@68: recordSets.add(currentSet); jpayne@68: } jpayne@68: } jpayne@68: currentSet.records.add(new Record(this)); jpayne@68: } jpayne@68: processed=true; jpayne@68: return old; jpayne@68: } jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: // final static int taxLevels=TaxTree.numTaxaNamesExtended; jpayne@68: final long[] levelCounts=new long[AnalyzeSketchResults.taxLevels]; jpayne@68: final long[] levelCountsSSU=new long[AnalyzeSketchResults.taxLevels]; jpayne@68: jpayne@68: final double[] levelAniSums=new double[AnalyzeSketchResults.taxLevels]; jpayne@68: final double[] levelSSUSums=new double[AnalyzeSketchResults.taxLevels]; jpayne@68: jpayne@68: final FloatList[] aniLists=new FloatList[AnalyzeSketchResults.taxLevels]; jpayne@68: final FloatList[] ssuLists=new FloatList[AnalyzeSketchResults.taxLevels]; jpayne@68: jpayne@68: final ArrayList recordSets; jpayne@68: jpayne@68: final int mode; jpayne@68: final TaxTree tree; jpayne@68: final ByteStreamWriter bswBad; jpayne@68: jpayne@68: int qTaxID=-1; jpayne@68: int rTaxID=-1; jpayne@68: long qBases; jpayne@68: long rBases; jpayne@68: long qSize; jpayne@68: long rSize; jpayne@68: double ani=-1; jpayne@68: double ssu=-1; jpayne@68: int taxLevelExtended=-1; jpayne@68: boolean processed=true; jpayne@68: RecordSet currentSet=null; jpayne@68: final boolean keepText; jpayne@68: jpayne@68: byte[] text=null; jpayne@68: jpayne@68: private static int qTaxIDColumn=7; jpayne@68: private static int rTaxIDColumn=8; jpayne@68: private static int qSizeColumn=3; jpayne@68: private static int rSizeColumn=4; jpayne@68: private static int qBasesColumn=5; jpayne@68: private static int rBasesColumn=6; jpayne@68: private static int aniColumn=2; jpayne@68: private static int ssuColumn=11; jpayne@68: private static int caLevelColumn=12; jpayne@68: jpayne@68: static int MIN_HITS=3; jpayne@68: jpayne@68: }