| 1 |
package sketch; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
import java.util.Collections; |
| 5 |
import java.util.Comparator; |
| 6 |
import java.util.Map.Entry; |
| 7 |
|
| 8 |
import json.JsonObject; |
| 9 |
import shared.Colors; |
| 10 |
import shared.Parse; |
| 11 |
import shared.Tools; |
| 12 |
import structures.ByteBuilder; |
| 13 |
import tax.PrintTaxonomy; |
| 14 |
import tax.TaxFilter; |
| 15 |
import tax.TaxNode; |
| 16 |
import tax.TaxTree; |
| 17 |
|
| 18 |
public class DisplayParams implements Cloneable { |
| 19 |
|
| 20 |
@Override |
| 21 |
public DisplayParams clone(){ |
| 22 |
try { |
| 23 |
DisplayParams copy=(DisplayParams)super.clone(); |
| 24 |
if(taxFilterWhite!=null){ |
| 25 |
copy.taxFilterWhite=taxFilterWhite.deepCopy(); |
| 26 |
} |
| 27 |
if(taxFilterBlack!=null){ |
| 28 |
copy.taxFilterBlack=taxFilterBlack.deepCopy(); |
| 29 |
} |
| 30 |
copy.postParsed=false; |
| 31 |
return copy; |
| 32 |
} catch (CloneNotSupportedException e) { |
| 33 |
|
| 34 |
e.printStackTrace(); |
| 35 |
throw new RuntimeException(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
public DisplayParams parseDoubleHeader(String s){ |
| 40 |
if(!s.startsWith("##")){return this;} |
| 41 |
|
| 42 |
StringBuilder sb=new StringBuilder(); |
| 43 |
for(int i=2; i<s.length(); i++){ |
| 44 |
char c=s.charAt(i); |
| 45 |
if(c=='\n'){break;} |
| 46 |
sb.append(c); |
| 47 |
} |
| 48 |
return parseDoubleHeaderLine(sb.toString()); |
| 49 |
} |
| 50 |
|
| 51 |
public DisplayParams parseDoubleHeaderLine(String line) { |
| 52 |
if(line.startsWith("##")){line=line.substring(2);} |
| 53 |
else{assert(!line.startsWith("#")) : line;} |
| 54 |
if(line.length()<1){return this;} |
| 55 |
|
| 56 |
DisplayParams params=this.clone(); |
| 57 |
|
| 58 |
String[] args=line.split(" "); |
| 59 |
for(String arg : args){ |
| 60 |
String[] split=arg.split("="); |
| 61 |
String a=split[0].toLowerCase(); |
| 62 |
String b=split.length>1 ? split[1] : null; |
| 63 |
if(b==null || b.equalsIgnoreCase("null")){b=null;} |
| 64 |
while(a.startsWith("-")){a=a.substring(1);} |
| 65 |
|
| 66 |
boolean x=params.parse(arg, a, b); |
| 67 |
|
| 68 |
if(!x){System.err.println("Warning: Unknown parameter "+arg);} |
| 69 |
} |
| 70 |
if(SketchObject.verbose2){System.err.println("Made it to post-parse. taxFilterWhite="+params.taxFilterWhite);} |
| 71 |
params.postParse(true, true); |
| 72 |
if(SketchObject.verbose2){System.err.println("Passed post-parse. taxFilterWhite="+params.taxFilterWhite);} |
| 73 |
|
| 74 |
return params; |
| 75 |
} |
| 76 |
|
| 77 |
public boolean parse(String arg, String a, String b){ |
| 78 |
|
| 79 |
if(a.equals("chunk")){ |
| 80 |
chunkNum=Integer.parseInt(b); |
| 81 |
}else if(a.equals("minhits") || a.equals("hits")){ |
| 82 |
minHits=Integer.parseInt(b); |
| 83 |
}else if(a.equalsIgnoreCase("minwkid") || a.equalsIgnoreCase("wkid")){ |
| 84 |
minWKID=Float.parseFloat(b); |
| 85 |
if(minWKID>1){minWKID/=100;} |
| 86 |
assert(minWKID<=1) : "minWKID should between 0 and 1"; |
| 87 |
}else if(a.equalsIgnoreCase("minid") || a.equalsIgnoreCase("id") || a.equalsIgnoreCase("minani") || a.equalsIgnoreCase("ani")){ |
| 88 |
minANI=Float.parseFloat(b); |
| 89 |
if(minANI>1){minANI/=100;} |
| 90 |
assert(minANI<=1) : "minANI should between 0 and 1"; |
| 91 |
if(minANI>0){ |
| 92 |
minWKID=(float)Tools.max(minWKID, Comparison.aniToWkid(minANI, 32)); |
| 93 |
} |
| 94 |
}else if(a.equals("minbases")){ |
| 95 |
minBases=Integer.parseInt(b); |
| 96 |
}else if(a.equals("minsizeratio")){ |
| 97 |
minSizeRatio=Float.parseFloat(b); |
| 98 |
|
| 99 |
if(minSizeRatio>1){minSizeRatio=1f/minSizeRatio;} |
| 100 |
}else if(a.equals("records") || a.equals("maxrecords") || a.equals("results")){ |
| 101 |
maxRecords=Integer.parseInt(b); |
| 102 |
assert(maxRecords>=1) : "Max records must be at least 1."; |
| 103 |
}else if(a.equals("recordsperlevel")){ |
| 104 |
recordsPerLevel=Integer.parseInt(b); |
| 105 |
}else if(a.equals("format")){ |
| 106 |
assert(b!=null) : "Invalid format: "+arg; |
| 107 |
if(b.equalsIgnoreCase("json")){ |
| 108 |
format=FORMAT_JSON; |
| 109 |
}else if(b.equalsIgnoreCase("jsonarray")){ |
| 110 |
format=FORMAT_JSON; |
| 111 |
jsonArray=true; |
| 112 |
}else if(b.equalsIgnoreCase("d3")){ |
| 113 |
format=FORMAT_JSON; |
| 114 |
printD3=true; |
| 115 |
}else if(b.equalsIgnoreCase("constellation")){ |
| 116 |
format=FORMAT_CONSTELLATION; |
| 117 |
}else if(b.equalsIgnoreCase("3column") || b.equalsIgnoreCase("queryrefani")){ |
| 118 |
format=FORMAT_QUERY_REF_ANI; |
| 119 |
}else if(Tools.isDigit(b.charAt(0))){ |
| 120 |
format=Integer.parseInt(b); |
| 121 |
}else{ |
| 122 |
assert(false) : "Invalid format: "+arg; |
| 123 |
} |
| 124 |
}else if(a.equalsIgnoreCase("json")){ |
| 125 |
if(Parse.parseBoolean(b)){ |
| 126 |
format=FORMAT_JSON; |
| 127 |
}else{ |
| 128 |
if(format==FORMAT_JSON){format=default_format;} |
| 129 |
} |
| 130 |
}else if(a.equalsIgnoreCase("jsonarray") || a.equalsIgnoreCase("jsonarrays")){ |
| 131 |
if(Parse.parseBoolean(b)){ |
| 132 |
format=FORMAT_JSON; |
| 133 |
jsonArray=true; |
| 134 |
}else{ |
| 135 |
jsonArray=false; |
| 136 |
} |
| 137 |
}else if(a.equalsIgnoreCase("d3") || a.equalsIgnoreCase("printd3")){ |
| 138 |
if(Parse.parseBoolean(b)){ |
| 139 |
format=FORMAT_JSON; |
| 140 |
printD3=true; |
| 141 |
}else{ |
| 142 |
printD3=false; |
| 143 |
} |
| 144 |
}else if(a.equalsIgnoreCase("jsonarray") || a.equalsIgnoreCase("jsonarrays")){ |
| 145 |
if(Parse.parseBoolean(b)){ |
| 146 |
jsonArray=true; |
| 147 |
}else{ |
| 148 |
jsonArray=false; |
| 149 |
} |
| 150 |
}else if(a.equalsIgnoreCase("d3levelnodes")){ |
| 151 |
D3LevelNodes=Parse.parseBoolean(b); |
| 152 |
}else if(a.equalsIgnoreCase("d3hitsize")){ |
| 153 |
if(Parse.parseBoolean(b)){D3sizeMode=D3_HIT_SIZE;} |
| 154 |
}else if(a.equalsIgnoreCase("d3anisize")){ |
| 155 |
if(Parse.parseBoolean(b)){D3sizeMode=D3_ANI_SIZE;} |
| 156 |
}else if(a.equalsIgnoreCase("d3wkidsize")){ |
| 157 |
if(Parse.parseBoolean(b)){D3sizeMode=D3_WKID_SIZE;} |
| 158 |
}else if(a.equalsIgnoreCase("d3depthsize")){ |
| 159 |
if(Parse.parseBoolean(b)){ |
| 160 |
D3sizeMode=D3_DEPTH_SIZE; |
| 161 |
printDepth=true; |
| 162 |
} |
| 163 |
}else if(a.equalsIgnoreCase("d3kidsize")){ |
| 164 |
if(Parse.parseBoolean(b)){D3sizeMode=D3_KID_SIZE;} |
| 165 |
}else if(a.equalsIgnoreCase("D3sizeMode")){ |
| 166 |
D3sizeMode=Integer.parseInt(b); |
| 167 |
}else if(a.equals("level") || a.equals("lv") || a.equals("taxlevel") || a.equals("tl") || a.equals("minlevel")){ |
| 168 |
taxLevel=TaxTree.parseLevel(b); |
| 169 |
} |
| 170 |
|
| 171 |
else if(a.equalsIgnoreCase("requireSSU")){ |
| 172 |
requireSSU=Parse.parseBoolean(b); |
| 173 |
} |
| 174 |
|
| 175 |
else if(a.equalsIgnoreCase("minRefSizeEstimate") || a.equalsIgnoreCase("minRefSize")){ |
| 176 |
minRefSizeEstimate=Long.parseLong(b); |
| 177 |
}else if(a.equalsIgnoreCase("minRefSizeBases")){ |
| 178 |
minRefSizeBases=Long.parseLong(b); |
| 179 |
} |
| 180 |
|
| 181 |
else if(a.equalsIgnoreCase("printtax") || a.equalsIgnoreCase("printtaxa")){ |
| 182 |
printTax=Parse.parseBoolean(b); |
| 183 |
}else if(a.equalsIgnoreCase("printssu") || a.equalsIgnoreCase("print16s") || a.equalsIgnoreCase("ssu")){ |
| 184 |
printSSU=Parse.parseBoolean(b); |
| 185 |
}else if(a.equalsIgnoreCase("printSSULen") || a.equalsIgnoreCase("print16slen") || a.equalsIgnoreCase("ssulen")){ |
| 186 |
printSSULen=Parse.parseBoolean(b); |
| 187 |
}else if(a.equalsIgnoreCase("printssusequence") || a.equalsIgnoreCase("print16ssequence")){ |
| 188 |
printSSUSequence=Parse.parseBoolean(b); |
| 189 |
}else if(a.equalsIgnoreCase("printqueryfilename") || a.equalsIgnoreCase("printqfname") || a.equalsIgnoreCase("printqfile") || a.equalsIgnoreCase("qfname")){ |
| 190 |
printQueryFileName=Parse.parseBoolean(b); |
| 191 |
}else if(a.equalsIgnoreCase("printreffilename") || a.equalsIgnoreCase("printrfname") || a.equalsIgnoreCase("printrfile") || a.equalsIgnoreCase("rfname")){ |
| 192 |
printRefFileName=Parse.parseBoolean(b); |
| 193 |
}else if(a.equalsIgnoreCase("printfilename") || a.equalsIgnoreCase("printfname") || a.equalsIgnoreCase("printfile")){ |
| 194 |
printQueryFileName=printRefFileName=Parse.parseBoolean(b); |
| 195 |
}else if(a.equalsIgnoreCase("printoriginalname") || a.equalsIgnoreCase("printseqname") || a.equalsIgnoreCase("printname0") || a.equals("pn0")){ |
| 196 |
printOriginalName=Parse.parseBoolean(b); |
| 197 |
}else if(a.equalsIgnoreCase("printimg")){ |
| 198 |
printImg=Parse.parseBoolean(b); |
| 199 |
}else if(a.equalsIgnoreCase("printcompleteness") || a.equalsIgnoreCase("completeness") || a.equalsIgnoreCase("printcomplt")){ |
| 200 |
printCompleteness=Parse.parseBoolean(b); |
| 201 |
}else if(a.equalsIgnoreCase("printani") || a.equalsIgnoreCase("ani")){ |
| 202 |
printAni=Parse.parseBoolean(b); |
| 203 |
}else if(a.equalsIgnoreCase("printkid") || a.equalsIgnoreCase("kid")){ |
| 204 |
printKID=Parse.parseBoolean(b); |
| 205 |
}else if(a.equalsIgnoreCase("printwkid") || a.equalsIgnoreCase("wkid")){ |
| 206 |
printWKID=Parse.parseBoolean(b); |
| 207 |
}else if(a.equalsIgnoreCase("printscore") || a.equalsIgnoreCase("score")){ |
| 208 |
printScore=Parse.parseBoolean(b); |
| 209 |
}else if(a.equalsIgnoreCase("printevalue") || a.equalsIgnoreCase("evalue")){ |
| 210 |
printEValue=Parse.parseBoolean(b); |
| 211 |
} |
| 212 |
|
| 213 |
else if(a.equalsIgnoreCase("trackcounts")){ |
| 214 |
trackCounts=Parse.parseBoolean(b); |
| 215 |
}else if(a.equalsIgnoreCase("printdepth") || a.equalsIgnoreCase("depth")){ |
| 216 |
printDepth=Parse.parseBoolean(b); |
| 217 |
}else if(a.equalsIgnoreCase("printdepth2") || a.equalsIgnoreCase("depth2")){ |
| 218 |
printDepth2=Parse.parseBoolean(b); |
| 219 |
}else if(a.equalsIgnoreCase("actualdepth") || a.equalsIgnoreCase("printactualdepth")){ |
| 220 |
printActualDepth=Parse.parseBoolean(b); |
| 221 |
}else if(a.equalsIgnoreCase("printvolume") || a.equalsIgnoreCase("volume")){ |
| 222 |
printVolume=Parse.parseBoolean(b); |
| 223 |
}else if(a.equalsIgnoreCase("printavgrefhits") || a.equalsIgnoreCase("printrefhits") || a.equalsIgnoreCase("avgrefhits") || a.equalsIgnoreCase("refhits")){ |
| 224 |
printRefHits=Parse.parseBoolean(b); |
| 225 |
} |
| 226 |
|
| 227 |
else if(a.equalsIgnoreCase("sortByDepth")){ |
| 228 |
boolean x=Parse.parseBoolean(b); |
| 229 |
if(x){comparator=Comparison.depthComparator;} |
| 230 |
}else if(a.equalsIgnoreCase("sortByDepth2")){ |
| 231 |
boolean x=Parse.parseBoolean(b); |
| 232 |
if(x){comparator=Comparison.depth2Comparator;} |
| 233 |
}else if(a.equalsIgnoreCase("sortByVolume")){ |
| 234 |
boolean x=Parse.parseBoolean(b); |
| 235 |
if(x){comparator=Comparison.volumeComparator;} |
| 236 |
}else if(a.equalsIgnoreCase("sortByScore")){ |
| 237 |
boolean x=Parse.parseBoolean(b); |
| 238 |
if(x){comparator=Comparison.scoreComparator;} |
| 239 |
} |
| 240 |
else if(a.equalsIgnoreCase("sortByKID")){ |
| 241 |
boolean x=Parse.parseBoolean(b); |
| 242 |
if(x){comparator=Comparison.KIDComparator;} |
| 243 |
}else if(a.equalsIgnoreCase("sortByWKID") || a.equalsIgnoreCase("sortByANI")){ |
| 244 |
boolean x=Parse.parseBoolean(b); |
| 245 |
if(x){comparator=Comparison.WKIDComparator;} |
| 246 |
}else if(a.equalsIgnoreCase("sortBySSU") || a.equalsIgnoreCase("sortBy16S")){ |
| 247 |
boolean x=Parse.parseBoolean(b); |
| 248 |
if(x){comparator=Comparison.SSUComparator;} |
| 249 |
}else if(a.equalsIgnoreCase("sortByHits") || a.equalsIgnoreCase("sortByMatches")){ |
| 250 |
boolean x=Parse.parseBoolean(b); |
| 251 |
if(x){comparator=Comparison.HitsComparator;} |
| 252 |
} |
| 253 |
|
| 254 |
else if(a.equalsIgnoreCase("printUMatches") || a.equalsIgnoreCase("printUHits") || a.equalsIgnoreCase("printUnique")){ |
| 255 |
printUnique=Parse.parseBoolean(b); |
| 256 |
}else if(a.equalsIgnoreCase("printUMatches2") || a.equalsIgnoreCase("printUnique2") || a.equalsIgnoreCase("unique2")){ |
| 257 |
printUnique2=Parse.parseBoolean(b); |
| 258 |
}else if(a.equalsIgnoreCase("printUMatches3") || a.equalsIgnoreCase("printUnique3") || a.equalsIgnoreCase("unique3")){ |
| 259 |
printUnique3=Parse.parseBoolean(b); |
| 260 |
}else if(a.equalsIgnoreCase("printUContam")){ |
| 261 |
printUContam=Parse.parseBoolean(b); |
| 262 |
}else if(a.equalsIgnoreCase("printNoHit")){ |
| 263 |
printNoHit=Parse.parseBoolean(b); |
| 264 |
}else if(a.equalsIgnoreCase("contamhits") || a.equalsIgnoreCase("contam") || a.equalsIgnoreCase("printcontam")){ |
| 265 |
printContam=Parse.parseBoolean(b); |
| 266 |
}else if(a.equalsIgnoreCase("contamhits2") || a.equalsIgnoreCase("contam2") || a.equalsIgnoreCase("printcontam2")){ |
| 267 |
if(b==null || b.length()<1){ |
| 268 |
printContam2=true; |
| 269 |
}else if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ |
| 270 |
contamLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); |
| 271 |
printContam2=true; |
| 272 |
}else if(TaxTree.levelMapExtendedContains(b)){ |
| 273 |
contamLevel=TaxTree.stringToLevelExtended(b); |
| 274 |
printContam2=true; |
| 275 |
}else{ |
| 276 |
printContam2=Parse.parseBoolean(b); |
| 277 |
} |
| 278 |
}else if(a.equalsIgnoreCase("contamLevel")){ |
| 279 |
if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ |
| 280 |
contamLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); |
| 281 |
printContam2=true; |
| 282 |
}else if(TaxTree.levelMapExtendedContains(b)){ |
| 283 |
contamLevel=TaxTree.stringToLevelExtended(b); |
| 284 |
printContam2=true; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
else if(a.equalsIgnoreCase("reportAniOnly") || a.equalsIgnoreCase("AniOnly")){ |
| 289 |
reportAniOnly=Parse.parseBoolean(b); |
| 290 |
} |
| 291 |
|
| 292 |
else if(a.equalsIgnoreCase("printMatches")){ |
| 293 |
printMatches=Parse.parseBoolean(b); |
| 294 |
}else if(a.equalsIgnoreCase("printLength")){ |
| 295 |
printLength=Parse.parseBoolean(b); |
| 296 |
}else if(a.equalsIgnoreCase("printTaxID")){ |
| 297 |
printTaxID=Parse.parseBoolean(b); |
| 298 |
}else if(a.equalsIgnoreCase("printGSize")){ |
| 299 |
printGSize=Parse.parseBoolean(b); |
| 300 |
}else if(a.equalsIgnoreCase("gSizeKMG")){ |
| 301 |
gSizeKMG=Parse.parseBoolean(b); |
| 302 |
}else if(a.equalsIgnoreCase("printGC")){ |
| 303 |
printGC=Parse.parseBoolean(b); |
| 304 |
}else if(a.equalsIgnoreCase("printGKmers")){ |
| 305 |
printGKmers=Parse.parseBoolean(b); |
| 306 |
}else if(a.equalsIgnoreCase("printCommonAncestor") || a.equalsIgnoreCase("printCA")){ |
| 307 |
printCommonAncestor=Parse.parseBoolean(b); |
| 308 |
}else if(a.equalsIgnoreCase("printCommonAncestorLevel") || a.equalsIgnoreCase("printCAL")){ |
| 309 |
printCommonAncestorLevel=Parse.parseBoolean(b); |
| 310 |
}else if(a.equalsIgnoreCase("printTaxName")){ |
| 311 |
printTaxName=Parse.parseBoolean(b); |
| 312 |
}else if(a.equalsIgnoreCase("printGSeqs")){ |
| 313 |
printGSeqs=Parse.parseBoolean(b); |
| 314 |
}else if(a.equalsIgnoreCase("printGBases")){ |
| 315 |
printGBases=Parse.parseBoolean(b); |
| 316 |
} |
| 317 |
|
| 318 |
else if(a.equalsIgnoreCase("minEntropy") || a.equalsIgnoreCase("entropy") || a.equalsIgnoreCase("efilter")){ |
| 319 |
minEntropy=Float.parseFloat(b); |
| 320 |
}else if(a.equalsIgnoreCase("minprob") || a.equalsIgnoreCase("pfilter")){ |
| 321 |
minProb=(float)Double.parseDouble(b); |
| 322 |
}else if(a.equalsIgnoreCase("minQual") || a.equalsIgnoreCase("minq")){ |
| 323 |
minQual=Byte.parseByte(b); |
| 324 |
} |
| 325 |
|
| 326 |
else if(a.equalsIgnoreCase("printColors") || a.equalsIgnoreCase("colors") || a.equalsIgnoreCase("color")){ |
| 327 |
|
| 328 |
if(b==null || b.length()<1){ |
| 329 |
printColors=true; |
| 330 |
}else if(b.equalsIgnoreCase("t") || b.equalsIgnoreCase("true")){ |
| 331 |
printColors=true; |
| 332 |
}else if(b.equalsIgnoreCase("f") || b.equalsIgnoreCase("false")){ |
| 333 |
printColors=false; |
| 334 |
}else{ |
| 335 |
printColors=true; |
| 336 |
if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ |
| 337 |
colorLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); |
| 338 |
}else{ |
| 339 |
colorLevel=TaxTree.stringToLevelExtended(b); |
| 340 |
} |
| 341 |
} |
| 342 |
setColors=true; |
| 343 |
|
| 344 |
}else if(a.equalsIgnoreCase("colorLevel")){ |
| 345 |
|
| 346 |
if(Tools.isDigit(b.charAt(0)) || b.charAt(0)=='-'){ |
| 347 |
colorLevel=Tools.max(0, TaxTree.levelToExtended(Integer.parseInt(b))); |
| 348 |
}else{ |
| 349 |
colorLevel=TaxTree.stringToLevelExtended(b); |
| 350 |
} |
| 351 |
|
| 352 |
} |
| 353 |
|
| 354 |
else if(a.equalsIgnoreCase("printRefDivisor") || a.equalsIgnoreCase("printRDiv")){ |
| 355 |
printRefDivisor=Parse.parseBoolean(b); |
| 356 |
}else if(a.equalsIgnoreCase("printQueryDivisor") || a.equalsIgnoreCase("printQDiv")){ |
| 357 |
printQueryDivisor=Parse.parseBoolean(b); |
| 358 |
}else if(a.equalsIgnoreCase("printRefSize") || a.equalsIgnoreCase("printRSize")){ |
| 359 |
printRefSize=Parse.parseBoolean(b); |
| 360 |
}else if(a.equalsIgnoreCase("printQuerySize") || a.equalsIgnoreCase("printQSize")){ |
| 361 |
printQuerySize=Parse.parseBoolean(b); |
| 362 |
}else if(a.equalsIgnoreCase("printContamHits") || a.equalsIgnoreCase("printCHits")){ |
| 363 |
printContamHits=Parse.parseBoolean(b); |
| 364 |
} |
| 365 |
|
| 366 |
else if(a.equalsIgnoreCase("printIntersection") || a.equalsIgnoreCase("intersection") || a.equalsIgnoreCase("intersect")){ |
| 367 |
printIntersection=Parse.parseBoolean(b); |
| 368 |
}else if(a.equalsIgnoreCase("mergePairs") || a.equalsIgnoreCase("merge")){ |
| 369 |
mergePairs=Parse.parseBoolean(b); |
| 370 |
} |
| 371 |
|
| 372 |
else if(a.equalsIgnoreCase("printAll")){ |
| 373 |
if(Parse.parseBoolean(b)){ |
| 374 |
setPrintAll(); |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
else if(a.equals("samplerate")){ |
| 379 |
samplerate=Float.parseFloat(b); |
| 380 |
}else if(a.equals("reads")){ |
| 381 |
maxReads=Parse.parseKMG(b); |
| 382 |
}else if(a.equals("mode") || a.equalsIgnoreCase("single") || a.equalsIgnoreCase("singlesketch") || a.equalsIgnoreCase("onesketch") |
| 383 |
|| a.equalsIgnoreCase("persequence") || a.equalsIgnoreCase("sequence") || a.equalsIgnoreCase("pertaxa") |
| 384 |
|| a.equalsIgnoreCase("perheader") || a.equalsIgnoreCase("perfile")){ |
| 385 |
mode=SketchObject.parseMode(arg, a, b); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
else if(a.equalsIgnoreCase("useTaxidName") || a.equalsIgnoreCase("useTaxidAsName")){ |
| 390 |
useTaxidName=Parse.parseBoolean(b); |
| 391 |
}else if(a.equalsIgnoreCase("useImgName") || a.equalsIgnoreCase("useImgAsName")){ |
| 392 |
useImgName=Parse.parseBoolean(b); |
| 393 |
}else if(a.equalsIgnoreCase("useTaxName") || a.equalsIgnoreCase("useTaxAsName")){ |
| 394 |
useTaxName=Parse.parseBoolean(b); |
| 395 |
}else if(a.equalsIgnoreCase("useFilePrefixName") || a.equalsIgnoreCase("useFilePrefixAsName")){ |
| 396 |
useFilePrefixName=Parse.parseBoolean(b); |
| 397 |
} |
| 398 |
|
| 399 |
else if(a.equalsIgnoreCase("taxfilterincludelevel") || a.equalsIgnoreCase("includelevel") |
| 400 |
|| a.equalsIgnoreCase("taxlevelwhite") || a.equalsIgnoreCase("ilevel") || a.equalsIgnoreCase("whitelevel")){ |
| 401 |
taxLevelWhite=TaxTree.parseLevel(b); |
| 402 |
}else if(a.equalsIgnoreCase("taxfilterinclude") || a.equalsIgnoreCase("include") || a.equalsIgnoreCase("taxfilterwhitelist")){ |
| 403 |
taxFilterWhiteList=b; |
| 404 |
}else if(a.equalsIgnoreCase("taxfilterincludestring") || a.equalsIgnoreCase("includestring") |
| 405 |
|| a.equalsIgnoreCase("taxfilterwhitestring") || a.equalsIgnoreCase("istring")){ |
| 406 |
taxFilterWhiteString=b; |
| 407 |
}else if(a.equalsIgnoreCase("banUnclassified") || a.equalsIgnoreCase("noUnclassified")){ |
| 408 |
banUnclassified=Parse.parseBoolean(b); |
| 409 |
}else if(a.equalsIgnoreCase("banVirus") || a.equalsIgnoreCase("noVirus") || a.equalsIgnoreCase("banViruses") || a.equalsIgnoreCase("noViruses")){ |
| 410 |
banVirus=Parse.parseBoolean(b); |
| 411 |
} |
| 412 |
|
| 413 |
else if(a.equalsIgnoreCase("taxfilterexcludelevel") || a.equalsIgnoreCase("excludelevel") |
| 414 |
|| a.equalsIgnoreCase("taxlevelblack") || a.equalsIgnoreCase("elevel") || a.equalsIgnoreCase("blacklevel")){ |
| 415 |
taxLevelBlack=TaxTree.parseLevel(b); |
| 416 |
}else if(a.equalsIgnoreCase("taxfilterexclude") || a.equalsIgnoreCase("exclude") || a.equalsIgnoreCase("taxfilterblacklist")){ |
| 417 |
taxFilterBlackList=b; |
| 418 |
}else if(a.equalsIgnoreCase("taxfilterexcludestring") || a.equalsIgnoreCase("excludestring") |
| 419 |
|| a.equalsIgnoreCase("taxfilterblackstring") || a.equalsIgnoreCase("estring")){ |
| 420 |
taxFilterBlackString=b; |
| 421 |
} |
| 422 |
|
| 423 |
else if(a.equalsIgnoreCase("minkmercount") || a.equalsIgnoreCase("minkeycount") || a.equalsIgnoreCase("mincount") || a.equalsIgnoreCase("minKeyOccuranceCount")){ |
| 424 |
minKeyOccuranceCount=Tools.max(1, Integer.parseInt(b)); |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
else if(a.equalsIgnoreCase("k") || a.equalsIgnoreCase("hk")){ |
| 432 |
|
| 433 |
if(b.indexOf(',')>=0){ |
| 434 |
String[] split=b.split(","); |
| 435 |
assert(split.length==2) : "\nBad argument "+arg+"\n"+b+"\n"; |
| 436 |
int x=Integer.parseInt(split[0]); |
| 437 |
int y=Integer.parseInt(split[1]); |
| 438 |
k=Tools.max(x, y); |
| 439 |
k2=Tools.min(x, y); |
| 440 |
if(k==k2){k2=0;} |
| 441 |
|
| 442 |
}else{ |
| 443 |
k=Integer.parseInt(b); |
| 444 |
|
| 445 |
} |
| 446 |
}else if(a.equalsIgnoreCase("hashversion") || a.equalsIgnoreCase("hv")){ |
| 447 |
hashVersion=Integer.parseInt(b); |
| 448 |
}else if(a.equalsIgnoreCase("amino") || a.equalsIgnoreCase("hamino")){ |
| 449 |
amino=Parse.parseBoolean(b); |
| 450 |
if(amino){translate=false;} |
| 451 |
}else if(a.equalsIgnoreCase("translate")){ |
| 452 |
translate=Parse.parseBoolean(b); |
| 453 |
if(translate){amino=false;} |
| 454 |
}else if(a.equalsIgnoreCase("sixframes")){ |
| 455 |
sixframes=Parse.parseBoolean(b); |
| 456 |
if(sixframes){amino=false; translate=true;} |
| 457 |
} |
| 458 |
|
| 459 |
else if(a.equalsIgnoreCase("requiredmeta") || a.equalsIgnoreCase("rmeta")){ |
| 460 |
if(b==null){requiredMeta=null;} |
| 461 |
else{ |
| 462 |
String[] split2=b.split(","); |
| 463 |
requiredMeta=new ArrayList<String>(split2.length); |
| 464 |
for(String mt : split2){ |
| 465 |
assert(mt.indexOf(':')>=0) : "Metadata tags must contain ':' symbol: "+mt; |
| 466 |
requiredMeta.add(mt); |
| 467 |
} |
| 468 |
} |
| 469 |
}else if(a.equalsIgnoreCase("bannedmeta") || a.equalsIgnoreCase("bmeta")){ |
| 470 |
if(b==null){bannedMeta=null;} |
| 471 |
else{ |
| 472 |
String[] split2=b.split(","); |
| 473 |
bannedMeta=new ArrayList<String>(split2.length); |
| 474 |
for(String mt : split2){ |
| 475 |
assert(mt.indexOf(':')>=0) : "Metadata tags must contain ':' symbol: "+mt; |
| 476 |
bannedMeta.add(mt); |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
else if(a.equalsIgnoreCase("requiredmetaand") || a.equalsIgnoreCase("rmetaand")){ |
| 504 |
requiredMetaAnd=Parse.parseBoolean(b); |
| 505 |
}else if(a.equalsIgnoreCase("requiredmetaor") || a.equalsIgnoreCase("rmetaor")){ |
| 506 |
requiredMetaAnd=!Parse.parseBoolean(b); |
| 507 |
} |
| 508 |
|
| 509 |
else if(a.equalsIgnoreCase("bbversion")){ |
| 510 |
inputVersion=b; |
| 511 |
} |
| 512 |
|
| 513 |
else{ |
| 514 |
return false; |
| 515 |
} |
| 516 |
return true; |
| 517 |
} |
| 518 |
|
| 519 |
public void postParse(boolean requireTree, boolean makeTaxFilters){ |
| 520 |
assert(!postParsed); |
| 521 |
synchronized(this){ |
| 522 |
if(postParsed){return;} |
| 523 |
|
| 524 |
if(makeTaxFilters){ |
| 525 |
if(taxFilterWhiteList!=null || taxFilterWhiteString!=null){ |
| 526 |
taxFilterWhite=new TaxFilter(SketchObject.taxtree, true); |
| 527 |
taxFilterWhite.setLevel(taxLevelWhite, false); |
| 528 |
taxFilterWhite.makeSet(); |
| 529 |
taxFilterWhite.addNamesOrNumbers(taxFilterWhiteList, false); |
| 530 |
taxFilterWhite.setContainsString(taxFilterWhiteString); |
| 531 |
if(requireTree){ |
| 532 |
assert(SketchObject.taxtree!=null) : "No taxtree loaded."; |
| 533 |
taxFilterWhite.setTree(SketchObject.taxtree); |
| 534 |
taxFilterWhite.promote(); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
if(taxFilterBlackList!=null || taxFilterBlackString!=null){ |
| 539 |
taxFilterBlack=new TaxFilter(SketchObject.taxtree, false); |
| 540 |
taxFilterBlack.setLevel(taxLevelBlack, false); |
| 541 |
taxFilterBlack.makeSet(); |
| 542 |
taxFilterBlack.addNamesOrNumbers(taxFilterBlackList, false); |
| 543 |
taxFilterBlack.setContainsString(taxFilterBlackString); |
| 544 |
if(requireTree){ |
| 545 |
assert(SketchObject.taxtree!=null) : "No taxtree loaded."; |
| 546 |
taxFilterBlack.setTree(SketchObject.taxtree); |
| 547 |
taxFilterBlack.promote(); |
| 548 |
} |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
noFilters=(!hasMetaFilters() && !hasTaxFilters() && !requireSSU && minRefSizeEstimate<1 && minRefSizeBases<1); |
| 553 |
postParsed=true; |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
public boolean postParsed(){return postParsed;} |
| 558 |
|
| 559 |
@Override |
| 560 |
public String toString(){ |
| 561 |
return toString(-1); |
| 562 |
} |
| 563 |
|
| 564 |
public String toString(int chunkNum){ |
| 565 |
StringBuilder sb=new StringBuilder(); |
| 566 |
sb.append("##"); |
| 567 |
sb.append("hits=").append(minHits); |
| 568 |
if(chunkNum>=0){sb.append(" chunk=").append(chunkNum);} |
| 569 |
sb.append(" wkid=").append(Tools.format("%.5f",minWKID)); |
| 570 |
if(minANI>0){sb.append(" id=").append(Tools.format("%.5f",minANI));} |
| 571 |
if(minBases>0){sb.append(" minbases=").append(minBases);} |
| 572 |
if(minSizeRatio>0){sb.append(" minsizeratio=").append(Tools.format("%.5f",minSizeRatio));} |
| 573 |
sb.append(" records=").append(maxRecords); |
| 574 |
if(recordsPerLevel>0){sb.append(" recordsperlevel=").append(recordsPerLevel);} |
| 575 |
sb.append(" format=").append(format); |
| 576 |
sb.append(" level=").append(taxLevel); |
| 577 |
if(inputVersion!=null){sb.append(" bbversion=").append(inputVersion);} |
| 578 |
|
| 579 |
if(k!=SketchObject.defaultK || k2!=0 || k!=SketchObject.k || k2!=SketchObject.k2){ |
| 580 |
assert(k>0 && k2>=0 && k2<k) : "Bad values for k: "+k+", "+k2+", "+SketchObject.k+", "+SketchObject.k2; |
| 581 |
assert(SketchObject.k>0 && SketchObject.k2>=0 && SketchObject.k2<SketchObject.k) : "Bad values for k: "+k+", "+k2+", "+SketchObject.k+", "+SketchObject.k2; |
| 582 |
sb.append(" hk=").append(SketchObject.k).append(',').append(SketchObject.k2); |
| 583 |
} |
| 584 |
if(SketchObject.amino){sb.append(" hamino=").append(SketchObject.amino);} |
| 585 |
if(SketchObject.translate){sb.append(" translate=").append(SketchObject.translate);} |
| 586 |
if(SketchObject.sixframes){sb.append(" sixframes=").append(SketchObject.sixframes);} |
| 587 |
if(SketchObject.HASH_VERSION>1){sb.append(" hashversion=").append(SketchObject.HASH_VERSION);} |
| 588 |
|
| 589 |
if(true){sb.append(" printSSU=").append(printSSU());} |
| 590 |
if(requireSSU){sb.append(" requireSSU=").append(requireSSU);} |
| 591 |
if(minRefSizeEstimate>0){sb.append(" minRefSizeEstimate=").append(minRefSizeEstimate);} |
| 592 |
if(minRefSizeBases>0){sb.append(" minRefSizeBases=").append(minRefSizeBases);} |
| 593 |
|
| 594 |
if(json()){sb.append(" printSSUSequence=").append(printSSUSequence);} |
| 595 |
if(printSSULen){sb.append(" printSSULen=").append(printSSULen);} |
| 596 |
if(true || printTax!=default_printTax){sb.append(" printTax=").append(printTax);} |
| 597 |
|
| 598 |
if(true || printQueryFileName!=default_printQueryFileName){sb.append(" printqfname=").append(printQueryFileName);} |
| 599 |
if(true || printRefFileName!=default_printRefFileName){sb.append(" printrfname=").append(printRefFileName);} |
| 600 |
if(true || printOriginalName!=default_printOriginalName){sb.append(" pn0=").append(printOriginalName);} |
| 601 |
if(true || printImg!=default_printImg){sb.append(" printImg=").append(printImg);} |
| 602 |
if(true || printAni!=default_printAni){sb.append(" printAni=").append(printAni);} |
| 603 |
if(!printKID){sb.append(" printKID=").append(printKID);} |
| 604 |
if(!printWKID){sb.append(" printWKID=").append(printWKID);} |
| 605 |
if(true || printCompleteness!=default_printCompleteness){sb.append(" printCompleteness=").append(printCompleteness);} |
| 606 |
|
| 607 |
if(true || printUnique!=default_printUnique){sb.append(" printUMatches=").append(printUnique);} |
| 608 |
if(true || printUnique2!=default_printUnique2){sb.append(" printUnique2=").append(printUnique2);} |
| 609 |
if(true || printUnique3!=default_printUnique3){sb.append(" printUnique3=").append(printUnique3);} |
| 610 |
if(true || printUContam!=default_printUContam){sb.append(" printUContam=").append(printUContam);} |
| 611 |
if(true || printNoHit!=default_printNoHit){sb.append(" printNoHit=").append(printNoHit);} |
| 612 |
if(true || printContam!=default_printContam){sb.append(" contam=").append(printContam);} |
| 613 |
if(true){sb.append(" contam2=").append(printContam2 ? TaxTree.extendedToLevel(contamLevel)+"" : "f");} |
| 614 |
|
| 615 |
if(true || printScore!=default_printScore){sb.append(" printScore=").append(printScore);} |
| 616 |
if(true || printEValue!=default_printEValue){sb.append(" printEValue=").append(printEValue);} |
| 617 |
|
| 618 |
if(true || printDepth!=default_printDepth){sb.append(" printDepth=").append(printDepth);} |
| 619 |
if(true || printDepth2!=default_printDepth2){sb.append(" printDepth2=").append(printDepth2);} |
| 620 |
if(true || printActualDepth!=default_printActualDepth){sb.append(" printActualDepth=").append(printActualDepth);} |
| 621 |
if(true || printVolume!=default_printVolume){sb.append(" printVolume=").append(printVolume);} |
| 622 |
if(true || printRefHits!=default_printRefHits){sb.append(" printRefHits=").append(printRefHits);} |
| 623 |
|
| 624 |
if(true || printMatches!=default_printMatches){sb.append(" printMatches=").append(printMatches);} |
| 625 |
if(true || printLength!=default_printLength){sb.append(" printLength=").append(printLength);} |
| 626 |
if(true || printTaxID!=default_printTaxID){sb.append(" printTaxID=").append(printTaxID);} |
| 627 |
if(true || printGSize!=default_printGSize){sb.append(" printGSize=").append(printGSize);} |
| 628 |
if(true || gSizeKMG!=default_gSizeKMG){sb.append(" gSizeKMG=").append(gSizeKMG);} |
| 629 |
if(true || printGC!=default_printGC){sb.append(" printGC=").append(printGC);} |
| 630 |
if(true || printGKmers!=default_printGKmers){sb.append(" printGKmers=").append(printGKmers);} |
| 631 |
|
| 632 |
if(printCommonAncestor){sb.append(" printCommonAncestor=").append(printCommonAncestor);} |
| 633 |
if(printCommonAncestorLevel){sb.append(" printCommonAncestorLevel=").append(printCommonAncestorLevel);} |
| 634 |
|
| 635 |
if(true || printTaxName!=default_printTaxName){sb.append(" printTaxName=").append(printTaxName);} |
| 636 |
if(true || printGSeqs!=default_printGSeqs){sb.append(" printGSeqs=").append(printGSeqs);} |
| 637 |
if(true || printGBases!=default_printGBases){sb.append(" printGBases=").append(printGBases);} |
| 638 |
if(true || minEntropy!=default_minEntropy){sb.append(" minEntropy=").append(Tools.format("%.4f", minEntropy));} |
| 639 |
if(true || minProb!=default_minProb){sb.append(" minProb=").append(Tools.format("%.4f", minProb));} |
| 640 |
if(true || minQual!=default_minQual){sb.append(" minQual=").append((int)minQual);} |
| 641 |
if(jsonArray!=default_jsonArray){sb.append(" jsonArray=").append(jsonArray);} |
| 642 |
if(printD3!=default_printD3){sb.append(" d3=").append(printD3);} |
| 643 |
if(printD3){ |
| 644 |
sb.append(" D3sizeMode=").append(D3sizeMode); |
| 645 |
sb.append(" D3LevelNodes=").append(D3LevelNodes); |
| 646 |
} |
| 647 |
if(comparator!=Comparison.scoreComparator){sb.append(" ").append(comparator.toString());} |
| 648 |
|
| 649 |
if(taxFilterWhiteList!=null || taxFilterWhiteString!=null){ |
| 650 |
if(taxFilterWhiteList!=null){sb.append(" taxfilterwhitelist=").append(taxFilterWhiteList);} |
| 651 |
if(taxFilterWhiteString!=null){sb.append(" taxfilterwhitestring=").append(taxFilterWhiteString);} |
| 652 |
sb.append(" taxlevelwhite=").append(taxLevelWhite); |
| 653 |
} |
| 654 |
if(taxFilterBlackList!=null || taxFilterBlackString!=null){ |
| 655 |
if(taxFilterBlackList!=null){sb.append(" taxfilterblacklist=").append(taxFilterBlackList);} |
| 656 |
if(taxFilterBlackString!=null){sb.append(" taxfilterblackstring=").append(taxFilterBlackString);} |
| 657 |
sb.append(" taxlevelblack=").append(taxLevelBlack); |
| 658 |
} |
| 659 |
if(banUnclassified){sb.append(" banunclassified");} |
| 660 |
if(banVirus){sb.append(" banvirus");} |
| 661 |
|
| 662 |
if(useTaxidName){sb.append(" useTaxidName=").append(useTaxidName);} |
| 663 |
if(useImgName){sb.append(" useImgName=").append(useImgName);} |
| 664 |
if(useTaxName){sb.append(" useTaxName=").append(useTaxName);} |
| 665 |
|
| 666 |
if(true){sb.append(" colors=").append(printColors ? TaxTree.extendedToLevel(colorLevel)+"" : "f");} |
| 667 |
|
| 668 |
if(minKeyOccuranceCount!=default_minKeyOccuranceCount){sb.append(" minKeyOccuranceCount=").append(minKeyOccuranceCount);} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
if(printRefDivisor){sb.append(" printRefDivisor=").append(printRefDivisor);} |
| 674 |
if(printQueryDivisor){sb.append(" printQueryDivisor=").append(printQueryDivisor);} |
| 675 |
if(printRefSize){sb.append(" printRefSize=").append(printRefSize);} |
| 676 |
if(printQuerySize){sb.append(" printQuerySize=").append(printQuerySize);} |
| 677 |
if(printContamHits){sb.append(" printContamHits=").append(printContamHits);} |
| 678 |
if(printIntersection){sb.append(" printIntersection=").append(printIntersection);} |
| 679 |
if(mergePairs){sb.append(" mergePairs=").append(mergePairs);} |
| 680 |
|
| 681 |
if(maxReads>-1){sb.append(" reads=").append(maxReads);} |
| 682 |
if(mode!=default_mode){sb.append(" mode=").append(mode);} |
| 683 |
if(samplerate!=default_samplerate){sb.append(" samplerate=").append(Tools.format("%.4f",samplerate));} |
| 684 |
|
| 685 |
if(!requiredMetaAnd){sb.append(" requiredmetaand="+requiredMetaAnd);} |
| 686 |
if(requiredMeta!=null && !requiredMeta.isEmpty()){ |
| 687 |
sb.append(" rmeta="); |
| 688 |
for(String s : requiredMeta){ |
| 689 |
sb.append(s); |
| 690 |
sb.append(','); |
| 691 |
} |
| 692 |
sb.setLength(sb.length()-1); |
| 693 |
} |
| 694 |
if(bannedMeta!=null && !bannedMeta.isEmpty()){ |
| 695 |
sb.append(" bmeta="); |
| 696 |
for(String s : bannedMeta){ |
| 697 |
sb.append(s); |
| 698 |
sb.append(','); |
| 699 |
} |
| 700 |
sb.setLength(sb.length()-1); |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
sb.append('\n'); |
| 720 |
return sb.toString(); |
| 721 |
} |
| 722 |
|
| 723 |
public boolean compatible(){ |
| 724 |
return SketchObject.k==k && SketchObject.k2==k2 && SketchObject.aminoOrTranslate()==aminoOrTranslate() && hashVersion==SketchObject.HASH_VERSION; |
| 725 |
} |
| 726 |
|
| 727 |
public void setPrintAll(){ |
| 728 |
printSSU=true; |
| 729 |
printSSULen=true; |
| 730 |
printSSUSequence=true; |
| 731 |
printTax=true; |
| 732 |
printQueryFileName=true; |
| 733 |
printRefFileName=true; |
| 734 |
printOriginalName=true; |
| 735 |
printImg=true; |
| 736 |
printAni=true; |
| 737 |
printKID=true; |
| 738 |
printWKID=true; |
| 739 |
printCompleteness=true; |
| 740 |
printScore=true; |
| 741 |
printEValue=true; |
| 742 |
printDepth=true; |
| 743 |
printDepth2=true; |
| 744 |
printVolume=true; |
| 745 |
printRefHits=true; |
| 746 |
|
| 747 |
printMatches=true; |
| 748 |
printLength=true; |
| 749 |
printTaxID=true; |
| 750 |
printGSize=true; |
| 751 |
printGC=true; |
| 752 |
printGKmers=true; |
| 753 |
printTaxName=true; |
| 754 |
printGSeqs=true; |
| 755 |
printGBases=true; |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
printUnique=true; |
| 760 |
printUnique2=true; |
| 761 |
printUnique3=true; |
| 762 |
printUContam=true; |
| 763 |
printNoHit=true; |
| 764 |
printContam=true; |
| 765 |
printContam2=true; |
| 766 |
|
| 767 |
printRefDivisor=true; |
| 768 |
printQueryDivisor=true; |
| 769 |
printRefSize=true; |
| 770 |
printQuerySize=true; |
| 771 |
printContamHits=true; |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
public JsonObject toJson(SketchResults sr){ |
| 779 |
JsonObject j=toJson(sr.sketch); |
| 780 |
if(sr.list!=null){ |
| 781 |
int i=0; |
| 782 |
for(Comparison c : sr.list){ |
| 783 |
JsonObject jc=toJson(c); |
| 784 |
j.add(c.name(), jc); |
| 785 |
i++; |
| 786 |
if(i>=maxRecords){break;} |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
if(jsonArray){ |
| 791 |
toJsonArrayForm(j); |
| 792 |
} |
| 793 |
|
| 794 |
if(printD3){ |
| 795 |
j.add("D3", toD3(sr)); |
| 796 |
} |
| 797 |
|
| 798 |
return j; |
| 799 |
} |
| 800 |
|
| 801 |
public void toJsonArrayForm(JsonObject j0){ |
| 802 |
if(j0.jmapSize()<1){return;} |
| 803 |
ArrayList<Object> list1=new ArrayList<Object>(j0.jmapSize()); |
| 804 |
Object[] keys=null; |
| 805 |
for(Entry<String, JsonObject> e1 : j0.jmap.entrySet()){ |
| 806 |
JsonObject j1=e1.getValue(); |
| 807 |
ArrayList<Object> list2=new ArrayList<Object>(j1.omapSize()); |
| 808 |
for(Entry<String, Object> e2 : j1.omap.entrySet()){ |
| 809 |
Object o2=e2.getValue(); |
| 810 |
list2.add(o2); |
| 811 |
} |
| 812 |
list1.add(list2.toArray()); |
| 813 |
if(keys==null){ |
| 814 |
ArrayList<Object> keyList=new ArrayList<Object>(j1.omapSize()); |
| 815 |
for(Entry<String, Object> e2 : j1.omap.entrySet()){ |
| 816 |
Object o2=e2.getKey(); |
| 817 |
keyList.add(o2); |
| 818 |
} |
| 819 |
keys=keyList.toArray(); |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
JsonObject title=new JsonObject(); |
| 824 |
for(Entry<String, Object> e : j0.omap.entrySet()){ |
| 825 |
title.add(e.getKey(), e.getValue()); |
| 826 |
} |
| 827 |
|
| 828 |
j0.clearJson(); |
| 829 |
j0.clearOmap(); |
| 830 |
|
| 831 |
j0.add("title", title); |
| 832 |
j0.add("header", keys); |
| 833 |
j0.add("rows", list1.toArray()); |
| 834 |
} |
| 835 |
|
| 836 |
public JsonObject toJson(Sketch sk){ |
| 837 |
assert(format==FORMAT_JSON); |
| 838 |
|
| 839 |
JsonObject j=new JsonObject(); |
| 840 |
j.add("Name", sk.name()); |
| 841 |
if(dbName!=null){j.add("DB", dbName);} |
| 842 |
j.add("SketchLen", sk.length()); |
| 843 |
|
| 844 |
j.add("Seqs", sk.genomeSequences); |
| 845 |
j.add("Bases", sk.genomeSizeBases); |
| 846 |
j.add("gSize", sk.genomeSizeEstimate()); |
| 847 |
if(sk.baseCounts!=null){j.addLiteral("GC", sk.gc(), 3);} |
| 848 |
if(sk.probCorrect<1 && sk.probCorrect>0){j.add("Quality", sk.probCorrect);} |
| 849 |
if(sk.keyCounts!=null){ |
| 850 |
double d=Tools.averageDouble(sk.keyCounts); |
| 851 |
j.add("AvgCount", d); |
| 852 |
j.add("Depth", Tools.observedToActualCoverage(d)); |
| 853 |
} |
| 854 |
|
| 855 |
if(sk.imgID>0){j.add("IMG", sk.imgID);} |
| 856 |
if(sk.spid>0){j.add("spid", sk.spid);} |
| 857 |
if(sk.taxID>0 && sk.taxID<SketchObject.minFakeID){j.add("TaxID", sk.taxID);} |
| 858 |
|
| 859 |
if((printRefFileName) && sk.fname()!=null){j.add("file", sk.fname());} |
| 860 |
if(printOriginalName && sk.name0()!=null){j.add("SeqName", sk.name0());} |
| 861 |
|
| 862 |
if(sk.meta!=null){ |
| 863 |
for(String st : sk.meta){ |
| 864 |
int colon=st.indexOf(':'); |
| 865 |
j.add(st.substring(0, colon), st.substring(colon+1)); |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
if(printSSULen){ |
| 870 |
if(sk.r16SLen()>0){j.add("16SLen", sk.r16SLen());} |
| 871 |
if(sk.r18SLen()>0){j.add("18SLen", sk.r18SLen());} |
| 872 |
} |
| 873 |
if(printSSUSequence){ |
| 874 |
if(sk.r16S()!=null){j.add("16SSequence", new String(sk.r16S()));} |
| 875 |
if(sk.r18S()!=null){j.add("18SSequence", new String(sk.r18S()));} |
| 876 |
} |
| 877 |
|
| 878 |
return j; |
| 879 |
} |
| 880 |
|
| 881 |
public JsonObject toJson(Comparison c){ |
| 882 |
final int tid=c.taxID; |
| 883 |
|
| 884 |
JsonObject j=new JsonObject(); |
| 885 |
|
| 886 |
|
| 887 |
if(printTaxName){j.add("taxName", c.taxName()==null ? "." : c.taxName());} |
| 888 |
|
| 889 |
if(printCommonAncestor){j.add("commonAncestor", c.commonAncestor());} |
| 890 |
if(printCommonAncestorLevel){j.add("commonAncestorLevel", c.commonAncestorLevel());} |
| 891 |
|
| 892 |
if(printRefFileName){j.add("file", c.fname()==null ? "." : c.fname());} |
| 893 |
if(printOriginalName){j.add("seqName", c.name0()==null ? "." : c.name0());} |
| 894 |
if(printTax && SketchObject.taxtree!=null){ |
| 895 |
TaxNode tn=null; |
| 896 |
if(tid>0 && tid<SketchObject.minFakeID){ |
| 897 |
tn=SketchObject.taxtree.getNode(tid); |
| 898 |
} |
| 899 |
|
| 900 |
if(tn!=null){ |
| 901 |
j.add("taxonomy", SketchObject.taxtree.toSemicolon(tn, SketchObject.skipNonCanonical, false)); |
| 902 |
}else{ |
| 903 |
j.add("taxonomy", (Object)null); |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
if(printWKID){j.addLiteral("WKID", 100*c.wkid(), 4);} |
| 908 |
if(printKID){j.addLiteral("KID", 100*c.kid(), 4);} |
| 909 |
|
| 910 |
if(printSSU() && c.ssuIdentity()>0){ |
| 911 |
j.addLiteral(c.ssuType()==18 ? "18S" : "16S", 100*c.ssuIdentity(), 3); |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
if(printAni){j.addLiteral((aminoOrTranslate() ? "AAI" : "ANI"), 100*c.ani(), 3);} |
| 916 |
if(printCompleteness){j.addLiteral("Complt", 100*c.completeness(), 3);} |
| 917 |
if(printContam){j.addLiteral("Contam", 100*c.contamFraction(), 3);} |
| 918 |
if(printContam2){j.addLiteral("Contam2", 100*c.contam2Fraction(), 3);} |
| 919 |
if(printUContam){j.addLiteral("uContam", 100*c.uContamFraction(), 3);} |
| 920 |
if(printScore){j.add("Score", c.score());} |
| 921 |
if(printEValue){j.add("E-Val", Tools.format("%5.2e", c.eValue()));} |
| 922 |
|
| 923 |
if(printDepth){j.add("Depth", c.depth(printActualDepth));} |
| 924 |
if(printDepth2){j.add("Depth2", c.depth2(printActualDepth));} |
| 925 |
if(printVolume){j.add("Volume", c.volume()+0.001);} |
| 926 |
if(printRefHits){j.add("RefHits", c.avgRefHits());} |
| 927 |
|
| 928 |
if(printMatches){j.add("Matches", c.hits());} |
| 929 |
if(printUnique){j.add("Unique", c.uHits());} |
| 930 |
if(printUnique2){j.add("Unique2", c.unique2());} |
| 931 |
if(printUnique3){j.add("Unique3", c.unique3());} |
| 932 |
if(printNoHit){j.add("noHit", c.noHits());} |
| 933 |
if(printLength){j.add("Length", c.maxDivisor());} |
| 934 |
if(printTaxID){j.add("TaxID", tid>=SketchObject.minFakeID ? -1 : tid);} |
| 935 |
if(printImg){j.add("ImgID", c.imgID());} |
| 936 |
if(printGBases){j.add("gBases", c.genomeSizeBases());} |
| 937 |
if(printGKmers){j.add("gKmers", c.genomeSizeKmers());} |
| 938 |
if(printGSize){j.add("gSize", c.genomeSizeEstimate());} |
| 939 |
if(printGSeqs){j.add("gSeqs", c.genomeSequences());} |
| 940 |
if(c.hasGC()){j.addLiteral("GC", c.gc(), 3);} |
| 941 |
|
| 942 |
|
| 943 |
if(printRefDivisor){j.add("rDiv", c.refDivisor());} |
| 944 |
if(printQueryDivisor){j.add("qDiv", c.queryDivisor());} |
| 945 |
if(printRefSize){j.add("rSize", c.refSize());} |
| 946 |
if(printQuerySize){j.add("qSize", c.querySize());} |
| 947 |
if(printContamHits){j.add("cHits", c.contamHits());} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
if(printSSULen){ |
| 952 |
if(c.has18S()){j.add("18SLen", c.b.r18SLen());} |
| 953 |
if(c.has16S()){j.add("16SLen", c.b.r16SLen());} |
| 954 |
} |
| 955 |
if(printSSUSequence){ |
| 956 |
if(c.has18S()){j.add("18SSequence", new String(c.b.r18S()));} |
| 957 |
if(c.has16S()){j.add("16SSequence", new String(c.b.r16S()));} |
| 958 |
} |
| 959 |
|
| 960 |
if(printIntersection){ |
| 961 |
Sketch intersection=Sketch.intersection(c.a, c.b); |
| 962 |
j.add("intersection", intersection.toString()); |
| 963 |
} |
| 964 |
|
| 965 |
return j; |
| 966 |
} |
| 967 |
|
| 968 |
public boolean json(){return format==FORMAT_JSON;} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
public JsonObject toD3(SketchResults sr){ |
| 975 |
if(sr==null || sr.isEmpty()){return new JsonObject("name", "no hits");} |
| 976 |
JsonObject root=new JsonObject("name", "life"); |
| 977 |
root.add("level", TaxTree.LIFE_E); |
| 978 |
if(sr.list!=null){ |
| 979 |
int i=0; |
| 980 |
for(Comparison c : sr.list){ |
| 981 |
ArrayList<JsonObject> tax=toD3List(c); |
| 982 |
addToLevel(root, tax, 0); |
| 983 |
i++; |
| 984 |
if(i>=maxRecords){break;} |
| 985 |
} |
| 986 |
} |
| 987 |
if(D3LevelNodes){ |
| 988 |
root=converToD3ArrayFormat_LevelNode(root); |
| 989 |
}else{ |
| 990 |
root=converToD3ArrayFormat_SingleNodeRoot(root); |
| 991 |
} |
| 992 |
return root; |
| 993 |
} |
| 994 |
|
| 995 |
private JsonObject converToD3ArrayFormat_SingleNodeRoot(JsonObject root){ |
| 996 |
JsonObject children=root.removeJson("children"); |
| 997 |
if(children==null){return root;} |
| 998 |
Object[] array=children.toJmapArray(); |
| 999 |
root=(JsonObject)array[0]; |
| 1000 |
|
| 1001 |
assert(root.getString("name").equalsIgnoreCase("Life")) : root; |
| 1002 |
return converToD3ArrayFormat_SingleNode(root); |
| 1003 |
} |
| 1004 |
|
| 1005 |
private JsonObject converToD3ArrayFormat_SingleNode(JsonObject nameNode){ |
| 1006 |
Object[] levelNodes=nameNode.toJmapArray(); |
| 1007 |
if(levelNodes==null){return nameNode;} |
| 1008 |
nameNode.clearJson(); |
| 1009 |
|
| 1010 |
ArrayList<JsonObject> fixed=new ArrayList<JsonObject>(); |
| 1011 |
for(Object o : levelNodes){ |
| 1012 |
JsonObject levelNode=(JsonObject)o; |
| 1013 |
String level=levelNode.getString("name"); |
| 1014 |
JsonObject children=levelNode.removeJson("children"); |
| 1015 |
if(children!=null){ |
| 1016 |
Object[] childArray=children.toJmapArray(); |
| 1017 |
for(Object o2 : childArray){ |
| 1018 |
JsonObject child=(JsonObject)o2; |
| 1019 |
String name=(String)child.removeObject("name"); |
| 1020 |
child.add("name", level+": "+name); |
| 1021 |
converToD3ArrayFormat_SingleNode(child); |
| 1022 |
fixed.add(child); |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} |
| 1026 |
Object[] children=fixed.toArray(); |
| 1027 |
nameNode.add("children", children); |
| 1028 |
return nameNode; |
| 1029 |
} |
| 1030 |
|
| 1031 |
private JsonObject converToD3ArrayFormat_LevelNode(JsonObject levelNode){ |
| 1032 |
JsonObject children=levelNode.removeJson("children"); |
| 1033 |
if(children==null){return levelNode;} |
| 1034 |
|
| 1035 |
Object[] array=children.toJmapArray(); |
| 1036 |
levelNode.add("children", array); |
| 1037 |
for(Object o : array){ |
| 1038 |
converToD3ArrayFormat_NameNode((JsonObject)o); |
| 1039 |
} |
| 1040 |
return levelNode; |
| 1041 |
} |
| 1042 |
|
| 1043 |
private JsonObject converToD3ArrayFormat_NameNode(JsonObject nameNode){ |
| 1044 |
Object[] array=nameNode.toJmapArray(); |
| 1045 |
if(array==null){return nameNode;} |
| 1046 |
|
| 1047 |
nameNode.clearJson(); |
| 1048 |
nameNode.add("children", array); |
| 1049 |
for(Object o : array){ |
| 1050 |
converToD3ArrayFormat_LevelNode((JsonObject)o); |
| 1051 |
} |
| 1052 |
return nameNode; |
| 1053 |
} |
| 1054 |
|
| 1055 |
void addToLevel(JsonObject levelNode, ArrayList<JsonObject> list, int pos){ |
| 1056 |
JsonObject jo=list.get(pos); |
| 1057 |
int rootLevel=levelNode.getInt("level"); |
| 1058 |
int joLevel=jo.getInt("level"); |
| 1059 |
if(rootLevel==joLevel){ |
| 1060 |
assert(levelNode.getString("name").equalsIgnoreCase(jo.getString("levelname"))) : levelNode+"\n"+jo; |
| 1061 |
addAsChild(levelNode, list, pos); |
| 1062 |
}else{ |
| 1063 |
assert(joLevel<rootLevel) : levelNode+"\n"+jo; |
| 1064 |
assert(false) : levelNode+"\n"+jo; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
void addAsChild(JsonObject levelNode, ArrayList<JsonObject> list, int pos){ |
| 1069 |
JsonObject children=levelNode.getJson("children"); |
| 1070 |
if(children==null){ |
| 1071 |
children=new JsonObject(); |
| 1072 |
levelNode.add("children", children); |
| 1073 |
} |
| 1074 |
JsonObject jo=list.get(pos); |
| 1075 |
String taxName=jo.getString("name"); |
| 1076 |
JsonObject nameNode=children.getJson(taxName); |
| 1077 |
if(nameNode==null){ |
| 1078 |
nameNode=new JsonObject("name", taxName); |
| 1079 |
children.add(taxName, nameNode); |
| 1080 |
} |
| 1081 |
Number size=jo.getNumber("size"); |
| 1082 |
Number oldSize=nameNode.getNumber("size"); |
| 1083 |
if(size!=null && (oldSize==null || oldSize.doubleValue()<size.doubleValue())){ |
| 1084 |
nameNode.add("size", jo.getNumber("size")); |
| 1085 |
nameNode.add("kid", jo.getNumber("kid")); |
| 1086 |
nameNode.add("wkid", jo.getNumber("wkid")); |
| 1087 |
nameNode.add("ani", jo.getNumber("ani")); |
| 1088 |
nameNode.add("hits", jo.getNumber("hits")); |
| 1089 |
nameNode.add("depth", jo.getNumber("depth")); |
| 1090 |
} |
| 1091 |
|
| 1092 |
if(pos<list.size()-1){ |
| 1093 |
jo=list.get(pos+1); |
| 1094 |
String levelName=jo.getString("levelname"); |
| 1095 |
int level=jo.getInt("level"); |
| 1096 |
JsonObject nextLevelNode=nameNode.getJson(levelName); |
| 1097 |
if(nextLevelNode==null){ |
| 1098 |
nextLevelNode=new JsonObject("name", levelName); |
| 1099 |
nextLevelNode.add("level", level); |
| 1100 |
nameNode.add(levelName, nextLevelNode); |
| 1101 |
} |
| 1102 |
addAsChild(nextLevelNode, list, pos+1); |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
int promote(int levelE) { |
| 1107 |
if(levelE<0){return levelE;} |
| 1108 |
while(!TaxTree.isSimple2(levelE) && levelE<TaxTree.LIFE){ |
| 1109 |
levelE++; |
| 1110 |
} |
| 1111 |
return levelE; |
| 1112 |
} |
| 1113 |
|
| 1114 |
public ArrayList<JsonObject> toD3List(Comparison c){ |
| 1115 |
final ArrayList<TaxNode> nodes=toTNList(c.taxID); |
| 1116 |
ArrayList<JsonObject> list=new ArrayList<JsonObject>(nodes.size()); |
| 1117 |
for(TaxNode tn : nodes){ |
| 1118 |
JsonObject jo=new JsonObject("name", tn.name); |
| 1119 |
int levelE=promote(tn.levelExtended); |
| 1120 |
jo.add("level", levelE); |
| 1121 |
jo.add("levelname", TaxTree.levelToStringExtended(levelE)); |
| 1122 |
list.add(jo); |
| 1123 |
} |
| 1124 |
if(list.size()>0){ |
| 1125 |
JsonObject tail=list.get(list.size()-1); |
| 1126 |
tail.add("size", toD3Size(c)); |
| 1127 |
tail.add("kid", c.kid()); |
| 1128 |
tail.add("wkid", c.wkid()); |
| 1129 |
tail.add("ani", c.ani()); |
| 1130 |
tail.add("hits", c.hits()); |
| 1131 |
tail.add("depth", c.depth(printActualDepth)); |
| 1132 |
} |
| 1133 |
return list; |
| 1134 |
} |
| 1135 |
|
| 1136 |
private Number toD3Size(Comparison c){ |
| 1137 |
if(D3sizeMode==D3_ANI_SIZE){ |
| 1138 |
return c.ani(); |
| 1139 |
}else if(D3sizeMode==D3_KID_SIZE){ |
| 1140 |
return c.kid(); |
| 1141 |
}else if(D3sizeMode==D3_WKID_SIZE){ |
| 1142 |
return c.wkid(); |
| 1143 |
}else if(D3sizeMode==D3_HIT_SIZE){ |
| 1144 |
return c.hits(); |
| 1145 |
}else if(D3sizeMode==D3_DEPTH_SIZE){ |
| 1146 |
return c.depth(printActualDepth); |
| 1147 |
} |
| 1148 |
assert(false) : "Invalid D3sizeMode "+D3sizeMode; |
| 1149 |
return c.hits(); |
| 1150 |
} |
| 1151 |
|
| 1152 |
public ArrayList<TaxNode> toTNList(final int tid){ |
| 1153 |
final TaxTree tree=TaxTree.getTree(); |
| 1154 |
|
| 1155 |
final ArrayList<TaxNode> list=new ArrayList<TaxNode>(); |
| 1156 |
int nulls=0; |
| 1157 |
{ |
| 1158 |
TaxNode tn=tree.getNode(tid); |
| 1159 |
if(tn.isRanked() && !tn.cellularOrganisms()){list.add(tn);} |
| 1160 |
while(tn.pid!=tn.id){ |
| 1161 |
tn=tree.getNode(tn.pid); |
| 1162 |
if(tn.isRanked() && !tn.cellularOrganisms()){list.add(tn);} |
| 1163 |
} |
| 1164 |
} |
| 1165 |
Collections.reverse(list); |
| 1166 |
int prevLevelE=TaxTree.LIFE; |
| 1167 |
for(int i=0; i<list.size(); i++){ |
| 1168 |
TaxNode tn=list.get(i); |
| 1169 |
int levelE=promote(tn.levelExtended); |
| 1170 |
|
| 1171 |
if(!TaxTree.isSimple2(levelE) || (i>0 && levelE>=prevLevelE)){ |
| 1172 |
list.set(i, null); |
| 1173 |
nulls++; |
| 1174 |
}else{prevLevelE=levelE;} |
| 1175 |
} |
| 1176 |
if(nulls>0){Tools.condenseStrict(list);} |
| 1177 |
return list; |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
ByteBuilder queryHeader(Sketch sk){ |
| 1185 |
ByteBuilder bb=new ByteBuilder(); |
| 1186 |
if(format>2){return bb;} |
| 1187 |
|
| 1188 |
String color=toColor(sk.taxID); |
| 1189 |
if(color!=null){bb.append(color);} |
| 1190 |
|
| 1191 |
bb.append("\nQuery: ").append(sk.name()==null ? "." : sk.name()); |
| 1192 |
if(dbName!=null){bb.append("\tDB: ").append(dbName);} |
| 1193 |
bb.append("\tSketchLen: ").append(sk.length()); |
| 1194 |
bb.append("\tSeqs: ").append(sk.genomeSequences).append(' '); |
| 1195 |
bb.append("\t"+(aminoOrTranslate() ? "SeqLen" : "Bases")+": ").append(sk.genomeSizeBases); |
| 1196 |
bb.append("\tgSize: ").append(sk.genomeSizeEstimate()); |
| 1197 |
if(sk.baseCounts!=null){bb.append("\tGC: ").append(sk.gc(), 3);} |
| 1198 |
if(sk.probCorrect<1 && sk.probCorrect>0){bb.append("\tQuality: ").append(sk.probCorrect, 4);} |
| 1199 |
if(sk.keyCounts!=null){ |
| 1200 |
double d=Tools.averageDouble(sk.keyCounts); |
| 1201 |
bb.append("\tAvgCount: ").append(d, 3); |
| 1202 |
bb.append("\tDepth: ").append(Tools.observedToActualCoverage(d), 3); |
| 1203 |
} |
| 1204 |
|
| 1205 |
if(sk.imgID>0){bb.append("\tIMG: ").append(sk.imgID);} |
| 1206 |
if(sk.spid>0){bb.append("\tspid: ").append(sk.spid);} |
| 1207 |
if(sk.taxID>0 && sk.taxID<SketchObject.minFakeID){bb.append("\tTaxID: ").append(sk.taxID);} |
| 1208 |
|
| 1209 |
if(printQueryFileName && sk.fname()!=null){bb.append("\tFile: "+sk.fname());} |
| 1210 |
if(printOriginalName && sk.name0()!=null && !sk.name0().equals(sk.name())){bb.append("\tSeqName: "+sk.name0());} |
| 1211 |
|
| 1212 |
if(sk.meta!=null){ |
| 1213 |
for(String st : sk.meta){ |
| 1214 |
bb.append("\t").append(st.replaceFirst(":", ": ")); |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
if(color!=null){bb.append(Colors.RESET);} |
| 1219 |
|
| 1220 |
return bb; |
| 1221 |
} |
| 1222 |
|
| 1223 |
int toColorTid(final int taxID){ |
| 1224 |
if(!printColors || SketchObject.taxtree==null || taxID<=0 || taxID>=SketchObject.minFakeID){return 0;} |
| 1225 |
TaxNode tn=SketchObject.taxtree.getNode(taxID); |
| 1226 |
while(tn!=null && tn.id!=tn.pid && tn.levelExtended<colorLevel){ |
| 1227 |
tn=SketchObject.taxtree.getNode(tn.pid); |
| 1228 |
|
| 1229 |
} |
| 1230 |
return tn==null || tn.levelExtended>=TaxTree.LIFE_E || (tn.levelExtended>colorLevel && tn.levelExtended>TaxTree.PHYLUM_E) ? 0 : tn.id; |
| 1231 |
} |
| 1232 |
|
| 1233 |
String toColor(final int taxID){ |
| 1234 |
if(!printColors || SketchObject.taxtree==null || taxID<=0 || taxID>=SketchObject.minFakeID){return null;} |
| 1235 |
TaxNode tn=SketchObject.taxtree.getNode(taxID); |
| 1236 |
while(tn!=null && tn.id!=tn.pid && tn.levelExtended<colorLevel){ |
| 1237 |
tn=SketchObject.taxtree.getNode(tn.pid); |
| 1238 |
|
| 1239 |
} |
| 1240 |
if(tn==null){ |
| 1241 |
return null; |
| 1242 |
}else{ |
| 1243 |
if(tn.levelExtended>=TaxTree.LIFE_E || (tn.levelExtended>colorLevel && tn.levelExtended>TaxTree.PHYLUM_E)){return Colors.WHITE;} |
| 1244 |
else{ |
| 1245 |
|
| 1246 |
return Colors.colorArray[tn.id%Colors.colorArray.length]; |
| 1247 |
} |
| 1248 |
} |
| 1249 |
} |
| 1250 |
|
| 1251 |
String header(){ |
| 1252 |
if(format==FORMAT_JSON){return null;} |
| 1253 |
final String ani=(aminoOrTranslate() ? "AAI" : "ANI"); |
| 1254 |
if(format==FORMAT_QUERY_REF_ANI || format==FORMAT_CONSTELLATION){ |
| 1255 |
if(reportAniOnly){return "#Query\tRef\t"+ani;} |
| 1256 |
if(format==FORMAT_QUERY_REF_ANI){ |
| 1257 |
return "#Query\tRef\t"+ani+ |
| 1258 |
"\tQSize\tRefSize\tQBases\tRBases"+ |
| 1259 |
(printTaxID ? "\tQTaxID\tRTaxID" : "")+(printKID ? "\tKID" : "")+(printWKID ? "\tWKID" : "")+ |
| 1260 |
(printSSU() ? "\tSSU" : "")+(printCommonAncestorLevel ? "\tCALevel" : ""); |
| 1261 |
} |
| 1262 |
if(format==FORMAT_CONSTELLATION){return "#Query\tRef\tKID\tWKID\t"+ani+"\tCmplt\tQSize\tRefSize\tQBases\tRefBases";} |
| 1263 |
} |
| 1264 |
return columnwiseHeader(); |
| 1265 |
} |
| 1266 |
|
| 1267 |
String columnwiseHeader(){ |
| 1268 |
final String ani=(aminoOrTranslate() ? "AAI" : "ANI"); |
| 1269 |
|
| 1270 |
StringBuilder sb=new StringBuilder(); |
| 1271 |
|
| 1272 |
|
| 1273 |
if(printKID){sb.append("WKID\t");} |
| 1274 |
if(printWKID){sb.append("KID\t");} |
| 1275 |
if(printAni){sb.append(ani+"\t");} |
| 1276 |
if(printSSU()){sb.append("SSU\t");} |
| 1277 |
if(printSSULen){sb.append("SSULen\t");} |
| 1278 |
if(printCompleteness){sb.append("Complt\t");} |
| 1279 |
if(printContam){sb.append("Contam\t");} |
| 1280 |
if(printContam2){sb.append("Contam2\t");} |
| 1281 |
if(printUContam){sb.append("uContam\t");} |
| 1282 |
if(printScore){sb.append("Score\t");} |
| 1283 |
if(printEValue){sb.append("E-Val\t");} |
| 1284 |
|
| 1285 |
if(printDepth){sb.append("Depth\t");} |
| 1286 |
if(printDepth2){sb.append("Depth2\t");} |
| 1287 |
if(printVolume){sb.append("Volume\t");} |
| 1288 |
if(printRefHits){sb.append("RefHits\t");} |
| 1289 |
if(printMatches){sb.append("Matches\t");} |
| 1290 |
if(printUnique){sb.append("Unique\t");} |
| 1291 |
if(printUnique2){sb.append("Unique2\t");} |
| 1292 |
if(printUnique3){sb.append("Unique3\t");} |
| 1293 |
if(printNoHit){sb.append("noHit\t");} |
| 1294 |
if(printLength){sb.append("Length\t");} |
| 1295 |
if(printTaxID){sb.append("TaxID\t");} |
| 1296 |
if(printImg){sb.append("ImgID \t");} |
| 1297 |
if(printGBases){sb.append("gBases\t");} |
| 1298 |
if(printGKmers){sb.append("gKmers\t");} |
| 1299 |
if(printGSize){sb.append("gSize\t");} |
| 1300 |
if(printGSeqs){sb.append("gSeqs\t");} |
| 1301 |
if(printGC){sb.append("GC\t");} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
if(printRefDivisor){sb.append("rDiv\t");} |
| 1306 |
if(printQueryDivisor){sb.append("qDiv\t");} |
| 1307 |
if(printRefSize){sb.append("rSize\t");} |
| 1308 |
if(printQuerySize){sb.append("qSize\t");} |
| 1309 |
if(printContamHits){sb.append("cHits\t");} |
| 1310 |
|
| 1311 |
|
| 1312 |
if(printCommonAncestor){sb.append("CA\t");} |
| 1313 |
if(printCommonAncestorLevel){sb.append("CALevel\t");} |
| 1314 |
if(printTaxName){sb.append("taxName\t");} |
| 1315 |
if(printRefFileName){sb.append("file\t");} |
| 1316 |
if(printOriginalName){sb.append("seqName\t");} |
| 1317 |
if(printTax && SketchObject.taxtree!=null){sb.append("taxonomy\t");} |
| 1318 |
|
| 1319 |
if(sb.length()>1){sb.setLength(sb.length()-1);} |
| 1320 |
|
| 1321 |
return sb.toString(); |
| 1322 |
} |
| 1323 |
|
| 1324 |
void formatComparisonColumnwise(Comparison c, ByteBuilder bb, int prevTid){ |
| 1325 |
final int tid=c.taxID; |
| 1326 |
boolean reset=false; |
| 1327 |
|
| 1328 |
if(printColors){ |
| 1329 |
final int ctid=toColorTid(tid); |
| 1330 |
final int prevCtid=toColorTid(prevTid); |
| 1331 |
|
| 1332 |
final int cnum=ctid%Colors.colorArray.length; |
| 1333 |
final int prevCnum=prevCtid%Colors.colorArray.length; |
| 1334 |
|
| 1335 |
String color=toColor(tid); |
| 1336 |
String underline=(printColors && cnum==prevCnum && ctid!=prevCtid && (ctid>1 && prevCtid>1) ? Colors.UNDERLINE : null); |
| 1337 |
|
| 1338 |
if(color!=null){bb.append(color);} |
| 1339 |
if(underline!=null){bb.append(underline);} |
| 1340 |
reset=(color!=null || underline!=null); |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
} |
| 1346 |
|
| 1347 |
|
| 1348 |
if(printWKID){bb.append(100*c.wkid(), 2).append('%').tab();} |
| 1349 |
if(printKID){bb.append(100*c.kid(), 2).append('%');} |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
if(printAni){bb.tab().append(100*c.ani(), 2).append('%');} |
| 1358 |
if(printSSU()){ |
| 1359 |
float id=100*c.ssuIdentity(); |
| 1360 |
if(id>0){ |
| 1361 |
bb.tab().append(id, 2).append(c.ssuType()==16 ? '%' : '*'); |
| 1362 |
}else{ |
| 1363 |
bb.tab().append('.'); |
| 1364 |
} |
| 1365 |
} |
| 1366 |
if(printSSULen){ |
| 1367 |
bb.tab().append(c.ssuLen()); |
| 1368 |
} |
| 1369 |
if(printCompleteness){bb.tab().append(100*c.completeness(), 2).append('%');} |
| 1370 |
if(printContam){bb.tab().append(100*c.contamFraction(), 2).append('%');} |
| 1371 |
if(printContam2){bb.tab().append(100*c.contam2Fraction(), 2).append('%');} |
| 1372 |
if(printUContam){bb.tab().append(100*c.uContamFraction(), 2).append('%');} |
| 1373 |
if(printScore){bb.tab().append(c.scoreS());} |
| 1374 |
if(printEValue){bb.tab().append(Tools.format("%5.2e", c.eValue()));} |
| 1375 |
|
| 1376 |
if(printDepth){bb.tab().append(c.depthS(printActualDepth));} |
| 1377 |
if(printDepth2){bb.tab().append(c.depth2S(printActualDepth));} |
| 1378 |
if(printVolume){bb.tab().append(c.volumeS());} |
| 1379 |
if(printRefHits){bb.tab().append(c.avgRefHitsS());} |
| 1380 |
|
| 1381 |
if(printMatches){bb.tab().append(c.hits());} |
| 1382 |
if(printUnique){bb.tab().append(c.uHits());} |
| 1383 |
if(printUnique2){bb.tab().append(c.unique2());} |
| 1384 |
if(printUnique3){bb.tab().append(c.unique3());} |
| 1385 |
if(printNoHit){bb.tab().append(c.noHits());} |
| 1386 |
if(printLength){bb.tab().append( c.maxDivisor());} |
| 1387 |
if(printTaxID){bb.tab().append(tid>=SketchObject.minFakeID ? -1 : tid);} |
| 1388 |
if(printImg){bb.tab().append(c.imgID());} |
| 1389 |
if(printGBases){appendKMG(c.genomeSizeBases(), bb);} |
| 1390 |
if(printGKmers){appendKMG(c.genomeSizeKmers(), bb);} |
| 1391 |
if(printGSize){appendKMG(c.genomeSizeEstimate(), bb);} |
| 1392 |
if(printGSeqs){appendKMG(c.genomeSequences(), bb);} |
| 1393 |
if(printGC){bb.tab().append(c.gc(),3);} |
| 1394 |
|
| 1395 |
|
| 1396 |
if(printRefDivisor){bb.tab().append(c.refDivisor());} |
| 1397 |
if(printQueryDivisor){bb.tab().append(c.queryDivisor());} |
| 1398 |
if(printRefSize){bb.tab().append(c.refSize());} |
| 1399 |
if(printQuerySize){bb.tab().append(c.querySize());} |
| 1400 |
if(printContamHits){bb.tab().append(c.contamHits());} |
| 1401 |
|
| 1402 |
|
| 1403 |
if(printCommonAncestor){bb.tab().append(c.commonAncestor());} |
| 1404 |
if(printCommonAncestorLevel){bb.tab().append(c.commonAncestorLevel());} |
| 1405 |
if(printTaxName){bb.tab().append(c.taxName()==null ? "." : c.taxName());} |
| 1406 |
if(printRefFileName){bb.tab().append(c.fname()==null ? "." : c.fname());} |
| 1407 |
if(printOriginalName){bb.tab().append(c.name0()==null ? "." : c.name0());} |
| 1408 |
if(printTax && SketchObject.taxtree!=null){ |
| 1409 |
bb.tab(); |
| 1410 |
TaxNode tn=null; |
| 1411 |
if(tid>0 && tid<SketchObject.minFakeID){ |
| 1412 |
tn=SketchObject.taxtree.getNode(tid); |
| 1413 |
} |
| 1414 |
|
| 1415 |
if(tn!=null){ |
| 1416 |
bb.append(SketchObject.taxtree.toSemicolon(tn, SketchObject.skipNonCanonical, false)); |
| 1417 |
}else{ |
| 1418 |
bb.append('.'); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
if(printTaxName && !printOriginalName && !printRefFileName && c.taxName()==null && c.name0()!=null){bb.tab().append(c.name0());} |
| 1422 |
|
| 1423 |
if(reset){bb.append(Colors.RESET);} |
| 1424 |
|
| 1425 |
bb.append('\n'); |
| 1426 |
|
| 1427 |
if(printIntersection){ |
| 1428 |
Sketch intersection=Sketch.intersection(c.a, c.b); |
| 1429 |
bb.append(intersection.toString()); |
| 1430 |
bb.append('\n'); |
| 1431 |
} |
| 1432 |
|
| 1433 |
} |
| 1434 |
|
| 1435 |
void appendKMG(long value, ByteBuilder bb){ |
| 1436 |
if(gSizeKMG){ |
| 1437 |
bb.tab().append(toKMG(value)); |
| 1438 |
}else{ |
| 1439 |
bb.tab().append(value); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
String toKMG(long value){ |
| 1444 |
if(value<10000000L){return Long.toString(value);} |
| 1445 |
value+=5; |
| 1446 |
if(value<1000000000L){return value/1000L+"K";} |
| 1447 |
if(value<1000000000000L){return value/1000000L+"M";} |
| 1448 |
if(value<1000000000000000L){return value/1000000000L+"G";} |
| 1449 |
return value/1000000000000L+"T"; |
| 1450 |
} |
| 1451 |
|
| 1452 |
void formatComparison3Column(Comparison c, ByteBuilder sb, int prevTid){ |
| 1453 |
Sketch query=c.a; |
| 1454 |
final long sea=Tools.max(1, c.a.genomeSizeEstimate()); |
| 1455 |
final long seb=Tools.max(1, c.b.genomeSizeEstimate()); |
| 1456 |
final long ba=Tools.max(1, c.a.genomeSizeBases); |
| 1457 |
final long bb=Tools.max(1, c.b.genomeSizeBases); |
| 1458 |
final String qName=format==FORMAT_CONSTELLATION ? (useFilePrefixName ? query.filePrefix() : ""+query.sketchID) : useTaxidName ? ""+query.taxID : |
| 1459 |
useImgName ? ""+query.imgID : useTaxName ? query.taxName() : query.name(); |
| 1460 |
final String rName=format==FORMAT_CONSTELLATION ? (useFilePrefixName ? c.b.filePrefix() : ""+c.b.sketchID) : useTaxidName ? ""+c.taxID() : |
| 1461 |
useImgName ? ""+c.imgID() : useTaxName ? c.taxName() : c.name(); |
| 1462 |
final int tid=c.taxID; |
| 1463 |
boolean reset=false; |
| 1464 |
|
| 1465 |
sb.append(qName).append('\t'); |
| 1466 |
if(printColors){ |
| 1467 |
final int ctid=toColorTid(tid); |
| 1468 |
final int prevCtid=toColorTid(prevTid); |
| 1469 |
|
| 1470 |
final int cnum=ctid%Colors.colorArray.length; |
| 1471 |
final int prevCnum=prevCtid%Colors.colorArray.length; |
| 1472 |
|
| 1473 |
String color=toColor(tid); |
| 1474 |
String underline=(printColors && cnum==prevCnum && ctid!=prevCtid && (ctid>1 && prevCtid>1) ? Colors.UNDERLINE : null); |
| 1475 |
|
| 1476 |
if(color!=null){sb.append(color);} |
| 1477 |
if(underline!=null){sb.append(underline);} |
| 1478 |
reset=(color!=null || underline!=null); |
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
float kid=100*c.kid(); |
| 1491 |
float wkid=100*c.wkid(); |
| 1492 |
float ani=100*c.ani(); |
| 1493 |
float complt=100*c.completeness(); |
| 1494 |
float ssu=printSSU() ? 100*c.ssuIdentity() : 0; |
| 1495 |
|
| 1496 |
sb.append(rName).append('\t'); |
| 1497 |
if(reportAniOnly){ |
| 1498 |
sb.append(ani, 3).append('\t'); |
| 1499 |
}else if(format==FORMAT_CONSTELLATION){ |
| 1500 |
sb.append(kid, 3).append('\t'); |
| 1501 |
sb.append(wkid, 3).append('\t'); |
| 1502 |
sb.append(ani, 3).append('\t'); |
| 1503 |
sb.append(complt, 3).append('\t'); |
| 1504 |
sb.append(sea).append('\t'); |
| 1505 |
sb.append(seb).append('\t'); |
| 1506 |
|
| 1507 |
|
| 1508 |
}else{ |
| 1509 |
sb.append(ani, 3).append('\t'); |
| 1510 |
sb.append(sea).append('\t'); |
| 1511 |
sb.append(seb).append('\t'); |
| 1512 |
sb.append(ba).append('\t'); |
| 1513 |
sb.append(bb).append('\t'); |
| 1514 |
if(printTaxID){sb.append(c.a.taxID).append('\t');} |
| 1515 |
if(printTaxID){sb.append(c.b.taxID).append('\t');} |
| 1516 |
if(printKID){sb.append(kid, 3).append('\t');} |
| 1517 |
if(printWKID){sb.append(wkid, 3).append('\t');} |
| 1518 |
if(printSSU()){ |
| 1519 |
if(ssu>0){ |
| 1520 |
sb.append(ssu, 3).append('\t'); |
| 1521 |
}else{ |
| 1522 |
sb.append('.').append('\t'); |
| 1523 |
} |
| 1524 |
} |
| 1525 |
if(printCommonAncestorLevel){sb.append(c.commonAncestorLevel()).append('\t');} |
| 1526 |
} |
| 1527 |
sb.setLength(sb.length()-1); |
| 1528 |
if(reset){sb.append(Colors.RESET);} |
| 1529 |
|
| 1530 |
sb.append('\n'); |
| 1531 |
|
| 1532 |
|
| 1533 |
} |
| 1534 |
|
| 1535 |
void formatComparison(Comparison c, ByteBuilder sb, int prevTaxID){ |
| 1536 |
if(format==FORMAT_MULTICOLUMN){ |
| 1537 |
formatComparisonColumnwise(c, sb, prevTaxID); |
| 1538 |
return; |
| 1539 |
}else if(format==FORMAT_QUERY_REF_ANI || format==FORMAT_CONSTELLATION){ |
| 1540 |
formatComparison3Column(c, sb, prevTaxID); |
| 1541 |
return; |
| 1542 |
} |
| 1543 |
String complt=(printCompleteness ? Tools.format("\tcomplt %.2f%%%%", 100*c.completeness()) : ""); |
| 1544 |
String contam=(printContam ? Tools.format("\tcontam %.2f%%%%", 100*c.contamFraction()) : ""); |
| 1545 |
|
| 1546 |
String score=(printScore ? "\tscore "+c.scoreS() : ""); |
| 1547 |
String depth=(printDepth ? "\tdepth "+c.depthS(printActualDepth) : ""); |
| 1548 |
String depth2=(printDepth2 ? "\tdepth2 "+c.depth2S(printActualDepth) : ""); |
| 1549 |
String volume=(printVolume ? "\tvolume "+c.volumeS() : ""); |
| 1550 |
String ccs=complt+contam+score; |
| 1551 |
|
| 1552 |
if(format==FORMAT_OLD){ |
| 1553 |
sb.append(Tools.format("WKID %.2f%%\tKID %.2f%%"+ccs+"\tmatches %d\tcompared %d", |
| 1554 |
100*c.wkid(), 100*c.kid(), c.hits(), c.minDivisor())+"\ttaxID "+c.taxID()+ |
| 1555 |
(printImg ? "\timgID "+c.imgID() : "")+"\tgKmers "+c.genomeSizeKmers()+"\t"+ |
| 1556 |
(c.taxName()==null ? "." : c.taxName())+ |
| 1557 |
((printOriginalName || (c.taxName()==null && c.name0()!=null)) ? "\t"+(c.name0()==null ? "." : c.name0()) : "")+"\n"); |
| 1558 |
if(printTax && SketchObject.taxtree!=null){ |
| 1559 |
if(c.taxID()>=0 && c.taxID()<SketchObject.minFakeID){ |
| 1560 |
TaxNode tn=SketchObject.taxtree.getNode(c.taxID()); |
| 1561 |
if(tn!=null){ |
| 1562 |
PrintTaxonomy.printTaxonomy(tn, sb, SketchObject.taxtree, TaxTree.DOMAIN, SketchObject.skipNonCanonical); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
sb.append('\n'); |
| 1566 |
} |
| 1567 |
}else{ |
| 1568 |
ArrayList<TaxNode> tnl=new ArrayList<TaxNode>(); |
| 1569 |
if(SketchObject.taxtree!=null && c.taxID()>=0 && c.taxID()<SketchObject.minFakeID){ |
| 1570 |
TaxNode tn=SketchObject.taxtree.getNode(c.taxID()); |
| 1571 |
while(tn!=null && tn.pid!=tn.id && tn.level<=TaxTree.DOMAIN){ |
| 1572 |
tnl.add(tn); |
| 1573 |
tn=SketchObject.taxtree.getNode(tn.pid); |
| 1574 |
} |
| 1575 |
} |
| 1576 |
|
| 1577 |
sb.append(Tools.format("WKID %.2f%%\tKID %.2f%%"+ccs+"\tmatches %d\tcompared %d\t", |
| 1578 |
100*c.wkid(), 100*c.kid(), c.hits(), c.minDivisor())); |
| 1579 |
sb.append("\ttaxID ").append(c.taxID()).append('\t'); |
| 1580 |
if(printImg){sb.append("\timgID ").append(c.imgID()).append('\t');} |
| 1581 |
sb.append(c.taxName()).append('\t'); |
| 1582 |
if(printRefFileName){sb.append(c.fname()).append('\t');} |
| 1583 |
if(printOriginalName || (c.taxName()==null && c.name0()!=null && !printRefFileName)){sb.append(c.name0()).append('\t');} |
| 1584 |
|
| 1585 |
if(printTax){ |
| 1586 |
for(int i=tnl.size()-1; i>=0; i--){ |
| 1587 |
TaxNode tn=tnl.get(i); |
| 1588 |
sb.append(tn.name); |
| 1589 |
if(i>0){sb.append(';');} |
| 1590 |
} |
| 1591 |
} |
| 1592 |
sb.append('\n'); |
| 1593 |
|
| 1594 |
tnl.clear(); |
| 1595 |
} |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
public boolean passesFilter(Sketch sk){ |
| 1603 |
assert(postParsed); |
| 1604 |
if(noFilters){return true;} |
| 1605 |
return passesSSUFilter(sk) && passesSizeFilter(sk) && passesTaxFilter(sk) && passesMetaFilter(sk); |
| 1606 |
} |
| 1607 |
|
| 1608 |
private boolean passesTaxFilter(Sketch sk){ |
| 1609 |
if(taxFilterWhite==null && taxFilterBlack==null){return true;} |
| 1610 |
int id=sk.taxID; |
| 1611 |
if(id>0){ |
| 1612 |
if(banUnclassified && SketchObject.taxtree.isUnclassified(id)){return false;} |
| 1613 |
if(banVirus && SketchObject.taxtree.isVirus(id)){return false;} |
| 1614 |
} |
| 1615 |
String s=sk.name(); |
| 1616 |
return passesTaxFilter(taxFilterWhite, id, s) && passesTaxFilter(taxFilterBlack, id, s); |
| 1617 |
} |
| 1618 |
|
| 1619 |
private boolean passesTaxFilter(TaxFilter filter, int id, String s){ |
| 1620 |
if(filter==null){return true;} |
| 1621 |
if(id>0 && !filter.passesFilter(id)){return false;} |
| 1622 |
|
| 1623 |
if(s!=null && !filter.passesFilterByNameOnly(s)){return false;} |
| 1624 |
return true; |
| 1625 |
} |
| 1626 |
|
| 1627 |
private boolean passesMetaFilter(Sketch sk){ |
| 1628 |
if(requiredMeta==null && bannedMeta==null){return true;} |
| 1629 |
return sk.passesMeta(requiredMeta, bannedMeta, requiredMetaAnd); |
| 1630 |
} |
| 1631 |
|
| 1632 |
private boolean passesSSUFilter(Sketch sk){ |
| 1633 |
return !requireSSU || sk.hasSSU(); |
| 1634 |
} |
| 1635 |
|
| 1636 |
private boolean passesSizeFilter(Sketch sk){ |
| 1637 |
if(minRefSizeEstimate>0 && sk.genomeSizeEstimate()<minRefSizeEstimate){return false;} |
| 1638 |
return sk.genomeSizeBases>=minRefSizeBases; |
| 1639 |
} |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
private int hashVersion=SketchObject.HASH_VERSION; |
| 1648 |
private int k=SketchObject.k; |
| 1649 |
private int k2=SketchObject.k2; |
| 1650 |
boolean amino=SketchObject.amino; |
| 1651 |
boolean translate=SketchObject.translate; |
| 1652 |
boolean sixframes=SketchObject.sixframes; |
| 1653 |
private boolean aminoOrTranslate(){return amino | translate;} |
| 1654 |
|
| 1655 |
boolean noFilters=false; |
| 1656 |
boolean postParsed=false; |
| 1657 |
|
| 1658 |
boolean amino(){return amino;} |
| 1659 |
|
| 1660 |
|
| 1661 |
public int maxRecords=default_maxRecords; |
| 1662 |
public int recordsPerLevel=0; |
| 1663 |
public float minANI=0; |
| 1664 |
public int minBases=0; |
| 1665 |
public float minSizeRatio=0; |
| 1666 |
public float minWKID=default_minWKID; |
| 1667 |
public int format=default_format; |
| 1668 |
|
| 1669 |
|
| 1670 |
public int chunkNum=-1; |
| 1671 |
public int minHits=default_minHits; |
| 1672 |
public int taxLevel=default_taxLevel; |
| 1673 |
public int mode=default_mode; |
| 1674 |
public float samplerate=default_samplerate; |
| 1675 |
public long maxReads=default_maxReads; |
| 1676 |
public int minKeyOccuranceCount=default_minKeyOccuranceCount; |
| 1677 |
public String inputVersion=null; |
| 1678 |
|
| 1679 |
public String dbName=null; |
| 1680 |
|
| 1681 |
boolean hasMetaFilters(){return requiredMeta!=null || bannedMeta!=null;} |
| 1682 |
boolean hasTaxFilters(){return taxFilterWhite!=null || taxFilterBlack!=null || banUnclassified || banVirus;} |
| 1683 |
boolean requireSSU=false; |
| 1684 |
long minRefSizeEstimate=-1; |
| 1685 |
long minRefSizeBases=-1; |
| 1686 |
|
| 1687 |
boolean requiredMetaAnd=true; |
| 1688 |
ArrayList<String> requiredMeta=null; |
| 1689 |
ArrayList<String> bannedMeta=null; |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
public boolean printKID=true; |
| 1696 |
public boolean printWKID=true; |
| 1697 |
public boolean printSSU=true; |
| 1698 |
public boolean printSSULen=false; |
| 1699 |
public boolean printSSU(){return SketchObject.processSSU && printSSU;} |
| 1700 |
public boolean printSSUSequence=default_printSSUSequence; |
| 1701 |
|
| 1702 |
|
| 1703 |
public boolean printTax=default_printTax; |
| 1704 |
public boolean printOriginalName=default_printOriginalName; |
| 1705 |
public boolean printQueryFileName=default_printQueryFileName; |
| 1706 |
public boolean printRefFileName=default_printRefFileName; |
| 1707 |
public boolean printImg=default_printImg; |
| 1708 |
public boolean printAni=default_printAni; |
| 1709 |
public boolean printCompleteness=default_printCompleteness; |
| 1710 |
public boolean printScore=default_printScore; |
| 1711 |
public boolean printEValue=default_printEValue; |
| 1712 |
|
| 1713 |
private boolean trackCounts=default_trackCounts; |
| 1714 |
public boolean printDepth=default_printDepth; |
| 1715 |
public boolean printDepth2=default_printDepth2; |
| 1716 |
public boolean printActualDepth=default_printActualDepth; |
| 1717 |
public boolean printVolume=default_printVolume; |
| 1718 |
public boolean printRefHits=default_printRefHits; |
| 1719 |
|
| 1720 |
public boolean printLength=default_printLength; |
| 1721 |
public boolean printTaxID=default_printTaxID; |
| 1722 |
public boolean printGSize=default_printGSize; |
| 1723 |
public boolean printGC=default_printGC; |
| 1724 |
public boolean gSizeKMG=default_gSizeKMG; |
| 1725 |
public boolean printGKmers=default_printGKmers; |
| 1726 |
public boolean printCommonAncestor=default_printCommonAncestor; |
| 1727 |
public boolean printCommonAncestorLevel=default_printCommonAncestorLevel; |
| 1728 |
public boolean printTaxName=default_printTaxName; |
| 1729 |
public boolean printGSeqs=default_printGSeqs; |
| 1730 |
public boolean printGBases=default_printGBases; |
| 1731 |
|
| 1732 |
public boolean jsonArray=default_jsonArray; |
| 1733 |
public boolean printD3=default_printD3; |
| 1734 |
public boolean D3LevelNodes=false; |
| 1735 |
public int D3sizeMode=D3_HIT_SIZE; |
| 1736 |
public static final int D3_HIT_SIZE=0, D3_ANI_SIZE=1, D3_KID_SIZE=2, D3_WKID_SIZE=3, D3_DEPTH_SIZE=4; |
| 1737 |
|
| 1738 |
public float minEntropy=default_minEntropy; |
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
public float minProb=0.0008f; |
| 1746 |
public byte minQual=0; |
| 1747 |
|
| 1748 |
public boolean printUnique=default_printUnique; |
| 1749 |
public boolean printUnique2=default_printUnique2; |
| 1750 |
public boolean printUnique3=default_printUnique3; |
| 1751 |
public boolean printUContam=default_printUContam; |
| 1752 |
public boolean printNoHit=default_printNoHit; |
| 1753 |
|
| 1754 |
public boolean printColors=default_printColors; |
| 1755 |
public boolean setColors=false; |
| 1756 |
public int colorLevel=default_colorLevel; |
| 1757 |
|
| 1758 |
|
| 1759 |
public boolean printContam=default_printContam; |
| 1760 |
public boolean printContam2=default_printContam2; |
| 1761 |
private int contamLevel=default_contamLevel; |
| 1762 |
|
| 1763 |
|
| 1764 |
public boolean printMatches=default_printMatches; |
| 1765 |
|
| 1766 |
public boolean printRefDivisor=false; |
| 1767 |
public boolean printQueryDivisor=false; |
| 1768 |
public boolean printRefSize=false; |
| 1769 |
public boolean printQuerySize=false; |
| 1770 |
public boolean printContamHits=false; |
| 1771 |
|
| 1772 |
public boolean mergePairs=false; |
| 1773 |
public boolean printIntersection=false; |
| 1774 |
|
| 1775 |
|
| 1776 |
public boolean useTaxidName=false; |
| 1777 |
public boolean useImgName=false; |
| 1778 |
public boolean useTaxName=false; |
| 1779 |
public boolean useFilePrefixName=false; |
| 1780 |
public boolean reportAniOnly=false; |
| 1781 |
|
| 1782 |
public int taxLevelWhite=0; |
| 1783 |
public int taxLevelBlack=0; |
| 1784 |
|
| 1785 |
public String taxFilterWhiteList=null; |
| 1786 |
public String taxFilterBlackList=null; |
| 1787 |
|
| 1788 |
public String taxFilterWhiteString=null; |
| 1789 |
public String taxFilterBlackString=null; |
| 1790 |
|
| 1791 |
public TaxFilter taxFilterWhite=null; |
| 1792 |
public TaxFilter taxFilterBlack=null; |
| 1793 |
|
| 1794 |
public boolean banUnclassified=false; |
| 1795 |
public boolean banVirus=false; |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
public boolean checkValid(){ |
| 1800 |
if(printUnique2 || printUnique3){ |
| 1801 |
assert(contamLevel()>=TaxTree.SUBSPECIES_E); |
| 1802 |
assert(needContamCounts()); |
| 1803 |
assert(SketchObject.makeIndex); |
| 1804 |
assert(SketchObject.taxtree!=null); |
| 1805 |
} |
| 1806 |
if(printContam2){ |
| 1807 |
assert(contamLevel()>=TaxTree.SUBSPECIES_E); |
| 1808 |
assert(needContamCounts()); |
| 1809 |
assert(SketchObject.makeIndex); |
| 1810 |
assert(SketchObject.taxtree!=null); |
| 1811 |
} |
| 1812 |
return true; |
| 1813 |
} |
| 1814 |
|
| 1815 |
public boolean trackCounts() { |
| 1816 |
return trackCounts || printDepth || printDepth2 || printVolume |
| 1817 |
|| comparator!=Comparison.scoreComparator || printD3; |
| 1818 |
} |
| 1819 |
|
| 1820 |
public boolean needContamCounts() { |
| 1821 |
return printContam || printContam2 || printContamHits || printUnique || printUnique2 || printUnique3 || printUContam || printNoHit; |
| 1822 |
} |
| 1823 |
|
| 1824 |
public boolean needIndex(){ |
| 1825 |
return printContam2 || printUnique2 || printUnique3; |
| 1826 |
} |
| 1827 |
|
| 1828 |
public int contamLevel() { |
| 1829 |
return needIndex() ? contamLevel : -1; |
| 1830 |
} |
| 1831 |
|
| 1832 |
public int compare(Comparison a, Comparison b){ |
| 1833 |
return comparator.compare(a, b); |
| 1834 |
} |
| 1835 |
|
| 1836 |
public Comparator<Comparison> comparator=Comparison.scoreComparator; |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
public static final int FORMAT_OLD=0, FORMAT_MULTICOLUMN=2, FORMAT_QUERY_REF_ANI=3, FORMAT_JSON=4, FORMAT_CONSTELLATION=5; |
| 1843 |
public static final boolean default_printD3=false; |
| 1844 |
public static final boolean default_jsonArray=false; |
| 1845 |
|
| 1846 |
public static final int default_maxRecords=20; |
| 1847 |
public static final float default_minWKID=0.0001f; |
| 1848 |
public static final int default_format=FORMAT_MULTICOLUMN; |
| 1849 |
public static final boolean default_printSSUSequence=false; |
| 1850 |
public static final boolean default_printTax=false; |
| 1851 |
public static final boolean default_printOriginalName=false; |
| 1852 |
public static final boolean default_printQueryFileName=true; |
| 1853 |
public static final boolean default_printRefFileName=false; |
| 1854 |
public static final boolean default_printImg=false; |
| 1855 |
public static final boolean default_printAni=true; |
| 1856 |
public static final boolean default_printCompleteness=true; |
| 1857 |
public static final boolean default_printScore=false; |
| 1858 |
public static final boolean default_printEValue=false; |
| 1859 |
|
| 1860 |
public static final boolean default_trackCounts=false; |
| 1861 |
public static final boolean default_printDepth=false; |
| 1862 |
public static final boolean default_printDepth2=false; |
| 1863 |
public static final boolean default_printActualDepth=true; |
| 1864 |
public static final boolean default_printVolume=false; |
| 1865 |
public static final boolean default_printRefHits=false; |
| 1866 |
|
| 1867 |
public static final boolean default_printContam=true; |
| 1868 |
public static final boolean default_printContam2=false; |
| 1869 |
|
| 1870 |
public static final boolean default_printMatches=true; |
| 1871 |
public static final boolean default_printLength=false; |
| 1872 |
public static final boolean default_printTaxID=true; |
| 1873 |
public static final boolean default_printGSize=true; |
| 1874 |
public static final boolean default_printGC=false; |
| 1875 |
public static final boolean default_gSizeKMG=true; |
| 1876 |
public static final boolean default_printGKmers=false; |
| 1877 |
public static final boolean default_printCommonAncestor=false; |
| 1878 |
public static final boolean default_printCommonAncestorLevel=false; |
| 1879 |
public static final boolean default_printTaxName=true; |
| 1880 |
public static final boolean default_printGSeqs=true; |
| 1881 |
public static final boolean default_printGBases=false; |
| 1882 |
|
| 1883 |
public static final float default_minEntropy=0.66f; |
| 1884 |
public static final float default_minEntropy_amino=0.70f; |
| 1885 |
public static final float default_minProb=0.0008f; |
| 1886 |
public static final byte default_minQual=0; |
| 1887 |
|
| 1888 |
public static final boolean default_printUnique=true; |
| 1889 |
public static final boolean default_printUnique2=false; |
| 1890 |
public static final boolean default_printUnique3=false; |
| 1891 |
public static final boolean default_printUContam=false; |
| 1892 |
public static final boolean default_printNoHit=false; |
| 1893 |
|
| 1894 |
public static final boolean default_printColors=true; |
| 1895 |
public static final int default_colorLevel=TaxTree.FAMILY_E; |
| 1896 |
|
| 1897 |
public static final int default_taxLevel=TaxTree.SPECIES; |
| 1898 |
public static final int default_contamLevel=TaxTree.GENUS_E; |
| 1899 |
|
| 1900 |
public static final int default_mode=SketchObject.ONE_SKETCH; |
| 1901 |
|
| 1902 |
public static final int default_minHits=3; |
| 1903 |
public static final float default_samplerate=1; |
| 1904 |
public static final long default_maxReads=-1; |
| 1905 |
public static final int default_minKeyOccuranceCount=1; |
| 1906 |
|
| 1907 |
} |