jpayne@68: package sketch; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.Collections; jpayne@68: import java.util.Comparator; jpayne@68: import java.util.Locale; jpayne@68: import java.util.Map.Entry; jpayne@68: jpayne@68: import json.JsonObject; jpayne@68: import shared.Colors; jpayne@68: import shared.Parse; jpayne@68: import shared.Tools; jpayne@68: import structures.ByteBuilder; jpayne@68: import tax.PrintTaxonomy; jpayne@68: import tax.TaxFilter; jpayne@68: import tax.TaxNode; jpayne@68: import tax.TaxTree; jpayne@68: jpayne@68: public class DisplayParams implements Cloneable { jpayne@68: jpayne@68: @Override jpayne@68: public DisplayParams clone(){ jpayne@68: try { jpayne@68: DisplayParams copy=(DisplayParams)super.clone(); jpayne@68: if(taxFilterWhite!=null){ jpayne@68: copy.taxFilterWhite=taxFilterWhite.deepCopy(); jpayne@68: } jpayne@68: if(taxFilterBlack!=null){ jpayne@68: copy.taxFilterBlack=taxFilterBlack.deepCopy(); jpayne@68: } jpayne@68: copy.postParsed=false; jpayne@68: return copy; jpayne@68: } catch (CloneNotSupportedException e) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e.printStackTrace(); jpayne@68: throw new RuntimeException(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: public DisplayParams parseDoubleHeader(String s){ jpayne@68: if(!s.startsWith("##")){return this;} jpayne@68: // if(!s.startsWith("##")){return this.clone();} jpayne@68: StringBuilder sb=new StringBuilder(); jpayne@68: for(int i=2; i1 ? split[1] : null; jpayne@68: if(b==null || b.equalsIgnoreCase("null")){b=null;} //Normally handled by PreParser, but not in this case. jpayne@68: while(a.startsWith("-")){a=a.substring(1);} //Strip leading hyphens jpayne@68: jpayne@68: boolean x=params.parse(arg, a, b); jpayne@68: // assert(x) : "Unknown parameter "+arg+"\n"+line; jpayne@68: if(!x){System.err.println("Warning: Unknown parameter "+arg);} jpayne@68: } jpayne@68: if(SketchObject.verbose2){System.err.println("Made it to post-parse. taxFilterWhite="+params.taxFilterWhite);} jpayne@68: params.postParse(true, true); jpayne@68: if(SketchObject.verbose2){System.err.println("Passed post-parse. taxFilterWhite="+params.taxFilterWhite);} jpayne@68: jpayne@68: return params; jpayne@68: } jpayne@68: jpayne@68: public boolean parse(String arg, String a, String b){ jpayne@68: jpayne@68: if(a.equals("chunk")){ jpayne@68: chunkNum=Integer.parseInt(b); jpayne@68: }else if(a.equals("minhits") || a.equals("hits")){ jpayne@68: minHits=Integer.parseInt(b); jpayne@68: }else if(a.equalsIgnoreCase("minwkid") || a.equalsIgnoreCase("wkid")){ jpayne@68: minWKID=Float.parseFloat(b); jpayne@68: if(minWKID>1){minWKID/=100;} jpayne@68: assert(minWKID<=1) : "minWKID should between 0 and 1"; jpayne@68: }else if(a.equalsIgnoreCase("minid") || a.equalsIgnoreCase("id") || a.equalsIgnoreCase("minani") || a.equalsIgnoreCase("ani")){ jpayne@68: minANI=Float.parseFloat(b); jpayne@68: if(minANI>1){minANI/=100;} jpayne@68: assert(minANI<=1) : "minANI should between 0 and 1"; jpayne@68: if(minANI>0){ jpayne@68: minWKID=(float)Tools.max(minWKID, Comparison.aniToWkid(minANI, 32));//Lowest possible minWKID for this ANI jpayne@68: } jpayne@68: }else if(a.equals("minbases")){ jpayne@68: minBases=Integer.parseInt(b); jpayne@68: }else if(a.equals("minsizeratio")){ jpayne@68: minSizeRatio=Float.parseFloat(b); jpayne@68: // assert(minSizeRatio>=0f && minSizeRatio<=1.0f) : "\nminSizeRatio must be between 0 and 1, inclusive.\n"; jpayne@68: if(minSizeRatio>1){minSizeRatio=1f/minSizeRatio;} jpayne@68: }else if(a.equals("records") || a.equals("maxrecords") || a.equals("results")){ jpayne@68: maxRecords=Integer.parseInt(b); jpayne@68: assert(maxRecords>=1) : "Max records must be at least 1."; jpayne@68: }else if(a.equals("recordsperlevel")){ jpayne@68: recordsPerLevel=Integer.parseInt(b); jpayne@68: }else if(a.equals("format")){ jpayne@68: assert(b!=null) : "Invalid format: "+arg; jpayne@68: if(b.equalsIgnoreCase("json")){ jpayne@68: format=FORMAT_JSON; jpayne@68: }else if(b.equalsIgnoreCase("jsonarray")){ jpayne@68: format=FORMAT_JSON; jpayne@68: jsonArray=true; jpayne@68: }else if(b.equalsIgnoreCase("d3")){ jpayne@68: format=FORMAT_JSON; jpayne@68: printD3=true; jpayne@68: }else if(b.equalsIgnoreCase("constellation")){ jpayne@68: format=FORMAT_CONSTELLATION; jpayne@68: }else if(b.equalsIgnoreCase("3column") || b.equalsIgnoreCase("queryrefani")){ jpayne@68: format=FORMAT_QUERY_REF_ANI; jpayne@68: }else if(Tools.isDigit(b.charAt(0))){ jpayne@68: format=Integer.parseInt(b); jpayne@68: }else{ jpayne@68: assert(false) : "Invalid format: "+arg; jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("json")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: format=FORMAT_JSON; jpayne@68: }else{ jpayne@68: if(format==FORMAT_JSON){format=default_format;} jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("jsonarray") || a.equalsIgnoreCase("jsonarrays")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: format=FORMAT_JSON; jpayne@68: jsonArray=true; jpayne@68: }else{ jpayne@68: jsonArray=false; jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("d3") || a.equalsIgnoreCase("printd3")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: format=FORMAT_JSON; jpayne@68: printD3=true; jpayne@68: }else{ jpayne@68: printD3=false; jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("jsonarray") || a.equalsIgnoreCase("jsonarrays")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: jsonArray=true; jpayne@68: }else{ jpayne@68: jsonArray=false; jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("d3levelnodes")){ jpayne@68: D3LevelNodes=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("d3hitsize")){ jpayne@68: if(Parse.parseBoolean(b)){D3sizeMode=D3_HIT_SIZE;} jpayne@68: }else if(a.equalsIgnoreCase("d3anisize")){ jpayne@68: if(Parse.parseBoolean(b)){D3sizeMode=D3_ANI_SIZE;} jpayne@68: }else if(a.equalsIgnoreCase("d3wkidsize")){ jpayne@68: if(Parse.parseBoolean(b)){D3sizeMode=D3_WKID_SIZE;} jpayne@68: }else if(a.equalsIgnoreCase("d3depthsize")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: D3sizeMode=D3_DEPTH_SIZE; jpayne@68: printDepth=true; jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("d3kidsize")){ jpayne@68: if(Parse.parseBoolean(b)){D3sizeMode=D3_KID_SIZE;} jpayne@68: }else if(a.equalsIgnoreCase("D3sizeMode")){ jpayne@68: D3sizeMode=Integer.parseInt(b); jpayne@68: }else if(a.equals("level") || a.equals("lv") || a.equals("taxlevel") || a.equals("tl") || a.equals("minlevel")){ jpayne@68: taxLevel=TaxTree.parseLevel(b);//TODO: Change to extended jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("requireSSU")){ jpayne@68: requireSSU=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("minRefSizeEstimate") || a.equalsIgnoreCase("minRefSize")){ jpayne@68: minRefSizeEstimate=Long.parseLong(b); jpayne@68: }else if(a.equalsIgnoreCase("minRefSizeBases")){ jpayne@68: minRefSizeBases=Long.parseLong(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printtax") || a.equalsIgnoreCase("printtaxa")){ jpayne@68: printTax=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printssu") || a.equalsIgnoreCase("print16s") || a.equalsIgnoreCase("ssu")){ jpayne@68: printSSU=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printSSULen") || a.equalsIgnoreCase("print16slen") || a.equalsIgnoreCase("ssulen")){ jpayne@68: printSSULen=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printssusequence") || a.equalsIgnoreCase("print16ssequence")){ jpayne@68: printSSUSequence=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printqueryfilename") || a.equalsIgnoreCase("printqfname") || a.equalsIgnoreCase("printqfile") || a.equalsIgnoreCase("qfname")){ jpayne@68: printQueryFileName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printreffilename") || a.equalsIgnoreCase("printrfname") || a.equalsIgnoreCase("printrfile") || a.equalsIgnoreCase("rfname")){ jpayne@68: printRefFileName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printfilename") || a.equalsIgnoreCase("printfname") || a.equalsIgnoreCase("printfile")){ jpayne@68: printQueryFileName=printRefFileName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printoriginalname") || a.equalsIgnoreCase("printseqname") || a.equalsIgnoreCase("printname0") || a.equals("pn0")){ jpayne@68: printOriginalName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printimg")){ jpayne@68: printImg=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printcompleteness") || a.equalsIgnoreCase("completeness") || a.equalsIgnoreCase("printcomplt")){ jpayne@68: printCompleteness=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printani") || a.equalsIgnoreCase("ani")){ jpayne@68: printAni=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printkid") || a.equalsIgnoreCase("kid")){ jpayne@68: printKID=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printwkid") || a.equalsIgnoreCase("wkid")){ jpayne@68: printWKID=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printscore") || a.equalsIgnoreCase("score")){ jpayne@68: printScore=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printevalue") || a.equalsIgnoreCase("evalue")){ jpayne@68: printEValue=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("trackcounts")){ jpayne@68: trackCounts=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printdepth") || a.equalsIgnoreCase("depth")){ jpayne@68: printDepth=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printdepth2") || a.equalsIgnoreCase("depth2")){ jpayne@68: printDepth2=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("actualdepth") || a.equalsIgnoreCase("printactualdepth")){ jpayne@68: printActualDepth=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printvolume") || a.equalsIgnoreCase("volume")){ jpayne@68: printVolume=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printavgrefhits") || a.equalsIgnoreCase("printrefhits") || a.equalsIgnoreCase("avgrefhits") || a.equalsIgnoreCase("refhits")){ jpayne@68: printRefHits=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("sortByDepth")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.depthComparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortByDepth2")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.depth2Comparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortByVolume")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.volumeComparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortByScore")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.scoreComparator;} jpayne@68: } jpayne@68: else if(a.equalsIgnoreCase("sortByKID")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.KIDComparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortByWKID") || a.equalsIgnoreCase("sortByANI")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.WKIDComparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortBySSU") || a.equalsIgnoreCase("sortBy16S")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.SSUComparator;} jpayne@68: }else if(a.equalsIgnoreCase("sortByHits") || a.equalsIgnoreCase("sortByMatches")){ jpayne@68: boolean x=Parse.parseBoolean(b); jpayne@68: if(x){comparator=Comparison.HitsComparator;} jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printUMatches") || a.equalsIgnoreCase("printUHits") || a.equalsIgnoreCase("printUnique")){ jpayne@68: printUnique=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printUMatches2") || a.equalsIgnoreCase("printUnique2") || a.equalsIgnoreCase("unique2")){ jpayne@68: printUnique2=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printUMatches3") || a.equalsIgnoreCase("printUnique3") || a.equalsIgnoreCase("unique3")){ jpayne@68: printUnique3=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printUContam")){ jpayne@68: printUContam=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printNoHit")){ jpayne@68: printNoHit=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("contamhits") || a.equalsIgnoreCase("contam") || a.equalsIgnoreCase("printcontam")){ jpayne@68: printContam=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("contamhits2") || a.equalsIgnoreCase("contam2") || a.equalsIgnoreCase("printcontam2")){ jpayne@68: if(b==null || b.length()<1){ jpayne@68: printContam2=true; jpayne@68: }else if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ jpayne@68: contamLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); jpayne@68: printContam2=true; jpayne@68: }else if(TaxTree.levelMapExtendedContains(b)){ jpayne@68: contamLevel=TaxTree.stringToLevelExtended(b); jpayne@68: printContam2=true; jpayne@68: }else{ jpayne@68: printContam2=Parse.parseBoolean(b); jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("contamLevel")){ jpayne@68: if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ jpayne@68: contamLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); jpayne@68: printContam2=true; jpayne@68: }else if(TaxTree.levelMapExtendedContains(b)){ jpayne@68: contamLevel=TaxTree.stringToLevelExtended(b); jpayne@68: printContam2=true; jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("reportAniOnly") || a.equalsIgnoreCase("AniOnly")){ jpayne@68: reportAniOnly=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printMatches")){ jpayne@68: printMatches=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printLength")){ jpayne@68: printLength=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printTaxID")){ jpayne@68: printTaxID=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printGSize")){ jpayne@68: printGSize=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("gSizeKMG")){ jpayne@68: gSizeKMG=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printGC")){ jpayne@68: printGC=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printGKmers")){ jpayne@68: printGKmers=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printCommonAncestor") || a.equalsIgnoreCase("printCA")){ jpayne@68: printCommonAncestor=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printCommonAncestorLevel") || a.equalsIgnoreCase("printCAL")){ jpayne@68: printCommonAncestorLevel=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printTaxName")){ jpayne@68: printTaxName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printGSeqs")){ jpayne@68: printGSeqs=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printGBases")){ jpayne@68: printGBases=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("minEntropy") || a.equalsIgnoreCase("entropy") || a.equalsIgnoreCase("efilter")){ jpayne@68: minEntropy=Float.parseFloat(b); jpayne@68: }else if(a.equalsIgnoreCase("minprob") || a.equalsIgnoreCase("pfilter")){ jpayne@68: minProb=(float)Double.parseDouble(b); jpayne@68: }else if(a.equalsIgnoreCase("minQual") || a.equalsIgnoreCase("minq")){ jpayne@68: minQual=Byte.parseByte(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printColors") || a.equalsIgnoreCase("colors") || a.equalsIgnoreCase("color")){ jpayne@68: // System.err.println("Parsing '"+arg+"'"); //123 jpayne@68: if(b==null || b.length()<1){ jpayne@68: printColors=true; jpayne@68: }else if(b.equalsIgnoreCase("t") || b.equalsIgnoreCase("true")){ jpayne@68: printColors=true; jpayne@68: }else if(b.equalsIgnoreCase("f") || b.equalsIgnoreCase("false")){ jpayne@68: printColors=false; jpayne@68: }else{ jpayne@68: printColors=true; jpayne@68: if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ jpayne@68: colorLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); jpayne@68: }else{ jpayne@68: colorLevel=TaxTree.stringToLevelExtended(b); jpayne@68: } jpayne@68: } jpayne@68: setColors=true; jpayne@68: // System.err.println("Parsed "+arg); //123 jpayne@68: }else if(a.equalsIgnoreCase("colorLevel")){ jpayne@68: // System.err.println("Parsing '"+arg+"'"); //123 jpayne@68: if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ jpayne@68: colorLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); jpayne@68: }else{ jpayne@68: colorLevel=TaxTree.stringToLevelExtended(b); jpayne@68: } jpayne@68: // System.err.println("Parsed "+arg); //123 jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printRefDivisor") || a.equalsIgnoreCase("printRDiv")){ jpayne@68: printRefDivisor=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printQueryDivisor") || a.equalsIgnoreCase("printQDiv")){ jpayne@68: printQueryDivisor=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printRefSize") || a.equalsIgnoreCase("printRSize")){ jpayne@68: printRefSize=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printQuerySize") || a.equalsIgnoreCase("printQSize")){ jpayne@68: printQuerySize=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("printContamHits") || a.equalsIgnoreCase("printCHits")){ jpayne@68: printContamHits=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printIntersection") || a.equalsIgnoreCase("intersection") || a.equalsIgnoreCase("intersect")){ jpayne@68: printIntersection=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("mergePairs") || a.equalsIgnoreCase("merge")){ jpayne@68: mergePairs=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("printAll")){ jpayne@68: if(Parse.parseBoolean(b)){ jpayne@68: setPrintAll(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: else if(a.equals("samplerate")){ jpayne@68: samplerate=Float.parseFloat(b); jpayne@68: }else if(a.equals("reads")){ jpayne@68: maxReads=Parse.parseKMG(b); jpayne@68: }else if(a.equals("mode") || a.equalsIgnoreCase("single") || a.equalsIgnoreCase("singlesketch") || a.equalsIgnoreCase("onesketch") jpayne@68: || a.equalsIgnoreCase("persequence") || a.equalsIgnoreCase("sequence") || a.equalsIgnoreCase("pertaxa") jpayne@68: || a.equalsIgnoreCase("perheader") || a.equalsIgnoreCase("perfile")){ jpayne@68: mode=SketchObject.parseMode(arg, a, b); jpayne@68: } jpayne@68: jpayne@68: //For format 3 jpayne@68: else if(a.equalsIgnoreCase("useTaxidName") || a.equalsIgnoreCase("useTaxidAsName")){ jpayne@68: useTaxidName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("useImgName") || a.equalsIgnoreCase("useImgAsName")){ jpayne@68: useImgName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("useTaxName") || a.equalsIgnoreCase("useTaxAsName")){ jpayne@68: useTaxName=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("useFilePrefixName") || a.equalsIgnoreCase("useFilePrefixAsName")){ jpayne@68: useFilePrefixName=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("taxfilterincludelevel") || a.equalsIgnoreCase("includelevel") jpayne@68: || a.equalsIgnoreCase("taxlevelwhite") || a.equalsIgnoreCase("ilevel") || a.equalsIgnoreCase("whitelevel")){ jpayne@68: taxLevelWhite=TaxTree.parseLevel(b);//TODO: Change to extended jpayne@68: }else if(a.equalsIgnoreCase("taxfilterinclude") || a.equalsIgnoreCase("include") || a.equalsIgnoreCase("taxfilterwhitelist")){ jpayne@68: taxFilterWhiteList=b; jpayne@68: }else if(a.equalsIgnoreCase("taxfilterincludestring") || a.equalsIgnoreCase("includestring") jpayne@68: || a.equalsIgnoreCase("taxfilterwhitestring") || a.equalsIgnoreCase("istring")){ jpayne@68: taxFilterWhiteString=b; jpayne@68: }else if(a.equalsIgnoreCase("banUnclassified") || a.equalsIgnoreCase("noUnclassified")){ jpayne@68: banUnclassified=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("banVirus") || a.equalsIgnoreCase("noVirus") || a.equalsIgnoreCase("banViruses") || a.equalsIgnoreCase("noViruses")){ jpayne@68: banVirus=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("taxfilterexcludelevel") || a.equalsIgnoreCase("excludelevel") jpayne@68: || a.equalsIgnoreCase("taxlevelblack") || a.equalsIgnoreCase("elevel") || a.equalsIgnoreCase("blacklevel")){ jpayne@68: taxLevelBlack=TaxTree.parseLevel(b);//TODO: Change to extended jpayne@68: }else if(a.equalsIgnoreCase("taxfilterexclude") || a.equalsIgnoreCase("exclude") || a.equalsIgnoreCase("taxfilterblacklist")){ jpayne@68: taxFilterBlackList=b; jpayne@68: }else if(a.equalsIgnoreCase("taxfilterexcludestring") || a.equalsIgnoreCase("excludestring") jpayne@68: || a.equalsIgnoreCase("taxfilterblackstring") || a.equalsIgnoreCase("estring")){ jpayne@68: taxFilterBlackString=b; jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("minkmercount") || a.equalsIgnoreCase("minkeycount") || a.equalsIgnoreCase("mincount") || a.equalsIgnoreCase("minKeyOccuranceCount")){ jpayne@68: minKeyOccuranceCount=Tools.max(1, Integer.parseInt(b)); jpayne@68: } jpayne@68: jpayne@68: //TODO: Eventually remove support for "amino" and "k" and just support "hamino" and "hk" jpayne@68: //This stands for "header amino" and "header k". jpayne@68: jpayne@68: //Parameters for compatibility verification jpayne@68: else if(a.equalsIgnoreCase("k") || a.equalsIgnoreCase("hk")){ jpayne@68: // System.err.println("A: k="+k+", k2="+k2+", arg="+arg); jpayne@68: if(b.indexOf(',')>=0){ jpayne@68: String[] split=b.split(","); jpayne@68: assert(split.length==2) : "\nBad argument "+arg+"\n"+b+"\n"; jpayne@68: int x=Integer.parseInt(split[0]); jpayne@68: int y=Integer.parseInt(split[1]); jpayne@68: k=Tools.max(x, y); jpayne@68: k2=Tools.min(x, y); jpayne@68: if(k==k2){k2=0;} jpayne@68: // System.err.println("B: k="+k+", k2="+k2+", split="+Arrays.toString(split)); jpayne@68: }else{ jpayne@68: k=Integer.parseInt(b); jpayne@68: // System.err.println("C: k="+k+", k2="+k2); jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("hashversion") || a.equalsIgnoreCase("hv")){ jpayne@68: hashVersion=Integer.parseInt(b); jpayne@68: }else if(a.equalsIgnoreCase("amino") || a.equalsIgnoreCase("hamino")){ jpayne@68: amino=Parse.parseBoolean(b); jpayne@68: if(amino){translate=false;} jpayne@68: }else if(a.equalsIgnoreCase("translate")){ jpayne@68: translate=Parse.parseBoolean(b); jpayne@68: if(translate){amino=false;} jpayne@68: }else if(a.equalsIgnoreCase("sixframes")){ jpayne@68: sixframes=Parse.parseBoolean(b); jpayne@68: if(sixframes){amino=false; translate=true;} jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("requiredmeta") || a.equalsIgnoreCase("rmeta")){ jpayne@68: if(b==null){requiredMeta=null;} jpayne@68: else{ jpayne@68: String[] split2=b.split(","); jpayne@68: requiredMeta=new ArrayList(split2.length); jpayne@68: for(String mt : split2){ jpayne@68: assert(mt.indexOf(':')>=0) : "Metadata tags must contain ':' symbol: "+mt; jpayne@68: requiredMeta.add(mt); jpayne@68: } jpayne@68: } jpayne@68: }else if(a.equalsIgnoreCase("bannedmeta") || a.equalsIgnoreCase("bmeta")){ jpayne@68: if(b==null){bannedMeta=null;} jpayne@68: else{ jpayne@68: String[] split2=b.split(","); jpayne@68: bannedMeta=new ArrayList(split2.length); jpayne@68: for(String mt : split2){ jpayne@68: assert(mt.indexOf(':')>=0) : "Metadata tags must contain ':' symbol: "+mt; jpayne@68: bannedMeta.add(mt); jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: // else if(a.equalsIgnoreCase("requiredtaxid") || a.equalsIgnoreCase("rtaxid")){ jpayne@68: // if(b==null){requiredTaxid=null;} jpayne@68: // else{ jpayne@68: // String[] split2=b.split(","); jpayne@68: // requiredTaxid=new IntList(split2.length); jpayne@68: // for(String mt : split2){ jpayne@68: // requiredTaxid.add(Integer.parseInt(mt)); jpayne@68: // } jpayne@68: // if(requiredTaxid.isEmpty()){requiredTaxid=null;} jpayne@68: // } jpayne@68: // }else if(a.equalsIgnoreCase("bannedtaxid") || a.equalsIgnoreCase("btaxid")){ jpayne@68: // if(b==null){bannedTaxid=null;} jpayne@68: // else{ jpayne@68: // String[] split2=b.split(","); jpayne@68: // bannedTaxid=new IntList(split2.length); jpayne@68: // for(String mt : split2){ jpayne@68: // bannedTaxid.add(Integer.parseInt(mt)); jpayne@68: // } jpayne@68: // if(bannedTaxid.isEmpty()){bannedTaxid=null;} jpayne@68: // } jpayne@68: // } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("requiredmetaand") || a.equalsIgnoreCase("rmetaand")){ jpayne@68: requiredMetaAnd=Parse.parseBoolean(b); jpayne@68: }else if(a.equalsIgnoreCase("requiredmetaor") || a.equalsIgnoreCase("rmetaor")){ jpayne@68: requiredMetaAnd=!Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equalsIgnoreCase("bbversion")){ jpayne@68: inputVersion=b; jpayne@68: } jpayne@68: jpayne@68: else{ jpayne@68: return false; jpayne@68: } jpayne@68: return true; jpayne@68: } jpayne@68: jpayne@68: public void postParse(boolean requireTree, boolean makeTaxFilters){ jpayne@68: assert(!postParsed); jpayne@68: synchronized(this){ jpayne@68: if(postParsed){return;} jpayne@68: jpayne@68: if(makeTaxFilters){ jpayne@68: if(taxFilterWhiteList!=null || taxFilterWhiteString!=null){ jpayne@68: taxFilterWhite=new TaxFilter(SketchObject.taxtree, true); jpayne@68: taxFilterWhite.setLevel(taxLevelWhite, false); jpayne@68: taxFilterWhite.makeSet(); jpayne@68: taxFilterWhite.addNamesOrNumbers(taxFilterWhiteList, false); jpayne@68: taxFilterWhite.setContainsString(taxFilterWhiteString); jpayne@68: if(requireTree){ jpayne@68: assert(SketchObject.taxtree!=null) : "No taxtree loaded."; jpayne@68: taxFilterWhite.setTree(SketchObject.taxtree); jpayne@68: taxFilterWhite.promote(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: if(taxFilterBlackList!=null || taxFilterBlackString!=null){ jpayne@68: taxFilterBlack=new TaxFilter(SketchObject.taxtree, false); jpayne@68: taxFilterBlack.setLevel(taxLevelBlack, false); jpayne@68: taxFilterBlack.makeSet(); jpayne@68: taxFilterBlack.addNamesOrNumbers(taxFilterBlackList, false); jpayne@68: taxFilterBlack.setContainsString(taxFilterBlackString); jpayne@68: if(requireTree){ jpayne@68: assert(SketchObject.taxtree!=null) : "No taxtree loaded."; jpayne@68: taxFilterBlack.setTree(SketchObject.taxtree); jpayne@68: taxFilterBlack.promote(); jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: noFilters=(!hasMetaFilters() && !hasTaxFilters() && !requireSSU && minRefSizeEstimate<1 && minRefSizeBases<1); jpayne@68: postParsed=true; jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: public boolean postParsed(){return postParsed;} jpayne@68: jpayne@68: @Override jpayne@68: public String toString(){ jpayne@68: return toString(-1); jpayne@68: } jpayne@68: jpayne@68: public String toString(int chunkNum){ jpayne@68: StringBuilder sb=new StringBuilder(); jpayne@68: sb.append("##"); jpayne@68: sb.append("hits=").append(minHits); jpayne@68: if(chunkNum>=0){sb.append(" chunk=").append(chunkNum);} jpayne@68: sb.append(" wkid=").append(String.format(Locale.ROOT, "%.5f",minWKID)); jpayne@68: if(minANI>0){sb.append(" id=").append(String.format(Locale.ROOT, "%.5f",minANI));} jpayne@68: if(minBases>0){sb.append(" minbases=").append(minBases);} jpayne@68: if(minSizeRatio>0){sb.append(" minsizeratio=").append(String.format(Locale.ROOT, "%.5f",minSizeRatio));} jpayne@68: sb.append(" records=").append(maxRecords); jpayne@68: if(recordsPerLevel>0){sb.append(" recordsperlevel=").append(recordsPerLevel);} jpayne@68: sb.append(" format=").append(format); jpayne@68: sb.append(" level=").append(taxLevel); jpayne@68: if(inputVersion!=null){sb.append(" bbversion=").append(inputVersion);} jpayne@68: jpayne@68: if(k!=SketchObject.defaultK || k2!=0 || k!=SketchObject.k || k2!=SketchObject.k2){ jpayne@68: assert(k>0 && k2>=0 && k20 && SketchObject.k2>=0 && SketchObject.k2 list1=new ArrayList(j0.jmapSize()); jpayne@68: Object[] keys=null; jpayne@68: for(Entry e1 : j0.jmap.entrySet()){ jpayne@68: JsonObject j1=e1.getValue(); jpayne@68: ArrayList list2=new ArrayList(j1.omapSize()); jpayne@68: for(Entry e2 : j1.omap.entrySet()){ jpayne@68: Object o2=e2.getValue(); jpayne@68: list2.add(o2); jpayne@68: } jpayne@68: list1.add(list2.toArray()); jpayne@68: if(keys==null){ jpayne@68: ArrayList keyList=new ArrayList(j1.omapSize()); jpayne@68: for(Entry e2 : j1.omap.entrySet()){ jpayne@68: Object o2=e2.getKey(); jpayne@68: keyList.add(o2); jpayne@68: } jpayne@68: keys=keyList.toArray(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: JsonObject title=new JsonObject(); jpayne@68: for(Entry e : j0.omap.entrySet()){ jpayne@68: title.add(e.getKey(), e.getValue()); jpayne@68: } jpayne@68: jpayne@68: j0.clearJson(); jpayne@68: j0.clearOmap(); jpayne@68: jpayne@68: j0.add("title", title); jpayne@68: j0.add("header", keys); jpayne@68: j0.add("rows", list1.toArray()); jpayne@68: } jpayne@68: jpayne@68: public JsonObject toJson(Sketch sk){ jpayne@68: assert(format==FORMAT_JSON); jpayne@68: jpayne@68: JsonObject j=new JsonObject(); jpayne@68: j.add("Name", sk.name()); jpayne@68: if(dbName!=null){j.add("DB", dbName);} jpayne@68: j.add("SketchLen", sk.length()); jpayne@68: jpayne@68: j.add("Seqs", sk.genomeSequences); jpayne@68: j.add("Bases", sk.genomeSizeBases); jpayne@68: j.add("gSize", sk.genomeSizeEstimate()); jpayne@68: if(sk.baseCounts!=null){j.addLiteral("GC", sk.gc(), 3);} jpayne@68: if(sk.probCorrect<1 && sk.probCorrect>0){j.add("Quality", sk.probCorrect);} jpayne@68: if(sk.keyCounts!=null){ jpayne@68: double d=Tools.averageDouble(sk.keyCounts); jpayne@68: j.add("AvgCount", d); jpayne@68: j.add("Depth", Tools.observedToActualCoverage(d)); jpayne@68: } jpayne@68: jpayne@68: if(sk.imgID>0){j.add("IMG", sk.imgID);} jpayne@68: if(sk.spid>0){j.add("spid", sk.spid);} jpayne@68: if(sk.taxID>0 && sk.taxID0){j.add("16SLen", sk.r16SLen());} jpayne@68: if(sk.r18SLen()>0){j.add("18SLen", sk.r18SLen());} jpayne@68: } jpayne@68: if(printSSUSequence){ jpayne@68: if(sk.r16S()!=null){j.add("16SSequence", new String(sk.r16S()));} jpayne@68: if(sk.r18S()!=null){j.add("18SSequence", new String(sk.r18S()));} jpayne@68: } jpayne@68: jpayne@68: return j; jpayne@68: } jpayne@68: jpayne@68: public JsonObject toJson(Comparison c){ jpayne@68: final int tid=c.taxID; jpayne@68: jpayne@68: JsonObject j=new JsonObject(); jpayne@68: jpayne@68: //Text fields jpayne@68: if(printTaxName){j.add("taxName", c.taxName()==null ? "." : c.taxName());} jpayne@68: jpayne@68: if(printCommonAncestor){j.add("commonAncestor", c.commonAncestor());} jpayne@68: if(printCommonAncestorLevel){j.add("commonAncestorLevel", c.commonAncestorLevel());} jpayne@68: jpayne@68: if(printRefFileName){j.add("file", c.fname()==null ? "." : c.fname());} jpayne@68: if(printOriginalName){j.add("seqName", c.name0()==null ? "." : c.name0());} jpayne@68: if(printTax && SketchObject.taxtree!=null){ jpayne@68: TaxNode tn=null; jpayne@68: if(tid>0 && tid0){j.addLiteral("SSU", 100*c.ssuIdentity(), 3);} //Old jpayne@68: if(printSSU() && c.ssuIdentity()>0){ jpayne@68: j.addLiteral(c.ssuType()==18 ? "18S" : "16S", 100*c.ssuIdentity(), 3); jpayne@68: } jpayne@68: jpayne@68: //Primary fields jpayne@68: if(printAni){j.addLiteral((aminoOrTranslate() ? "AAI" : "ANI"), 100*c.ani(), 3);} jpayne@68: if(printCompleteness){j.addLiteral("Complt", 100*c.completeness(), 3);} jpayne@68: if(printContam){j.addLiteral("Contam", 100*c.contamFraction(), 3);} jpayne@68: if(printContam2){j.addLiteral("Contam2", 100*c.contam2Fraction(), 3);} jpayne@68: if(printUContam){j.addLiteral("uContam", 100*c.uContamFraction(), 3);} jpayne@68: if(printScore){j.add("Score", c.score());} jpayne@68: if(printEValue){j.add("E-Val", String.format(Locale.ROOT, "%5.2e", c.eValue()));} jpayne@68: jpayne@68: if(printDepth){j.add("Depth", c.depth(printActualDepth));} jpayne@68: if(printDepth2){j.add("Depth2", c.depth2(printActualDepth));} jpayne@68: if(printVolume){j.add("Volume", c.volume()+0.001);} jpayne@68: if(printRefHits){j.add("RefHits", c.avgRefHits());} jpayne@68: jpayne@68: if(printMatches){j.add("Matches", c.hits());} jpayne@68: if(printUnique){j.add("Unique", c.uHits());} jpayne@68: if(printUnique2){j.add("Unique2", c.unique2());} jpayne@68: if(printUnique3){j.add("Unique3", c.unique3());} jpayne@68: if(printNoHit){j.add("noHit", c.noHits());} jpayne@68: if(printLength){j.add("Length", c.maxDivisor());} jpayne@68: if(printTaxID){j.add("TaxID", tid>=SketchObject.minFakeID ? -1 : tid);} jpayne@68: if(printImg){j.add("ImgID", c.imgID());} jpayne@68: if(printGBases){j.add("gBases", c.genomeSizeBases());} jpayne@68: if(printGKmers){j.add("gKmers", c.genomeSizeKmers());} jpayne@68: if(printGSize){j.add("gSize", c.genomeSizeEstimate());} jpayne@68: if(printGSeqs){j.add("gSeqs", c.genomeSequences());} jpayne@68: if(c.hasGC()){j.addLiteral("GC", c.gc(), 3);} jpayne@68: jpayne@68: //Raw fields jpayne@68: if(printRefDivisor){j.add("rDiv", c.refDivisor());} jpayne@68: if(printQueryDivisor){j.add("qDiv", c.queryDivisor());} jpayne@68: if(printRefSize){j.add("rSize", c.refSize());} jpayne@68: if(printQuerySize){j.add("qSize", c.querySize());} jpayne@68: if(printContamHits){j.add("cHits", c.contamHits());} jpayne@68: jpayne@68: jpayne@68: jpayne@68: if(printSSULen){ jpayne@68: if(c.has18S()){j.add("18SLen", c.b.r18SLen());} jpayne@68: /*else*/ if(c.has16S()){j.add("16SLen", c.b.r16SLen());} jpayne@68: } jpayne@68: if(printSSUSequence){ jpayne@68: if(c.has18S()){j.add("18SSequence", new String(c.b.r18S()));} jpayne@68: /*else*/ if(c.has16S()){j.add("16SSequence", new String(c.b.r16S()));} jpayne@68: } jpayne@68: jpayne@68: if(printIntersection){ jpayne@68: Sketch intersection=Sketch.intersection(c.a, c.b); jpayne@68: j.add("intersection", intersection.toString()); jpayne@68: } jpayne@68: jpayne@68: return j; jpayne@68: } jpayne@68: jpayne@68: public boolean json(){return format==FORMAT_JSON;} jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- D3 ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: public JsonObject toD3(SketchResults sr){ jpayne@68: if(sr==null || sr.isEmpty()){return new JsonObject("name", "no hits");} jpayne@68: JsonObject root=new JsonObject("name", "life"); jpayne@68: root.add("level", TaxTree.LIFE_E); jpayne@68: if(sr.list!=null){ jpayne@68: int i=0; jpayne@68: for(Comparison c : sr.list){ jpayne@68: ArrayList tax=toD3List(c); jpayne@68: addToLevel(root, tax, 0); jpayne@68: i++; jpayne@68: if(i>=maxRecords){break;} jpayne@68: } jpayne@68: } jpayne@68: if(D3LevelNodes){ jpayne@68: root=converToD3ArrayFormat_LevelNode(root); jpayne@68: }else{ jpayne@68: root=converToD3ArrayFormat_SingleNodeRoot(root); jpayne@68: } jpayne@68: return root; jpayne@68: } jpayne@68: jpayne@68: private JsonObject converToD3ArrayFormat_SingleNodeRoot(JsonObject root){ jpayne@68: JsonObject children=root.removeJson("children"); jpayne@68: if(children==null){return root;} jpayne@68: Object[] array=children.toJmapArray(); jpayne@68: root=(JsonObject)array[0];//Life node jpayne@68: jpayne@68: assert(root.getString("name").equalsIgnoreCase("Life")) : root; jpayne@68: return converToD3ArrayFormat_SingleNode(root); jpayne@68: } jpayne@68: jpayne@68: private JsonObject converToD3ArrayFormat_SingleNode(JsonObject nameNode){ jpayne@68: Object[] levelNodes=nameNode.toJmapArray(); jpayne@68: if(levelNodes==null){return nameNode;} jpayne@68: nameNode.clearJson(); jpayne@68: jpayne@68: ArrayList fixed=new ArrayList(); jpayne@68: for(Object o : levelNodes){ jpayne@68: JsonObject levelNode=(JsonObject)o; jpayne@68: String level=levelNode.getString("name"); jpayne@68: JsonObject children=levelNode.removeJson("children"); jpayne@68: if(children!=null){ jpayne@68: Object[] childArray=children.toJmapArray(); jpayne@68: for(Object o2 : childArray){ jpayne@68: JsonObject child=(JsonObject)o2;//Now a name node jpayne@68: String name=(String)child.removeObject("name"); jpayne@68: child.add("name", level+": "+name); jpayne@68: converToD3ArrayFormat_SingleNode(child); jpayne@68: fixed.add(child); jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: Object[] children=fixed.toArray(); jpayne@68: nameNode.add("children", children); jpayne@68: return nameNode; jpayne@68: } jpayne@68: jpayne@68: private JsonObject converToD3ArrayFormat_LevelNode(JsonObject levelNode){ jpayne@68: JsonObject children=levelNode.removeJson("children"); jpayne@68: if(children==null){return levelNode;} jpayne@68: jpayne@68: Object[] array=children.toJmapArray(); jpayne@68: levelNode.add("children", array); jpayne@68: for(Object o : array){ jpayne@68: converToD3ArrayFormat_NameNode((JsonObject)o); jpayne@68: } jpayne@68: return levelNode; jpayne@68: } jpayne@68: jpayne@68: private JsonObject converToD3ArrayFormat_NameNode(JsonObject nameNode){ jpayne@68: Object[] array=nameNode.toJmapArray(); jpayne@68: if(array==null){return nameNode;} jpayne@68: jpayne@68: nameNode.clearJson(); jpayne@68: nameNode.add("children", array); jpayne@68: for(Object o : array){ jpayne@68: converToD3ArrayFormat_LevelNode((JsonObject)o); jpayne@68: } jpayne@68: return nameNode; jpayne@68: } jpayne@68: jpayne@68: void addToLevel(JsonObject levelNode, ArrayList list, int pos){ jpayne@68: JsonObject jo=list.get(pos); jpayne@68: int rootLevel=levelNode.getInt("level"); jpayne@68: int joLevel=jo.getInt("level"); jpayne@68: if(rootLevel==joLevel){ jpayne@68: assert(levelNode.getString("name").equalsIgnoreCase(jo.getString("levelname"))) : levelNode+"\n"+jo; jpayne@68: addAsChild(levelNode, list, pos); jpayne@68: }else{ jpayne@68: assert(joLevel list, int pos){ jpayne@68: JsonObject children=levelNode.getJson("children"); jpayne@68: if(children==null){ jpayne@68: children=new JsonObject(); jpayne@68: levelNode.add("children", children); jpayne@68: } jpayne@68: JsonObject jo=list.get(pos); jpayne@68: String taxName=jo.getString("name"); jpayne@68: JsonObject nameNode=children.getJson(taxName); jpayne@68: if(nameNode==null){ jpayne@68: nameNode=new JsonObject("name", taxName); jpayne@68: children.add(taxName, nameNode); jpayne@68: } jpayne@68: Number size=jo.getNumber("size"); jpayne@68: Number oldSize=nameNode.getNumber("size"); jpayne@68: if(size!=null && (oldSize==null || oldSize.doubleValue() toD3List(Comparison c){ jpayne@68: final ArrayList nodes=toTNList(c.taxID); jpayne@68: ArrayList list=new ArrayList(nodes.size()); jpayne@68: for(TaxNode tn : nodes){ jpayne@68: JsonObject jo=new JsonObject("name", tn.name); jpayne@68: int levelE=promote(tn.levelExtended); jpayne@68: jo.add("level", levelE); jpayne@68: jo.add("levelname", TaxTree.levelToStringExtended(levelE)); jpayne@68: list.add(jo); jpayne@68: } jpayne@68: if(list.size()>0){ jpayne@68: JsonObject tail=list.get(list.size()-1); jpayne@68: tail.add("size", toD3Size(c)); jpayne@68: tail.add("kid", c.kid()); jpayne@68: tail.add("wkid", c.wkid()); jpayne@68: tail.add("ani", c.ani()); jpayne@68: tail.add("hits", c.hits()); jpayne@68: tail.add("depth", c.depth(printActualDepth)); jpayne@68: } jpayne@68: return list; jpayne@68: } jpayne@68: jpayne@68: private Number toD3Size(Comparison c){ jpayne@68: if(D3sizeMode==D3_ANI_SIZE){ jpayne@68: return c.ani(); jpayne@68: }else if(D3sizeMode==D3_KID_SIZE){ jpayne@68: return c.kid(); jpayne@68: }else if(D3sizeMode==D3_WKID_SIZE){ jpayne@68: return c.wkid(); jpayne@68: }else if(D3sizeMode==D3_HIT_SIZE){ jpayne@68: return c.hits(); jpayne@68: }else if(D3sizeMode==D3_DEPTH_SIZE){ jpayne@68: return c.depth(printActualDepth); jpayne@68: } jpayne@68: assert(false) : "Invalid D3sizeMode "+D3sizeMode; jpayne@68: return c.hits(); jpayne@68: } jpayne@68: jpayne@68: public ArrayList toTNList(final int tid){ jpayne@68: final TaxTree tree=TaxTree.getTree(); jpayne@68: jpayne@68: final ArrayList list=new ArrayList(); jpayne@68: int nulls=0; jpayne@68: { jpayne@68: TaxNode tn=tree.getNode(tid); jpayne@68: if(tn.isRanked() && !tn.cellularOrganisms()){list.add(tn);} jpayne@68: while(tn.pid!=tn.id){ jpayne@68: tn=tree.getNode(tn.pid); jpayne@68: if(tn.isRanked() && !tn.cellularOrganisms()){list.add(tn);} jpayne@68: } jpayne@68: } jpayne@68: Collections.reverse(list); jpayne@68: int prevLevelE=TaxTree.LIFE; jpayne@68: for(int i=0; i0 && levelE>=prevLevelE)){ jpayne@68: list.set(i, null); jpayne@68: nulls++; jpayne@68: }else{prevLevelE=levelE;} jpayne@68: } jpayne@68: if(nulls>0){Tools.condenseStrict(list);} jpayne@68: return list; jpayne@68: } jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Formatting ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: ByteBuilder queryHeader(Sketch sk){ jpayne@68: ByteBuilder bb=new ByteBuilder(); jpayne@68: if(format>2){return bb;} jpayne@68: jpayne@68: String color=toColor(sk.taxID); jpayne@68: if(color!=null){bb.append(color);} jpayne@68: jpayne@68: bb.append("\nQuery: ").append(sk.name()==null ? "." : sk.name()); jpayne@68: if(dbName!=null){bb.append("\tDB: ").append(dbName);} jpayne@68: bb.append("\tSketchLen: ").append(sk.length()); jpayne@68: bb.append("\tSeqs: ").append(sk.genomeSequences).append(' '); jpayne@68: bb.append("\t"+(aminoOrTranslate() ? "SeqLen" : "Bases")+": ").append(sk.genomeSizeBases); jpayne@68: bb.append("\tgSize: ").append(sk.genomeSizeEstimate()); jpayne@68: if(sk.baseCounts!=null){bb.append("\tGC: ").append(sk.gc(), 3);} jpayne@68: if(sk.probCorrect<1 && sk.probCorrect>0){bb.append("\tQuality: ").append(sk.probCorrect, 4);} jpayne@68: if(sk.keyCounts!=null){ jpayne@68: double d=Tools.averageDouble(sk.keyCounts); jpayne@68: bb.append("\tAvgCount: ").append(d, 3); jpayne@68: bb.append("\tDepth: ").append(Tools.observedToActualCoverage(d), 3); jpayne@68: } jpayne@68: jpayne@68: if(sk.imgID>0){bb.append("\tIMG: ").append(sk.imgID);} jpayne@68: if(sk.spid>0){bb.append("\tspid: ").append(sk.spid);} jpayne@68: if(sk.taxID>0 && sk.taxID=SketchObject.minFakeID){return 0;} jpayne@68: TaxNode tn=SketchObject.taxtree.getNode(taxID); jpayne@68: while(tn!=null && tn.id!=tn.pid && tn.levelExtended=TaxTree.LIFE_E || (tn.levelExtended>colorLevel && tn.levelExtended>TaxTree.PHYLUM_E) ? 0 : tn.id; jpayne@68: } jpayne@68: jpayne@68: String toColor(final int taxID){ jpayne@68: if(!printColors || SketchObject.taxtree==null || taxID<=0 || taxID>=SketchObject.minFakeID){return null;} jpayne@68: TaxNode tn=SketchObject.taxtree.getNode(taxID); jpayne@68: while(tn!=null && tn.id!=tn.pid && tn.levelExtended=TaxTree.LIFE_E || (tn.levelExtended>colorLevel && tn.levelExtended>TaxTree.PHYLUM_E)){return Colors.WHITE;} jpayne@68: else{ jpayne@68: // System.err.println("*"+tn.id+", "+tn.id%Colors.colorArray.length); jpayne@68: return Colors.colorArray[tn.id%Colors.colorArray.length]; jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: String header(){ jpayne@68: if(format==FORMAT_JSON){return null;} jpayne@68: final String ani=(aminoOrTranslate() ? "AAI" : "ANI"); jpayne@68: if(format==FORMAT_QUERY_REF_ANI || format==FORMAT_CONSTELLATION){ jpayne@68: if(reportAniOnly){return "#Query\tRef\t"+ani;} jpayne@68: if(format==FORMAT_QUERY_REF_ANI){ jpayne@68: return "#Query\tRef\t"+ani+ jpayne@68: "\tQSize\tRefSize\tQBases\tRBases"+ jpayne@68: (printTaxID ? "\tQTaxID\tRTaxID" : "")+(printKID ? "\tKID" : "")+(printWKID ? "\tWKID" : "")+ jpayne@68: (printSSU() ? "\tSSU" : "")+(printCommonAncestorLevel ? "\tCALevel" : ""); jpayne@68: } jpayne@68: if(format==FORMAT_CONSTELLATION){return "#Query\tRef\tKID\tWKID\t"+ani+"\tCmplt\tQSize\tRefSize\tQBases\tRefBases";} jpayne@68: } jpayne@68: return columnwiseHeader(); jpayne@68: } jpayne@68: jpayne@68: String columnwiseHeader(){ jpayne@68: final String ani=(aminoOrTranslate() ? "AAI" : "ANI"); jpayne@68: jpayne@68: StringBuilder sb=new StringBuilder(); jpayne@68: jpayne@68: //Numeric fields jpayne@68: if(printKID){sb.append("WKID\t");} jpayne@68: if(printWKID){sb.append("KID\t");} jpayne@68: if(printAni){sb.append(ani+"\t");} jpayne@68: if(printSSU()){sb.append("SSU\t");} jpayne@68: if(printSSULen){sb.append("SSULen\t");} jpayne@68: if(printCompleteness){sb.append("Complt\t");} jpayne@68: if(printContam){sb.append("Contam\t");} jpayne@68: if(printContam2){sb.append("Contam2\t");} jpayne@68: if(printUContam){sb.append("uContam\t");} jpayne@68: if(printScore){sb.append("Score\t");} jpayne@68: if(printEValue){sb.append("E-Val\t");} jpayne@68: jpayne@68: if(printDepth){sb.append("Depth\t");} jpayne@68: if(printDepth2){sb.append("Depth2\t");} jpayne@68: if(printVolume){sb.append("Volume\t");} jpayne@68: if(printRefHits){sb.append("RefHits\t");} jpayne@68: if(printMatches){sb.append("Matches\t");} jpayne@68: if(printUnique){sb.append("Unique\t");} jpayne@68: if(printUnique2){sb.append("Unique2\t");} jpayne@68: if(printUnique3){sb.append("Unique3\t");} jpayne@68: if(printNoHit){sb.append("noHit\t");} jpayne@68: if(printLength){sb.append("Length\t");} jpayne@68: if(printTaxID){sb.append("TaxID\t");} jpayne@68: if(printImg){sb.append("ImgID \t");} jpayne@68: if(printGBases){sb.append("gBases\t");} jpayne@68: if(printGKmers){sb.append("gKmers\t");} jpayne@68: if(printGSize){sb.append("gSize\t");} jpayne@68: if(printGSeqs){sb.append("gSeqs\t");} jpayne@68: if(printGC){sb.append("GC\t");} jpayne@68: jpayne@68: jpayne@68: //Raw fields jpayne@68: if(printRefDivisor){sb.append("rDiv\t");} jpayne@68: if(printQueryDivisor){sb.append("qDiv\t");} jpayne@68: if(printRefSize){sb.append("rSize\t");} jpayne@68: if(printQuerySize){sb.append("qSize\t");} jpayne@68: if(printContamHits){sb.append("cHits\t");} jpayne@68: jpayne@68: //Text fields jpayne@68: if(printCommonAncestor){sb.append("CA\t");} jpayne@68: if(printCommonAncestorLevel){sb.append("CALevel\t");} jpayne@68: if(printTaxName){sb.append("taxName\t");} jpayne@68: if(printRefFileName){sb.append("file\t");} jpayne@68: if(printOriginalName){sb.append("seqName\t");} jpayne@68: if(printTax && SketchObject.taxtree!=null){sb.append("taxonomy\t");} jpayne@68: jpayne@68: if(sb.length()>1){sb.setLength(sb.length()-1);}//trim trailing tab jpayne@68: jpayne@68: return sb.toString(); jpayne@68: } jpayne@68: jpayne@68: void formatComparisonColumnwise(Comparison c, ByteBuilder bb, int prevTid){ jpayne@68: final int tid=c.taxID; jpayne@68: boolean reset=false; jpayne@68: jpayne@68: if(printColors){ jpayne@68: final int ctid=toColorTid(tid); jpayne@68: final int prevCtid=toColorTid(prevTid); jpayne@68: jpayne@68: final int cnum=ctid%Colors.colorArray.length; jpayne@68: final int prevCnum=prevCtid%Colors.colorArray.length; jpayne@68: jpayne@68: String color=toColor(tid); jpayne@68: String underline=(printColors && cnum==prevCnum && ctid!=prevCtid && (ctid>1 && prevCtid>1) ? Colors.UNDERLINE : null); jpayne@68: jpayne@68: if(color!=null){bb.append(color);} jpayne@68: if(underline!=null){bb.append(underline);} jpayne@68: reset=(color!=null || underline!=null); jpayne@68: jpayne@68: // System.err.println((color==null ? "" : color)+(underline==null ? "" : underline)+ jpayne@68: // tid+", "+prevTid+"; \t"+ctid+", "+prevCtid+"; \t"+cnum+", "+prevCnum+"; \t"+((underline!=null)+"")+Colors.RESET); jpayne@68: // System.err.println(color==null ? "null" : color.substring(1)); jpayne@68: } jpayne@68: jpayne@68: // sb.append(String.format(Locale.ROOT, "%.2f%%\t%.2f%%", 100*c.idMinDivisor(), 100*c.idMaxDivisor())); jpayne@68: if(printWKID){bb.append(100*c.wkid(), 2).append('%').tab();} jpayne@68: if(printKID){bb.append(100*c.kid(), 2).append('%');} jpayne@68: jpayne@68: // if(printAni){sb.append(String.format(Locale.ROOT, "\t%.2f%%", 100*c.ani()));} jpayne@68: // if(printCompleteness){sb.append(String.format(Locale.ROOT, "\t%.2f%%", 100*c.completeness()));} jpayne@68: // if(printContam){sb.append(String.format(Locale.ROOT, "\t%.2f%%", 100*c.contamFraction()));} jpayne@68: // if(printContam2){sb.append(String.format(Locale.ROOT, "\t%.2f%%", 100*c.contam2Fraction()));} jpayne@68: // if(printUContam){sb.append(String.format(Locale.ROOT, "\t%.2f%%", 100*c.uContamFraction()));} jpayne@68: jpayne@68: if(printAni){bb.tab().append(100*c.ani(), 2).append('%');} jpayne@68: if(printSSU()){ jpayne@68: float id=100*c.ssuIdentity(); jpayne@68: if(id>0){ jpayne@68: bb.tab().append(id, 2).append(c.ssuType()==16 ? '%' : '*'); //This is where 16S and 18S are differentiated jpayne@68: }else{ jpayne@68: bb.tab().append('.'); jpayne@68: } jpayne@68: } jpayne@68: if(printSSULen){ jpayne@68: bb.tab().append(c.ssuLen()); jpayne@68: } jpayne@68: if(printCompleteness){bb.tab().append(100*c.completeness(), 2).append('%');} jpayne@68: if(printContam){bb.tab().append(100*c.contamFraction(), 2).append('%');} jpayne@68: if(printContam2){bb.tab().append(100*c.contam2Fraction(), 2).append('%');} jpayne@68: if(printUContam){bb.tab().append(100*c.uContamFraction(), 2).append('%');} jpayne@68: if(printScore){bb.tab().append(c.scoreS());} jpayne@68: if(printEValue){bb.tab().append(String.format(Locale.ROOT, "%5.2e", c.eValue()));} jpayne@68: jpayne@68: if(printDepth){bb.tab().append(c.depthS(printActualDepth));} jpayne@68: if(printDepth2){bb.tab().append(c.depth2S(printActualDepth));} jpayne@68: if(printVolume){bb.tab().append(c.volumeS());} jpayne@68: if(printRefHits){bb.tab().append(c.avgRefHitsS());} jpayne@68: jpayne@68: if(printMatches){bb.tab().append(c.hits());} jpayne@68: if(printUnique){bb.tab().append(c.uHits());} jpayne@68: if(printUnique2){bb.tab().append(c.unique2());} jpayne@68: if(printUnique3){bb.tab().append(c.unique3());} jpayne@68: if(printNoHit){bb.tab().append(c.noHits());} jpayne@68: if(printLength){bb.tab().append( c.maxDivisor());} jpayne@68: if(printTaxID){bb.tab().append(tid>=SketchObject.minFakeID ? -1 : tid);} jpayne@68: if(printImg){bb.tab().append(c.imgID());} jpayne@68: if(printGBases){appendKMG(c.genomeSizeBases(), bb);} jpayne@68: if(printGKmers){appendKMG(c.genomeSizeKmers(), bb);} jpayne@68: if(printGSize){appendKMG(c.genomeSizeEstimate(), bb);} jpayne@68: if(printGSeqs){appendKMG(c.genomeSequences(), bb);} jpayne@68: if(printGC){bb.tab().append(c.gc(),3);} jpayne@68: jpayne@68: //Raw fields jpayne@68: if(printRefDivisor){bb.tab().append(c.refDivisor());} jpayne@68: if(printQueryDivisor){bb.tab().append(c.queryDivisor());} jpayne@68: if(printRefSize){bb.tab().append(c.refSize());} jpayne@68: if(printQuerySize){bb.tab().append(c.querySize());} jpayne@68: if(printContamHits){bb.tab().append(c.contamHits());} jpayne@68: jpayne@68: //Text fields jpayne@68: if(printCommonAncestor){bb.tab().append(c.commonAncestor());} jpayne@68: if(printCommonAncestorLevel){bb.tab().append(c.commonAncestorLevel());} jpayne@68: if(printTaxName){bb.tab().append(c.taxName()==null ? "." : c.taxName());} jpayne@68: if(printRefFileName){bb.tab().append(c.fname()==null ? "." : c.fname());} jpayne@68: if(printOriginalName){bb.tab().append(c.name0()==null ? "." : c.name0());} jpayne@68: if(printTax && SketchObject.taxtree!=null){ jpayne@68: bb.tab(); jpayne@68: TaxNode tn=null; jpayne@68: if(tid>0 && tid1 && prevCtid>1) ? Colors.UNDERLINE : null); jpayne@68: jpayne@68: if(color!=null){sb.append(color);} jpayne@68: if(underline!=null){sb.append(underline);} jpayne@68: reset=(color!=null || underline!=null); jpayne@68: jpayne@68: // System.err.println((color==null ? "" : color)+(underline==null ? "" : underline)+ jpayne@68: // tid+", "+prevTid+"; \t"+ctid+", "+prevCtid+"; \t"+cnum+", "+prevCnum+"; \t"+((underline!=null)+"")+Colors.RESET); jpayne@68: // System.err.println(color==null ? "null" : color.substring(1)); jpayne@68: } jpayne@68: jpayne@68: // sb.append(rName).append(String.format(Locale.ROOT, "\t%.2f\t%.3f", 100*c.ani(), sea/(float)seb)); jpayne@68: // sb.append(rName).append(String.format(Locale.ROOT, "\t%.2f\t%d\t%d\t%d", 100*c.ani(), sea, seb, ba)); jpayne@68: jpayne@68: //"#Query\tRef\tKID\tWKID\tANI\tCmplt\tQSize\tRefSize\tQBases\tRefBases"; jpayne@68: jpayne@68: float kid=100*c.kid(); jpayne@68: float wkid=100*c.wkid(); jpayne@68: float ani=100*c.ani(); jpayne@68: float complt=100*c.completeness(); jpayne@68: float ssu=printSSU() ? 100*c.ssuIdentity() : 0; jpayne@68: jpayne@68: sb.append(rName).append('\t'); jpayne@68: if(reportAniOnly){ jpayne@68: sb.append(ani, 3).append('\t'); jpayne@68: }else if(format==FORMAT_CONSTELLATION){ jpayne@68: sb.append(kid, 3).append('\t'); jpayne@68: sb.append(wkid, 3).append('\t'); jpayne@68: sb.append(ani, 3).append('\t'); jpayne@68: sb.append(complt, 3).append('\t'); jpayne@68: sb.append(sea).append('\t'); jpayne@68: sb.append(seb).append('\t'); jpayne@68: // sb.append(ba).append('\t'); jpayne@68: // sb.append(bb).append('\t'); jpayne@68: }else{ jpayne@68: sb.append(ani, 3).append('\t'); jpayne@68: sb.append(sea).append('\t'); jpayne@68: sb.append(seb).append('\t'); jpayne@68: sb.append(ba).append('\t'); jpayne@68: sb.append(bb).append('\t'); jpayne@68: if(printTaxID){sb.append(c.a.taxID).append('\t');} jpayne@68: if(printTaxID){sb.append(c.b.taxID).append('\t');} jpayne@68: if(printKID){sb.append(kid, 3).append('\t');} jpayne@68: if(printWKID){sb.append(wkid, 3).append('\t');} jpayne@68: if(printSSU()){ jpayne@68: if(ssu>0){ jpayne@68: sb.append(ssu, 3).append('\t'); jpayne@68: }else{ jpayne@68: sb.append('.').append('\t'); jpayne@68: } jpayne@68: } jpayne@68: if(printCommonAncestorLevel){sb.append(c.commonAncestorLevel()).append('\t');} jpayne@68: } jpayne@68: sb.setLength(sb.length()-1); jpayne@68: if(reset){sb.append(Colors.RESET);} jpayne@68: jpayne@68: sb.append('\n'); jpayne@68: jpayne@68: // System.err.println(sb); jpayne@68: } jpayne@68: jpayne@68: void formatComparison(Comparison c, ByteBuilder sb, int prevTaxID){ jpayne@68: if(format==FORMAT_MULTICOLUMN){ jpayne@68: formatComparisonColumnwise(c, sb, prevTaxID); jpayne@68: return; jpayne@68: }else if(format==FORMAT_QUERY_REF_ANI || format==FORMAT_CONSTELLATION){ jpayne@68: formatComparison3Column(c, sb, prevTaxID); jpayne@68: return; jpayne@68: } jpayne@68: String complt=(printCompleteness ? String.format(Locale.ROOT, "\tcomplt %.2f%%%%", 100*c.completeness()) : ""); jpayne@68: String contam=(printContam ? String.format(Locale.ROOT, "\tcontam %.2f%%%%", 100*c.contamFraction()) : ""); jpayne@68: // String score=(printScore ? String.format(Locale.ROOT, "\tscore %.2f", c.score2()) : ""); jpayne@68: String score=(printScore ? "\tscore "+c.scoreS() : ""); jpayne@68: String depth=(printDepth ? "\tdepth "+c.depthS(printActualDepth) : ""); jpayne@68: String depth2=(printDepth2 ? "\tdepth2 "+c.depth2S(printActualDepth) : ""); jpayne@68: String volume=(printVolume ? "\tvolume "+c.volumeS() : ""); jpayne@68: String ccs=complt+contam+score; jpayne@68: jpayne@68: if(format==FORMAT_OLD){ jpayne@68: sb.append(String.format(Locale.ROOT, "WKID %.2f%%\tKID %.2f%%"+ccs+"\tmatches %d\tcompared %d", jpayne@68: 100*c.wkid(), 100*c.kid(), c.hits(), c.minDivisor())+"\ttaxID "+c.taxID()+ jpayne@68: (printImg ? "\timgID "+c.imgID() : "")+"\tgKmers "+c.genomeSizeKmers()+"\t"+ jpayne@68: (c.taxName()==null ? "." : c.taxName())+ jpayne@68: ((printOriginalName || (c.taxName()==null && c.name0()!=null)) ? "\t"+(c.name0()==null ? "." : c.name0()) : "")+"\n"); jpayne@68: if(printTax && SketchObject.taxtree!=null){ jpayne@68: if(c.taxID()>=0 && c.taxID() tnl=new ArrayList(); jpayne@68: if(SketchObject.taxtree!=null && c.taxID()>=0 && c.taxID()=0; i--){ jpayne@68: TaxNode tn=tnl.get(i); jpayne@68: sb.append(tn.name); jpayne@68: if(i>0){sb.append(';');} jpayne@68: } jpayne@68: } jpayne@68: sb.append('\n'); jpayne@68: jpayne@68: tnl.clear(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Filtering ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: public boolean passesFilter(Sketch sk){ jpayne@68: assert(postParsed); jpayne@68: if(noFilters){return true;} jpayne@68: return passesSSUFilter(sk) && passesSizeFilter(sk) && passesTaxFilter(sk) && passesMetaFilter(sk); jpayne@68: } jpayne@68: jpayne@68: private boolean passesTaxFilter(Sketch sk){ jpayne@68: if(taxFilterWhite==null && taxFilterBlack==null){return true;} jpayne@68: int id=sk.taxID; jpayne@68: if(id>0){ jpayne@68: if(banUnclassified && SketchObject.taxtree.isUnclassified(id)){return false;} jpayne@68: if(banVirus && SketchObject.taxtree.isVirus(id)){return false;} jpayne@68: } jpayne@68: String s=sk.name(); jpayne@68: return passesTaxFilter(taxFilterWhite, id, s) && passesTaxFilter(taxFilterBlack, id, s); jpayne@68: } jpayne@68: jpayne@68: private boolean passesTaxFilter(TaxFilter filter, int id, String s){ jpayne@68: if(filter==null){return true;} jpayne@68: if(id>0 && !filter.passesFilter(id)){return false;} jpayne@68: // if(id>0 && !filter.passesFilterFast(id)){return false;} jpayne@68: if(s!=null && !filter.passesFilterByNameOnly(s)){return false;} jpayne@68: return true; jpayne@68: } jpayne@68: jpayne@68: private boolean passesMetaFilter(Sketch sk){ jpayne@68: if(requiredMeta==null && bannedMeta==null){return true;} jpayne@68: return sk.passesMeta(requiredMeta, bannedMeta, requiredMetaAnd); jpayne@68: } jpayne@68: jpayne@68: private boolean passesSSUFilter(Sketch sk){ jpayne@68: return !requireSSU || sk.hasSSU(); jpayne@68: } jpayne@68: jpayne@68: private boolean passesSizeFilter(Sketch sk){ jpayne@68: if(minRefSizeEstimate>0 && sk.genomeSizeEstimate()=minRefSizeBases; jpayne@68: } jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Fields ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: //These are shared with SketchObject jpayne@68: //They do not affect anything and are just for the server to validate remote settings. jpayne@68: private int hashVersion=SketchObject.HASH_VERSION; jpayne@68: private int k=SketchObject.k; jpayne@68: private int k2=SketchObject.k2; jpayne@68: boolean amino=SketchObject.amino; jpayne@68: boolean translate=SketchObject.translate; jpayne@68: boolean sixframes=SketchObject.sixframes; jpayne@68: private boolean aminoOrTranslate(){return amino | translate;} jpayne@68: jpayne@68: boolean noFilters=false; jpayne@68: boolean postParsed=false; jpayne@68: jpayne@68: boolean amino(){return amino;} jpayne@68: jpayne@68: //These are unique jpayne@68: public int maxRecords=default_maxRecords; jpayne@68: public int recordsPerLevel=0; jpayne@68: public float minANI=0; jpayne@68: public int minBases=0; jpayne@68: public float minSizeRatio=0; jpayne@68: public float minWKID=default_minWKID; jpayne@68: public int format=default_format; jpayne@68: jpayne@68: /** For tracking unique SendSketch queries */ jpayne@68: public int chunkNum=-1; jpayne@68: public int minHits=default_minHits; jpayne@68: public int taxLevel=default_taxLevel; jpayne@68: public int mode=default_mode; jpayne@68: public float samplerate=default_samplerate; jpayne@68: public long maxReads=default_maxReads; jpayne@68: public int minKeyOccuranceCount=default_minKeyOccuranceCount; jpayne@68: public String inputVersion=null; jpayne@68: jpayne@68: public String dbName=null; jpayne@68: jpayne@68: boolean hasMetaFilters(){return requiredMeta!=null || bannedMeta!=null/* || requiredTaxid!=null || bannedTaxid!=null*/;} jpayne@68: boolean hasTaxFilters(){return taxFilterWhite!=null || taxFilterBlack!=null || banUnclassified || banVirus;} jpayne@68: boolean requireSSU=false; jpayne@68: long minRefSizeEstimate=-1; jpayne@68: long minRefSizeBases=-1; jpayne@68: jpayne@68: boolean requiredMetaAnd=true; jpayne@68: ArrayList requiredMeta=null; jpayne@68: ArrayList bannedMeta=null; jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Print Columns ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: public boolean printKID=true; jpayne@68: public boolean printWKID=true; jpayne@68: public boolean printSSU=true; jpayne@68: public boolean printSSULen=false; jpayne@68: public boolean printSSU(){return SketchObject.processSSU && printSSU;} jpayne@68: public boolean printSSUSequence=default_printSSUSequence; jpayne@68: jpayne@68: //For format 2 jpayne@68: public boolean printTax=default_printTax; jpayne@68: public boolean printOriginalName=default_printOriginalName; jpayne@68: public boolean printQueryFileName=default_printQueryFileName; jpayne@68: public boolean printRefFileName=default_printRefFileName; jpayne@68: public boolean printImg=default_printImg; jpayne@68: public boolean printAni=default_printAni; jpayne@68: public boolean printCompleteness=default_printCompleteness; jpayne@68: public boolean printScore=default_printScore; jpayne@68: public boolean printEValue=default_printEValue; jpayne@68: jpayne@68: private boolean trackCounts=default_trackCounts; jpayne@68: public boolean printDepth=default_printDepth; jpayne@68: public boolean printDepth2=default_printDepth2; jpayne@68: public boolean printActualDepth=default_printActualDepth; jpayne@68: public boolean printVolume=default_printVolume; jpayne@68: public boolean printRefHits=default_printRefHits; jpayne@68: jpayne@68: public boolean printLength=default_printLength; jpayne@68: public boolean printTaxID=default_printTaxID; jpayne@68: public boolean printGSize=default_printGSize; jpayne@68: public boolean printGC=default_printGC; jpayne@68: public boolean gSizeKMG=default_gSizeKMG; jpayne@68: public boolean printGKmers=default_printGKmers; jpayne@68: public boolean printCommonAncestor=default_printCommonAncestor; jpayne@68: public boolean printCommonAncestorLevel=default_printCommonAncestorLevel; jpayne@68: public boolean printTaxName=default_printTaxName; jpayne@68: public boolean printGSeqs=default_printGSeqs; jpayne@68: public boolean printGBases=default_printGBases; jpayne@68: jpayne@68: public boolean jsonArray=default_jsonArray; jpayne@68: public boolean printD3=default_printD3; jpayne@68: public boolean D3LevelNodes=false; jpayne@68: public int D3sizeMode=D3_HIT_SIZE; jpayne@68: public static final int D3_HIT_SIZE=0, D3_ANI_SIZE=1, D3_KID_SIZE=2, D3_WKID_SIZE=3, D3_DEPTH_SIZE=4; jpayne@68: jpayne@68: public float minEntropy=default_minEntropy; jpayne@68: jpayne@68: //For k=32: jpayne@68: //0.000095f is >=Q6 (75%); 0.0008 is >=Q7 (80%); 0.0039 is >=Q8 (84%). jpayne@68: //0.002f is >=Q7.53 (82.3%) jpayne@68: //0.0017f is >=Q7.44 (82.0%) jpayne@68: //0.6f works better for Illumina reads but this is more robust for PacBio. jpayne@68: public float minProb=0.0008f; jpayne@68: public byte minQual=0; jpayne@68: jpayne@68: public boolean printUnique=default_printUnique; jpayne@68: public boolean printUnique2=default_printUnique2; jpayne@68: public boolean printUnique3=default_printUnique3; jpayne@68: public boolean printUContam=default_printUContam; jpayne@68: public boolean printNoHit=default_printNoHit; jpayne@68: jpayne@68: public boolean printColors=default_printColors; jpayne@68: public boolean setColors=false; jpayne@68: public int colorLevel=default_colorLevel; jpayne@68: jpayne@68: /** TODO: Note this is conflated between printing %contam and calculating things based on contam hits. */ jpayne@68: public boolean printContam=default_printContam; jpayne@68: public boolean printContam2=default_printContam2; jpayne@68: private int contamLevel=default_contamLevel; jpayne@68: jpayne@68: /** Raw fields */ jpayne@68: public boolean printMatches=default_printMatches; jpayne@68: jpayne@68: public boolean printRefDivisor=false; jpayne@68: public boolean printQueryDivisor=false; jpayne@68: public boolean printRefSize=false; jpayne@68: public boolean printQuerySize=false; jpayne@68: public boolean printContamHits=false; jpayne@68: jpayne@68: public boolean mergePairs=false; jpayne@68: public boolean printIntersection=false; jpayne@68: jpayne@68: //For format 3 or 5 jpayne@68: public boolean useTaxidName=false; jpayne@68: public boolean useImgName=false; jpayne@68: public boolean useTaxName=false; jpayne@68: public boolean useFilePrefixName=false; jpayne@68: public boolean reportAniOnly=false; jpayne@68: jpayne@68: public int taxLevelWhite=0; jpayne@68: public int taxLevelBlack=0; jpayne@68: jpayne@68: public String taxFilterWhiteList=null; jpayne@68: public String taxFilterBlackList=null; jpayne@68: jpayne@68: public String taxFilterWhiteString=null; jpayne@68: public String taxFilterBlackString=null; jpayne@68: jpayne@68: public TaxFilter taxFilterWhite=null; jpayne@68: public TaxFilter taxFilterBlack=null; jpayne@68: jpayne@68: public boolean banUnclassified=false; jpayne@68: public boolean banVirus=false; jpayne@68: jpayne@68: /** Make sure the settings are consistent, for CompareSketch. jpayne@68: * This is not yet complete. */ jpayne@68: public boolean checkValid(){ jpayne@68: if(printUnique2 || printUnique3){ jpayne@68: assert(contamLevel()>=TaxTree.SUBSPECIES_E); jpayne@68: assert(needContamCounts()); jpayne@68: assert(SketchObject.makeIndex); jpayne@68: assert(SketchObject.taxtree!=null); jpayne@68: } jpayne@68: if(printContam2){ jpayne@68: assert(contamLevel()>=TaxTree.SUBSPECIES_E); jpayne@68: assert(needContamCounts()); jpayne@68: assert(SketchObject.makeIndex); jpayne@68: assert(SketchObject.taxtree!=null); jpayne@68: } jpayne@68: return true; jpayne@68: } jpayne@68: jpayne@68: public boolean trackCounts() { jpayne@68: return trackCounts || printDepth || printDepth2 || printVolume jpayne@68: || comparator!=Comparison.scoreComparator || printD3; //|| minKeyOccuranceCount>1; jpayne@68: } jpayne@68: jpayne@68: public boolean needContamCounts() { jpayne@68: return printContam || printContam2 || printContamHits || printUnique || printUnique2 || printUnique3 || printUContam || printNoHit; // || true jpayne@68: } jpayne@68: jpayne@68: public boolean needIndex(){ jpayne@68: return printContam2 || printUnique2 || printUnique3; jpayne@68: } jpayne@68: jpayne@68: public int contamLevel() { jpayne@68: return needIndex() ? contamLevel : -1; jpayne@68: } jpayne@68: jpayne@68: public int compare(Comparison a, Comparison b){ jpayne@68: return comparator.compare(a, b); jpayne@68: } jpayne@68: jpayne@68: public Comparator comparator=Comparison.scoreComparator; jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Constants ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: public static final int FORMAT_OLD=0, FORMAT_MULTICOLUMN=2, FORMAT_QUERY_REF_ANI=3, FORMAT_JSON=4, FORMAT_CONSTELLATION=5; jpayne@68: public static final boolean default_printD3=false; jpayne@68: public static final boolean default_jsonArray=false; jpayne@68: jpayne@68: public static final int default_maxRecords=20; jpayne@68: public static final float default_minWKID=0.0001f; jpayne@68: public static final int default_format=FORMAT_MULTICOLUMN; jpayne@68: public static final boolean default_printSSUSequence=false; jpayne@68: public static final boolean default_printTax=false; jpayne@68: public static final boolean default_printOriginalName=false; jpayne@68: public static final boolean default_printQueryFileName=true; jpayne@68: public static final boolean default_printRefFileName=false; jpayne@68: public static final boolean default_printImg=false; jpayne@68: public static final boolean default_printAni=true; jpayne@68: public static final boolean default_printCompleteness=true; jpayne@68: public static final boolean default_printScore=false; jpayne@68: public static final boolean default_printEValue=false; jpayne@68: jpayne@68: public static final boolean default_trackCounts=false; jpayne@68: public static final boolean default_printDepth=false; jpayne@68: public static final boolean default_printDepth2=false; jpayne@68: public static final boolean default_printActualDepth=true; jpayne@68: public static final boolean default_printVolume=false; jpayne@68: public static final boolean default_printRefHits=false; jpayne@68: jpayne@68: public static final boolean default_printContam=true; jpayne@68: public static final boolean default_printContam2=false; jpayne@68: jpayne@68: public static final boolean default_printMatches=true; jpayne@68: public static final boolean default_printLength=false; jpayne@68: public static final boolean default_printTaxID=true; jpayne@68: public static final boolean default_printGSize=true; jpayne@68: public static final boolean default_printGC=false; jpayne@68: public static final boolean default_gSizeKMG=true; jpayne@68: public static final boolean default_printGKmers=false; jpayne@68: public static final boolean default_printCommonAncestor=false; jpayne@68: public static final boolean default_printCommonAncestorLevel=false; jpayne@68: public static final boolean default_printTaxName=true; jpayne@68: public static final boolean default_printGSeqs=true; jpayne@68: public static final boolean default_printGBases=false; jpayne@68: jpayne@68: public static final float default_minEntropy=0.66f; jpayne@68: public static final float default_minEntropy_amino=0.70f; jpayne@68: public static final float default_minProb=0.0008f; jpayne@68: public static final byte default_minQual=0; jpayne@68: jpayne@68: public static final boolean default_printUnique=true; jpayne@68: public static final boolean default_printUnique2=false; jpayne@68: public static final boolean default_printUnique3=false; jpayne@68: public static final boolean default_printUContam=false; jpayne@68: public static final boolean default_printNoHit=false; jpayne@68: jpayne@68: public static final boolean default_printColors=true; jpayne@68: public static final int default_colorLevel=TaxTree.FAMILY_E; jpayne@68: jpayne@68: public static final int default_taxLevel=TaxTree.SPECIES; jpayne@68: public static final int default_contamLevel=TaxTree.GENUS_E; jpayne@68: jpayne@68: public static final int default_mode=SketchObject.ONE_SKETCH; jpayne@68: jpayne@68: public static final int default_minHits=3; jpayne@68: public static final float default_samplerate=1; jpayne@68: public static final long default_maxReads=-1; jpayne@68: public static final int default_minKeyOccuranceCount=1; jpayne@68: jpayne@68: }