| 1 |
package tax; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.IOException; |
| 5 |
import java.io.InputStream; |
| 6 |
import java.io.PrintStream; |
| 7 |
import java.net.InetSocketAddress; |
| 8 |
import java.util.ArrayList; |
| 9 |
import java.util.Arrays; |
| 10 |
import java.util.Collections; |
| 11 |
import java.util.Date; |
| 12 |
import java.util.HashMap; |
| 13 |
import java.util.List; |
| 14 |
import java.util.Map.Entry; |
| 15 |
import java.util.concurrent.ConcurrentHashMap; |
| 16 |
import java.util.concurrent.atomic.AtomicInteger; |
| 17 |
import java.util.concurrent.atomic.AtomicLong; |
| 18 |
import java.util.concurrent.atomic.AtomicLongArray; |
| 19 |
|
| 20 |
import com.sun.net.httpserver.HttpExchange; |
| 21 |
import com.sun.net.httpserver.HttpHandler; |
| 22 |
import com.sun.net.httpserver.HttpServer; |
| 23 |
import com.sun.net.httpserver.HttpsServer; |
| 24 |
|
| 25 |
import dna.Data; |
| 26 |
import fileIO.ReadWrite; |
| 27 |
import json.JsonObject; |
| 28 |
import server.PercentEncoding; |
| 29 |
import server.ServerTools; |
| 30 |
import shared.KillSwitch; |
| 31 |
import shared.Parse; |
| 32 |
import shared.Parser; |
| 33 |
import shared.PreParser; |
| 34 |
import shared.Shared; |
| 35 |
import shared.Timer; |
| 36 |
import shared.Tools; |
| 37 |
import sketch.CompareBuffer; |
| 38 |
import sketch.Comparison; |
| 39 |
import sketch.DisplayParams; |
| 40 |
import sketch.Sketch; |
| 41 |
import sketch.SketchMakerMini; |
| 42 |
import sketch.SketchObject; |
| 43 |
import sketch.SketchResults; |
| 44 |
import sketch.SketchSearcher; |
| 45 |
import sketch.SketchTool; |
| 46 |
import sketch.Whitelist; |
| 47 |
import stream.Read; |
| 48 |
import structures.ByteBuilder; |
| 49 |
import structures.IntList; |
| 50 |
import structures.StringNum; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public class TaxServer { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static void main(String[] args) throws Exception { |
| 66 |
Timer t=new Timer(); |
| 67 |
@SuppressWarnings("unused") |
| 68 |
TaxServer ts=new TaxServer(args); |
| 69 |
|
| 70 |
t.stop("Time: "); |
| 71 |
|
| 72 |
System.err.println("Ready!"); |
| 73 |
|
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
public TaxServer(String[] args) throws Exception { |
| 79 |
|
| 80 |
{ |
| 81 |
PreParser pp=new PreParser(args, getClass(), false); |
| 82 |
args=pp.args; |
| 83 |
outstream=pp.outstream; |
| 84 |
} |
| 85 |
|
| 86 |
ReadWrite.USE_UNPIGZ=true; |
| 87 |
TaxFilter.printNodesAdded=false; |
| 88 |
TaxFilter.REQUIRE_PRESENT=false; |
| 89 |
Read.JUNK_MODE=Read.FIX_JUNK; |
| 90 |
SketchObject.compareSelf=true; |
| 91 |
|
| 92 |
int port_=3068; |
| 93 |
String killCode_=null; |
| 94 |
boolean allowRemoteFileAccess_=false; |
| 95 |
boolean allowLocalHost_=false; |
| 96 |
String addressPrefix_="128."; |
| 97 |
long defaultSketchReads=200000; |
| 98 |
boolean https=false; |
| 99 |
|
| 100 |
int serverNum_=0; |
| 101 |
int serverCount_=1; |
| 102 |
|
| 103 |
|
| 104 |
Parser parser=new Parser(); |
| 105 |
|
| 106 |
|
| 107 |
for(int i=0; i<args.length; i++){ |
| 108 |
String arg=args[i]; |
| 109 |
|
| 110 |
|
| 111 |
String[] split=arg.split("="); |
| 112 |
String a=split[0].toLowerCase(); |
| 113 |
String b=split.length>1 ? split[1] : null; |
| 114 |
|
| 115 |
if(a.equals("verbose")){ |
| 116 |
verbose=Parse.parseBoolean(b); |
| 117 |
}else if(a.equals("verbose2")){ |
| 118 |
verbose2=SketchObject.verbose2=Parse.parseBoolean(b); |
| 119 |
}else if(a.equals("html")){ |
| 120 |
useHtml=Parse.parseBoolean(b); |
| 121 |
}else if(a.equals("https")){ |
| 122 |
https=Parse.parseBoolean(b); |
| 123 |
}else if(a.equals("http")){ |
| 124 |
https=!Parse.parseBoolean(b); |
| 125 |
}else if(a.equals("servers") || a.equals("numservers") || a.equals("servercount")){ |
| 126 |
serverCount_=Integer.parseInt(b); |
| 127 |
assert(serverCount_>0) : arg; |
| 128 |
}else if(a.equals("servernum")){ |
| 129 |
serverNum_=Integer.parseInt(b); |
| 130 |
assert(serverNum_>=0) : arg; |
| 131 |
}else if(a.startsWith("slave") && Tools.isDigit(a.charAt(a.length()-1))){ |
| 132 |
int num=Integer.parseInt(a.substring(5)); |
| 133 |
if(slaveAddress==null){slaveAddress=new ArrayList<String>(serverCount_);} |
| 134 |
while(slaveAddress.size()<=num){slaveAddress.add(null);} |
| 135 |
slaveAddress.set(num, b); |
| 136 |
}else if(a.equals("table") || a.equals("gi") || a.equals("gitable")){ |
| 137 |
giTableFile=b; |
| 138 |
}else if(a.equals("tree") || a.equals("taxtree")){ |
| 139 |
taxTreeFile=b; |
| 140 |
}else if(a.equals("accession")){ |
| 141 |
accessionFile=b; |
| 142 |
}else if(a.equals("pattern")){ |
| 143 |
patternFile=b; |
| 144 |
}else if(a.equals("size") || a.equals("sizefile")){ |
| 145 |
sizeFile=b; |
| 146 |
}else if(a.equalsIgnoreCase("img")){ |
| 147 |
imgFile=b; |
| 148 |
}else if(a.equals("domain")){ |
| 149 |
domain=b; |
| 150 |
while(domain!=null && domain.endsWith("/")){domain=domain.substring(0, domain.length()-1);} |
| 151 |
}else if(a.equals("port")){ |
| 152 |
port_=Integer.parseInt(b); |
| 153 |
}else if(a.equals("kill") || a.equals("killcode")){ |
| 154 |
killCode_=b; |
| 155 |
}else if(a.equals("oldcode")){ |
| 156 |
oldKillCode=b; |
| 157 |
}else if(a.equals("oldaddress")){ |
| 158 |
oldAddress=b; |
| 159 |
}else if(a.equals("sketchonly")){ |
| 160 |
sketchOnly=Parse.parseBoolean(b); |
| 161 |
}else if(a.equals("sketchreads")){ |
| 162 |
defaultSketchReads=Parse.parseKMG(b); |
| 163 |
}else if(a.equals("handlerthreads")){ |
| 164 |
handlerThreads=Integer.parseInt(b); |
| 165 |
}else if(a.equals("sketchthreads") || a.equals("sketchcomparethreads")){ |
| 166 |
maxConcurrentSketchCompareThreads=Integer.parseInt(b); |
| 167 |
}else if(a.equals("sketchloadthreads")){ |
| 168 |
maxConcurrentSketchLoadThreads=Integer.parseInt(b); |
| 169 |
}else if(a.equals("hashnames")){ |
| 170 |
hashNames=Parse.parseBoolean(b); |
| 171 |
}else if(a.equals("hashdotformat")){ |
| 172 |
hashDotFormat=Parse.parseBoolean(b); |
| 173 |
}else if(a.equals("printip")){ |
| 174 |
printIP=Parse.parseBoolean(b); |
| 175 |
}else if(a.equals("printheaders")){ |
| 176 |
printHeaders=Parse.parseBoolean(b); |
| 177 |
}else if(a.equals("countqueries")){ |
| 178 |
countQueries=Parse.parseBoolean(b); |
| 179 |
}else if(a.equals("clear") || a.equals("clearmem")){ |
| 180 |
clearMem=Parse.parseBoolean(b); |
| 181 |
}else if(a.equals("dbname")){ |
| 182 |
SketchObject.defaultParams.dbName=b; |
| 183 |
}else if(a.equals("allowremotefileaccess")){ |
| 184 |
allowRemoteFileAccess_=Parse.parseBoolean(b); |
| 185 |
}else if(a.equals("allowlocalhost")){ |
| 186 |
allowLocalHost_=Parse.parseBoolean(b); |
| 187 |
}else if(a.equals("addressprefix")){ |
| 188 |
addressPrefix_=b; |
| 189 |
}else if(a.equals("maxpigzprocesses")){ |
| 190 |
AccessionToTaxid.maxPigzProcesses=Integer.parseInt(b); |
| 191 |
}else if(a.equals("path") || a.equals("treepath") || a.equals("basepath")){ |
| 192 |
basePath=b; |
| 193 |
}else if(a.equalsIgnoreCase("prealloc")){ |
| 194 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 195 |
if(Parse.parseBoolean(b)){ |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
prealloc=0.75f; |
| 200 |
}else{ |
| 201 |
prealloc=0; |
| 202 |
} |
| 203 |
}else{ |
| 204 |
prealloc=Float.parseFloat(b); |
| 205 |
} |
| 206 |
SketchObject.prealloc=prealloc; |
| 207 |
}else if(searcher.parse(arg, a, b, true)){ |
| 208 |
|
| 209 |
}else if(parser.parse(arg, a, b)){ |
| 210 |
|
| 211 |
}else{ |
| 212 |
throw new RuntimeException(arg); |
| 213 |
} |
| 214 |
} |
| 215 |
if("auto".equalsIgnoreCase(imgFile)){imgFile=TaxTree.defaultImgFile();} |
| 216 |
if("auto".equalsIgnoreCase(taxTreeFile)){taxTreeFile=TaxTree.defaultTreeFile();} |
| 217 |
if("auto".equalsIgnoreCase(giTableFile)){giTableFile=TaxTree.defaultTableFile();} |
| 218 |
if("auto".equalsIgnoreCase(accessionFile)){accessionFile=TaxTree.defaultAccessionFile();} |
| 219 |
if("auto".equalsIgnoreCase(patternFile)){patternFile=TaxTree.defaultPatternFile();} |
| 220 |
if("auto".equalsIgnoreCase(sizeFile)){sizeFile=TaxTree.defaultSizeFile();} |
| 221 |
|
| 222 |
serverNum=AccessionToTaxid.serverNum=serverNum_; |
| 223 |
serverCount=AccessionToTaxid.serverCount=serverCount_; |
| 224 |
distributed=AccessionToTaxid.distributed=serverCount>1; |
| 225 |
assert(serverNum<serverCount && serverNum>=0); |
| 226 |
if(distributed && serverNum==0){ |
| 227 |
assert(slaveAddress!=null); |
| 228 |
assert(slaveAddress.size()==serverCount); |
| 229 |
for(int i=1; i<slaveAddress.size(); i++){ |
| 230 |
assert(slaveAddress.get(i)!=null); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
maxConcurrentSketchCompareThreads=Tools.mid(1, maxConcurrentSketchCompareThreads, Shared.threads()); |
| 235 |
maxConcurrentSketchLoadThreads=Tools.mid(1, maxConcurrentSketchLoadThreads, Shared.threads()); |
| 236 |
assert(maxConcurrentSketchCompareThreads>=1); |
| 237 |
assert(maxConcurrentSketchLoadThreads>=1); |
| 238 |
|
| 239 |
if(basePath==null || basePath.trim().length()==0){basePath="";} |
| 240 |
else{ |
| 241 |
basePath=basePath.trim().replace('\\', '/').replaceAll("/+", "/"); |
| 242 |
if(!basePath.endsWith("/")){basePath=basePath+"/";} |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
SketchObject.postParse(); |
| 247 |
|
| 248 |
if(sketchOnly){ |
| 249 |
|
| 250 |
giTableFile=null; |
| 251 |
accessionFile=null; |
| 252 |
imgFile=null; |
| 253 |
patternFile=null; |
| 254 |
} |
| 255 |
|
| 256 |
port=port_; |
| 257 |
killCode=killCode_; |
| 258 |
allowRemoteFileAccess=allowRemoteFileAccess_; |
| 259 |
allowLocalHost=allowLocalHost_; |
| 260 |
addressPrefix=addressPrefix_; |
| 261 |
|
| 262 |
|
| 263 |
USAGE=makeUsagePrefix(); |
| 264 |
rawHtml=(useHtml ? loadRawHtml() : null); |
| 265 |
typeMap=makeTypeMap(); |
| 266 |
commonMap=makeCommonMap(); |
| 267 |
|
| 268 |
|
| 269 |
if(giTableFile!=null){ |
| 270 |
outstream.println("Loading gi table."); |
| 271 |
GiToTaxid.initialize(giTableFile); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
if(taxTreeFile!=null){ |
| 276 |
tree=TaxTree.loadTaxTree(taxTreeFile, outstream, hashNames, hashDotFormat); |
| 277 |
if(hashNames){tree.hashChildren();} |
| 278 |
assert(tree.nameMap!=null || sketchOnly); |
| 279 |
}else{ |
| 280 |
tree=null; |
| 281 |
throw new RuntimeException("No tree specified."); |
| 282 |
} |
| 283 |
|
| 284 |
SketchObject.taxtree=tree; |
| 285 |
|
| 286 |
if(sizeFile!=null){ |
| 287 |
Timer t=new Timer(); |
| 288 |
outstream.println("Loading size file."); |
| 289 |
tree.loadSizeFile(sizeFile); |
| 290 |
t.stopAndPrint(); |
| 291 |
} |
| 292 |
|
| 293 |
if(imgFile!=null){ |
| 294 |
TaxTree.loadIMG(imgFile, false, outstream); |
| 295 |
} |
| 296 |
|
| 297 |
if(patternFile!=null){ |
| 298 |
Timer t=new Timer(); |
| 299 |
AnalyzeAccession.loadCodeMap(patternFile); |
| 300 |
outstream.println("Loading pattern table."); |
| 301 |
t.stopAndPrint(); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
if(accessionFile!=null){ |
| 306 |
Timer t=new Timer(); |
| 307 |
AccessionToTaxid.tree=tree; |
| 308 |
AccessionToTaxid.prealloc=prealloc; |
| 309 |
outstream.println("Loading accession table."); |
| 310 |
AccessionToTaxid.load(accessionFile); |
| 311 |
t.stopAndPrint(); |
| 312 |
|
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
hasSketches=searcher.refFileCount()>0; |
| 319 |
if(hasSketches){ |
| 320 |
outstream.println("Loading sketches."); |
| 321 |
Timer t=new Timer(); |
| 322 |
searcher.loadReferences(SketchObject.PER_TAXA, SketchObject.defaultParams); |
| 323 |
t.stopAndPrint(); |
| 324 |
|
| 325 |
} |
| 326 |
|
| 327 |
SketchObject.allowMultithreadedFastq=(maxConcurrentSketchLoadThreads>1); |
| 328 |
SketchObject.defaultParams.maxReads=defaultSketchReads; |
| 329 |
ReadWrite.USE_UNPIGZ=false; |
| 330 |
|
| 331 |
|
| 332 |
if(clearMem){ |
| 333 |
System.err.println("Clearing memory."); |
| 334 |
System.gc(); |
| 335 |
Shared.printMemory(); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
if(oldKillCode!=null && oldAddress!=null){ |
| 340 |
outstream.println("Killing old instance."); |
| 341 |
killOldInstance(); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
httpServer=initializeServer(1000, 8, https); |
| 346 |
assert(httpServer!=null); |
| 347 |
|
| 348 |
|
| 349 |
if(!sketchOnly){ |
| 350 |
httpServer.createContext("/", new TaxHandler(false)); |
| 351 |
httpServer.createContext("/tax", new TaxHandler(false)); |
| 352 |
httpServer.createContext("/stax", new TaxHandler(true)); |
| 353 |
httpServer.createContext("/simpletax", new TaxHandler(true)); |
| 354 |
}else{ |
| 355 |
httpServer.createContext("/", new SketchHandler()); |
| 356 |
} |
| 357 |
httpServer.createContext("/sketch", new SketchHandler()); |
| 358 |
if(killCode!=null){ |
| 359 |
httpServer.createContext("/kill", new KillHandler()); |
| 360 |
} |
| 361 |
|
| 362 |
httpServer.createContext("/help", new HelpHandler()); |
| 363 |
httpServer.createContext("/usage", new HelpHandler()); |
| 364 |
httpServer.createContext("/stats", new StatsHandler()); |
| 365 |
httpServer.createContext("/favicon.ico", new IconHandler()); |
| 366 |
|
| 367 |
handlerThreads=handlerThreads>0 ? handlerThreads : Tools.max(2, Shared.threads()); |
| 368 |
httpServer.setExecutor(java.util.concurrent.Executors.newFixedThreadPool(handlerThreads)); |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
httpServer.start(); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
private void killOldInstance(){ |
| 378 |
StringNum result=null; |
| 379 |
try { |
| 380 |
result=ServerTools.sendAndReceive(oldKillCode.getBytes(), oldAddress); |
| 381 |
} catch (Exception e) { |
| 382 |
|
| 383 |
if(e!=null){e.printStackTrace();} |
| 384 |
System.err.println("\nException suppressed; continuing.\n"); |
| 385 |
return; |
| 386 |
} |
| 387 |
if(result==null || result.s==null || !"Success.".equals(result.s)){ |
| 388 |
|
| 389 |
System.err.println("Bad kill result: "+result+"\nContinuing.\n"); |
| 390 |
} |
| 391 |
ServerTools.pause(1000); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
private HttpServer initializeServer(int millis0, int iterations, boolean https){ |
| 396 |
HttpServer server=null; |
| 397 |
InetSocketAddress isa=new InetSocketAddress(port); |
| 398 |
Exception ee=null; |
| 399 |
for(int i=0, millis=millis0; i<iterations && server==null; i++){ |
| 400 |
try { |
| 401 |
if(https){ |
| 402 |
server=HttpsServer.create(isa, 0); |
| 403 |
}else{ |
| 404 |
server=HttpServer.create(isa, 0); |
| 405 |
} |
| 406 |
} catch (java.net.BindException e) { |
| 407 |
System.err.println(e); |
| 408 |
System.err.println("\nWaiting "+millis+" ms"); |
| 409 |
ee=e; |
| 410 |
ServerTools.pause(millis); |
| 411 |
millis=millis*2; |
| 412 |
} catch (IOException e) { |
| 413 |
System.err.println(e); |
| 414 |
System.err.println("\nWaiting "+millis+" ms"); |
| 415 |
ee=e; |
| 416 |
ServerTools.pause(millis); |
| 417 |
millis=millis*2; |
| 418 |
} |
| 419 |
} |
| 420 |
if(server==null){throw new RuntimeException(ee);} |
| 421 |
return server; |
| 422 |
} |
| 423 |
|
| 424 |
public void returnUsage(long startTime, HttpExchange t){ |
| 425 |
if(useHtml){ |
| 426 |
returnUsageHtml(startTime, t); |
| 427 |
return; |
| 428 |
} |
| 429 |
if(logUsage){System.err.println("usage");} |
| 430 |
|
| 431 |
bytesOut.addAndGet(USAGE.length()); |
| 432 |
ServerTools.reply(USAGE, "text/plain", t, verbose2, 200, true); |
| 433 |
final long stopTime=System.nanoTime(); |
| 434 |
final long elapsed=stopTime-startTime; |
| 435 |
timeMeasurementsUsage.incrementAndGet(); |
| 436 |
elapsedTimeUsage.addAndGet(elapsed); |
| 437 |
lastTimeUsage.set(elapsed); |
| 438 |
} |
| 439 |
|
| 440 |
public void returnUsageHtml(long startTime, HttpExchange t){ |
| 441 |
if(logUsage){System.err.println("usage");} |
| 442 |
String s=makeUsageHtml(); |
| 443 |
bytesOut.addAndGet(s.length()); |
| 444 |
ServerTools.reply(s, "html", t, verbose2, 200, true); |
| 445 |
final long stopTime=System.nanoTime(); |
| 446 |
final long elapsed=stopTime-startTime; |
| 447 |
timeMeasurementsUsage.incrementAndGet(); |
| 448 |
elapsedTimeUsage.addAndGet(elapsed); |
| 449 |
lastTimeUsage.set(elapsed); |
| 450 |
} |
| 451 |
|
| 452 |
public void returnStats(long startTime, HttpExchange t){ |
| 453 |
if(logUsage){System.err.println("stats");} |
| 454 |
String stats=makeStats(); |
| 455 |
bytesOut.addAndGet(stats.length()); |
| 456 |
ServerTools.reply(stats, "text/plain", t, verbose2, 200, true); |
| 457 |
final long stopTime=System.nanoTime(); |
| 458 |
final long elapsed=stopTime-startTime; |
| 459 |
timeMeasurementsUsage.incrementAndGet(); |
| 460 |
elapsedTimeUsage.addAndGet(elapsed); |
| 461 |
lastTimeUsage.set(elapsed); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
class IconHandler implements HttpHandler { |
| 470 |
|
| 471 |
@Override |
| 472 |
public void handle(HttpExchange t) throws IOException { |
| 473 |
if(verbose2){System.err.println("Icon handler");} |
| 474 |
iconQueries.incrementAndGet(); |
| 475 |
ServerTools.reply(favIcon, "image/x-icon", t, verbose2, 200, true); |
| 476 |
} |
| 477 |
|
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
class HelpHandler implements HttpHandler { |
| 484 |
|
| 485 |
@Override |
| 486 |
public void handle(HttpExchange t) throws IOException { |
| 487 |
if(verbose2){System.err.println("Help handler");} |
| 488 |
final long startTime=System.nanoTime(); |
| 489 |
returnUsage(startTime, t); |
| 490 |
} |
| 491 |
|
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
class StatsHandler implements HttpHandler { |
| 498 |
|
| 499 |
@Override |
| 500 |
public void handle(HttpExchange t) throws IOException { |
| 501 |
if(verbose2){System.err.println("Http handler");} |
| 502 |
final long startTime=System.nanoTime(); |
| 503 |
returnStats(startTime, t); |
| 504 |
} |
| 505 |
|
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
class KillHandler implements HttpHandler { |
| 512 |
|
| 513 |
@Override |
| 514 |
public void handle(HttpExchange t) throws IOException { |
| 515 |
if(verbose2){System.err.println("Kill handler");} |
| 516 |
|
| 517 |
|
| 518 |
String rparam=getRParam(t, false); |
| 519 |
InetSocketAddress remote=t.getRemoteAddress(); |
| 520 |
|
| 521 |
if(testCode(t, rparam)){ |
| 522 |
ServerTools.reply("Success.", "text/plain", t, verbose2, 200, true); |
| 523 |
System.err.println("Killed by remote address "+remote); |
| 524 |
|
| 525 |
KillSwitch.killSilent(); |
| 526 |
} |
| 527 |
|
| 528 |
if(verbose){System.err.println("Bad kill from address "+remote);} |
| 529 |
ServerTools.reply(BAD_CODE, "text/plain", t, verbose2, 403, true); |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
private boolean testCode(HttpExchange t, String rparam){ |
| 534 |
String[] params = rparam.split("/"); |
| 535 |
if(verbose2){System.err.println(Arrays.toString(params));} |
| 536 |
|
| 537 |
if(killCode!=null){ |
| 538 |
if(params.length>1){ |
| 539 |
return (params[1].equals(killCode)); |
| 540 |
}else{ |
| 541 |
try { |
| 542 |
String code=ServerTools.receive(t); |
| 543 |
return (code!=null && code.equals(killCode)); |
| 544 |
} catch (Exception e) { |
| 545 |
|
| 546 |
e.printStackTrace(); |
| 547 |
} |
| 548 |
} |
| 549 |
} |
| 550 |
return false; |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
class SketchHandler implements HttpHandler { |
| 558 |
|
| 559 |
@Override |
| 560 |
public void handle(HttpExchange t) throws IOException { |
| 561 |
if(verbose2){outstream.println("Got a request.");} |
| 562 |
SketchInstance si=new SketchInstance(t); |
| 563 |
if(verbose2){outstream.println("Made si.");} |
| 564 |
si.handleInner(); |
| 565 |
if(verbose2){outstream.println("Done.");} |
| 566 |
} |
| 567 |
|
| 568 |
private ArrayList<Sketch> loadSketchesFromBody(String body){ |
| 569 |
|
| 570 |
ArrayList<Sketch> sketches=null; |
| 571 |
|
| 572 |
if(body!=null && body.length()>0){ |
| 573 |
sketches=searcher.loadSketchesFromString(body); |
| 574 |
if(Whitelist.exists()){ |
| 575 |
for(Sketch sk : sketches){ |
| 576 |
Whitelist.apply(sk); |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
return sketches; |
| 581 |
} |
| 582 |
|
| 583 |
private ArrayList<Sketch> loadSketchesFromFile(String fname, DisplayParams params){ |
| 584 |
|
| 585 |
ArrayList<Sketch> sketches=null; |
| 586 |
|
| 587 |
SketchTool tool=searcher.tool; |
| 588 |
if(tool.minKeyOccuranceCount!=params.minKeyOccuranceCount || params.trackCounts()){ |
| 589 |
tool=new SketchTool(SketchObject.targetSketchSize, params); |
| 590 |
} |
| 591 |
|
| 592 |
if(verbose2){System.err.println("Loading sketches from file "+fname);} |
| 593 |
sketches=tool.loadSketchesFromFile(fname, (SketchMakerMini)null, maxConcurrentSketchLoadThreads, params.maxReads, params.mode, params, true); |
| 594 |
if(verbose2){System.err.println("Loaded "+(sketches==null ? "null" : sketches.size())+" sketches from file "+fname);} |
| 595 |
return sketches; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
private class SketchInstance { |
| 600 |
|
| 601 |
SketchInstance(HttpExchange t_){ |
| 602 |
t=t_; |
| 603 |
instanceStartTime=System.nanoTime(); |
| 604 |
} |
| 605 |
|
| 606 |
void handleInner(){ |
| 607 |
|
| 608 |
if(!hasSketches){ |
| 609 |
if(verbose2){System.err.println("No sketches.");} |
| 610 |
ServerTools.reply("\nERROR: This server has no sketches loaded.\n" |
| 611 |
+ "Please download the latest BBTools version to use SendSketch.\n", "text/plain", t, verbose2, 400, true); |
| 612 |
return; |
| 613 |
} |
| 614 |
|
| 615 |
String rparam=parseRparamSketch(t); |
| 616 |
if(verbose2){System.err.println("Parsed rparam.");} |
| 617 |
if(rparam==null){ |
| 618 |
returnUsage(instanceStartTime, t); |
| 619 |
return; |
| 620 |
} |
| 621 |
final boolean internal=incrementQueries(t, fileMode, refMode, false, false, false, false, false, false, false, false, -1); |
| 622 |
if(verbose2){System.err.println("Incremented queries rparam.");} |
| 623 |
|
| 624 |
if(verbose2){System.err.println(rparam);} |
| 625 |
if(verbose2){System.err.println("fileMode="+fileMode+", refMode="+refMode);} |
| 626 |
|
| 627 |
if(fileMode && (!internal || !allowRemoteFileAccess)){ |
| 628 |
if(verbose){System.err.println("Illegal file query from "+ServerTools.getClientAddress(t));} |
| 629 |
malformedQueries.incrementAndGet(); |
| 630 |
|
| 631 |
|
| 632 |
ServerTools.reply("\nERROR: This server does not allow remote file access. " |
| 633 |
+ "You may only use the 'local' flag from within the local intranet, for files on the server's filesystem.\n", "text/plain", t, verbose2, 400, true); |
| 634 |
|
| 635 |
return; |
| 636 |
} |
| 637 |
|
| 638 |
String body=getBody(t); |
| 639 |
if(verbose2){System.err.println("Got body.");} |
| 640 |
|
| 641 |
if(body!=null){bytesIn.addAndGet(body.length());} |
| 642 |
|
| 643 |
if(verbose2){System.err.println("Found body: "+body);} |
| 644 |
if(body!=null && body.length()>0){ |
| 645 |
if((fileMode || refMode) && !body.startsWith("##")){ |
| 646 |
body="##"+body; |
| 647 |
} |
| 648 |
try { |
| 649 |
params=params.parseDoubleHeader(body); |
| 650 |
if(verbose2){System.err.println("Passed parse params.");} |
| 651 |
|
| 652 |
} catch (Throwable e) { |
| 653 |
String s=Tools.toString(e); |
| 654 |
ServerTools.reply("\nERROR: \n"+ s, |
| 655 |
"text/plain", t, verbose2, 400, true); |
| 656 |
return; |
| 657 |
} |
| 658 |
if(!params.compatible()){ |
| 659 |
ServerTools.reply("\nERROR: The sketch is not compatible with this server.\n" |
| 660 |
+ "Server settings: k="+SketchObject.k+(SketchObject.k2>0 ? ","+SketchObject.k2 : "") |
| 661 |
+" amino="+SketchObject.amino+" hash_version="+SketchObject.HASH_VERSION+"\n" |
| 662 |
+ "You may need to download a newer version of BBTools; this server is running version "+Shared.BBTOOLS_VERSION_STRING, |
| 663 |
"text/plain", t, verbose2, 400, true); |
| 664 |
return; |
| 665 |
} |
| 666 |
} |
| 667 |
if(params.trackCounts()){ |
| 668 |
depthQueries.incrementAndGet(); |
| 669 |
} |
| 670 |
|
| 671 |
if(verbose2){System.err.println("Parsed params: "+params.toString());} |
| 672 |
|
| 673 |
|
| 674 |
ArrayList<Sketch> sketches; |
| 675 |
|
| 676 |
if(fileMode){ |
| 677 |
assert(internal && allowRemoteFileAccess); |
| 678 |
if(!allowRemoteFileAccess) {throw new RuntimeException("Bad access to "+rparam);} |
| 679 |
File f=new File(rparam); |
| 680 |
if(!f.exists() && !rparam.startsWith("/")){ |
| 681 |
String temp="/"+rparam; |
| 682 |
f=new File(temp); |
| 683 |
if(f.exists()){rparam=temp;} |
| 684 |
} |
| 685 |
if(!f.exists() || !f.canRead()) { |
| 686 |
ServerTools.reply("\nERROR: This file cannot be read.\n", "text/plain", t, verbose2, 400, true); |
| 687 |
return; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
sketches=loadSketchesFromFile(rparam, params); |
| 697 |
}else if(refMode){ |
| 698 |
String[] split=rparam.split(","); |
| 699 |
sketches=new ArrayList<Sketch>(split.length); |
| 700 |
for(String s : split){ |
| 701 |
Sketch sk=findRefSketch(s); |
| 702 |
if(sk!=null){sketches.add(sk);} |
| 703 |
} |
| 704 |
}else{ |
| 705 |
sketches=loadSketchesFromBody(body); |
| 706 |
} |
| 707 |
if(verbose2){System.err.println("Loaded "+sketches.size()+" sketches.");} |
| 708 |
|
| 709 |
final int numSketches=sketches==null ? 0 : sketches.size(); |
| 710 |
if(params.chunkNum<0){ |
| 711 |
if(numSketches<2){ |
| 712 |
unknownChunkSingle.incrementAndGet(); |
| 713 |
}else{ |
| 714 |
unknownChunkMulti.incrementAndGet(); |
| 715 |
} |
| 716 |
}else if(params.chunkNum==0){ |
| 717 |
if(numSketches<2){ |
| 718 |
firstChunkSingle.incrementAndGet(); |
| 719 |
}else{ |
| 720 |
firstChunkMulti.incrementAndGet(); |
| 721 |
} |
| 722 |
}else{ |
| 723 |
if(numSketches<2){ |
| 724 |
nthChunkSingle.incrementAndGet(); |
| 725 |
}else{ |
| 726 |
nthChunkMulti.incrementAndGet(); |
| 727 |
} |
| 728 |
} |
| 729 |
bulkCount.addAndGet(numSketches); |
| 730 |
|
| 731 |
if(params.inputVersion==null){params.inputVersion="unknown";} |
| 732 |
synchronized(versionMap){ |
| 733 |
StringNum sn=versionMap.get(params.inputVersion); |
| 734 |
if(sn==null){versionMap.put(params.inputVersion, new StringNum(params.inputVersion, 1));} |
| 735 |
else{sn.increment();} |
| 736 |
} |
| 737 |
|
| 738 |
String response=null; |
| 739 |
if(sketches==null || sketches.isEmpty()){ |
| 740 |
malformedQueries.incrementAndGet(); |
| 741 |
response="Error."; |
| 742 |
if(verbose){ |
| 743 |
StringBuilder sb=new StringBuilder(); |
| 744 |
sb.append("Malformed query from ").append(ServerTools.getClientAddress(t)).append(". body:"); |
| 745 |
if(body==null){ |
| 746 |
sb.append(" null"); |
| 747 |
}else{ |
| 748 |
String[] split = body.split("\n"); |
| 749 |
sb.append(" ").append(split.length).append(" lines total, displaying ").append(Tools.min(3, split.length)).append('.'); |
| 750 |
for(int i=0; i<3 && i<split.length; i++){ |
| 751 |
String s=split[i]; |
| 752 |
int len=s.length(); |
| 753 |
if(s.length()>1000){s=s.substring(0, 1000)+" [truncated, "+len+" total]";} |
| 754 |
sb.append('\n'); |
| 755 |
sb.append(s); |
| 756 |
} |
| 757 |
} |
| 758 |
System.err.println(sb); |
| 759 |
} |
| 760 |
}else{ |
| 761 |
if(verbose2){ |
| 762 |
System.err.println("Received "+sketches.get(0).name()+", size "+sketches.get(0).keys.length); |
| 763 |
System.err.println("params: "+params); |
| 764 |
System.err.println("postparsed: "+params.postParsed()); |
| 765 |
System.err.println("taxwhitelist: "+params.taxFilterWhite); |
| 766 |
} |
| 767 |
response=compare(sketches, params); |
| 768 |
|
| 769 |
if(verbose2){System.err.println("Result: '"+response+"'");} |
| 770 |
} |
| 771 |
|
| 772 |
bytesOut.addAndGet(response.length()); |
| 773 |
ServerTools.reply(response, "text/plain", t, verbose2, 200, true); |
| 774 |
|
| 775 |
final long stopTime=System.nanoTime(); |
| 776 |
final long elapsed=stopTime-instanceStartTime; |
| 777 |
if(fileMode){ |
| 778 |
timeMeasurementsLocal.incrementAndGet(); |
| 779 |
elapsedTimeLocal.addAndGet(elapsed); |
| 780 |
lastTimeLocal.set(elapsed); |
| 781 |
}else if(refMode){ |
| 782 |
timeMeasurementsReference.incrementAndGet(); |
| 783 |
elapsedTimeReference.addAndGet(elapsed); |
| 784 |
lastTimeReference.set(elapsed); |
| 785 |
}else{ |
| 786 |
timeMeasurementsRemote.incrementAndGet(); |
| 787 |
elapsedTimeRemote.addAndGet(elapsed); |
| 788 |
lastTimeRemote.set(elapsed); |
| 789 |
|
| 790 |
queryCounts.incrementAndGet(Tools.min(numSketches, queryCounts.length()-1)); |
| 791 |
timesByCount.addAndGet(Tools.min(numSketches, queryCounts.length()-1), elapsed); |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
private String parseRparamSketch(HttpExchange t){ |
| 796 |
|
| 797 |
String rparam=getRParam(t, false); |
| 798 |
if(rparam!=null){bytesIn.addAndGet(rparam.length());} |
| 799 |
|
| 800 |
if(rparam.length()<1 || rparam.equalsIgnoreCase("help") || rparam.equalsIgnoreCase("usage") || rparam.equalsIgnoreCase("help/") || rparam.equalsIgnoreCase("usage/")){ |
| 801 |
return null; |
| 802 |
} |
| 803 |
|
| 804 |
if(rparam.startsWith("sketch/")){rparam=rparam.substring(7);} |
| 805 |
else if(rparam.equals("sketch")){rparam="";} |
| 806 |
while(rparam.startsWith("/")){rparam=rparam.substring(1);} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
if(rparam.length()<2){ |
| 811 |
params=SketchObject.defaultParams; |
| 812 |
}else{ |
| 813 |
params=SketchObject.defaultParams.clone(); |
| 814 |
String[] args=rparam.split("/"); |
| 815 |
int trimmed=0; |
| 816 |
for(int i=0; i<args.length; i++){ |
| 817 |
String arg=args[i]; |
| 818 |
if(arg.length()>0){ |
| 819 |
String[] split=arg.split("="); |
| 820 |
String a=split[0].toLowerCase(); |
| 821 |
String b=split.length>1 ? split[1] : null; |
| 822 |
|
| 823 |
if(a.equals("file")){ |
| 824 |
fileMode=true; |
| 825 |
trimmed+=5; |
| 826 |
break; |
| 827 |
}else if(a.equals("ref") || a.equals("taxid") || a.equals("tid")){ |
| 828 |
refMode=true; |
| 829 |
trimmed+=4; |
| 830 |
break; |
| 831 |
}else if(params.parse(arg, a, b)){ |
| 832 |
trimmed+=arg.length()+1; |
| 833 |
}else{ |
| 834 |
assert(false) : "Bad argument:'"+arg+"'"+"\n"+Arrays.toString(args)+"\n"+rparam; |
| 835 |
} |
| 836 |
} |
| 837 |
} |
| 838 |
params.postParse(true, true); |
| 839 |
|
| 840 |
if(trimmed>0){ |
| 841 |
rparam=rparam.substring(Tools.min(trimmed, rparam.length())); |
| 842 |
} |
| 843 |
|
| 844 |
} |
| 845 |
|
| 846 |
if(verbose2){ |
| 847 |
System.err.println(rparam); |
| 848 |
System.err.println("rparam.startsWith(\"file/\"):"+rparam.startsWith("file/")); |
| 849 |
} |
| 850 |
|
| 851 |
return rparam; |
| 852 |
} |
| 853 |
|
| 854 |
private final HttpExchange t; |
| 855 |
private DisplayParams params; |
| 856 |
private final long instanceStartTime; |
| 857 |
private boolean fileMode=false; |
| 858 |
private boolean refMode=false; |
| 859 |
} |
| 860 |
|
| 861 |
} |
| 862 |
|
| 863 |
private Sketch findRefSketch(String s){ |
| 864 |
assert(s!=null); |
| 865 |
if(s==null || s.length()<1){return null;} |
| 866 |
int tid=-1; |
| 867 |
if(Tools.isDigit(s.charAt(0))){tid=Integer.parseInt(s);} |
| 868 |
else{ |
| 869 |
TaxNode tn=getTaxNodeByName(s); |
| 870 |
tid=tn==null ? -1 : tn.id; |
| 871 |
} |
| 872 |
Sketch sk=tid<0 ? null : searcher.findReferenceSketch(tid); |
| 873 |
if(sk!=null){sk=(Sketch)sk.clone();} |
| 874 |
return sk; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
class TaxHandler implements HttpHandler { |
| 881 |
|
| 882 |
public TaxHandler(boolean skipNonCanonical_){ |
| 883 |
skipNonCanonical=skipNonCanonical_; |
| 884 |
} |
| 885 |
|
| 886 |
@Override |
| 887 |
public void handle(HttpExchange t) throws IOException { |
| 888 |
if(verbose2){System.err.println("Tax handler");} |
| 889 |
final long startTime=System.nanoTime(); |
| 890 |
|
| 891 |
if(sketchOnly){ |
| 892 |
ServerTools.reply("\nERROR: This server is tunning in sketch mode and should not be used for taxonomic lookups.\n" |
| 893 |
+ "The taxonomy server is at "+Shared.taxServer()+"\n", "text/plain", t, verbose2, 400, true); |
| 894 |
return; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
String rparam=getRParam(t, true); |
| 899 |
|
| 900 |
|
| 901 |
boolean simple=skipNonCanonical; |
| 902 |
|
| 903 |
{ |
| 904 |
if(rparam.startsWith("simpletax/")){rparam=rparam.substring(7); simple=true;} |
| 905 |
else if(rparam.startsWith("stax/")){rparam=rparam.substring(5); simple=true;} |
| 906 |
else if(rparam.startsWith("tax/")){rparam=rparam.substring(4);} |
| 907 |
else if(rparam.equals("simpletax") || rparam.equals("stax")){rparam=""; simple=true;} |
| 908 |
else if(rparam.equals("tax")){rparam="";} |
| 909 |
} |
| 910 |
while(rparam.startsWith("/")){rparam=rparam.substring(1);} |
| 911 |
if(rparam.length()<1 || rparam.equalsIgnoreCase("help") || rparam.equalsIgnoreCase("usage")){ |
| 912 |
returnUsage(startTime, t); |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
String[] params = rparam.split("/"); |
| 917 |
if(verbose2){System.err.println(Arrays.toString(params));} |
| 918 |
|
| 919 |
final String response=toResponse(simple, params, t); |
| 920 |
final String type=response.startsWith("{") ? "application/json" : "text/plain"; |
| 921 |
|
| 922 |
ServerTools.reply(response, type, t, verbose2, 200, true); |
| 923 |
|
| 924 |
final long stopTime=System.nanoTime(); |
| 925 |
final long elapsed=stopTime-startTime; |
| 926 |
if(response.startsWith("Welcome to ")){ |
| 927 |
timeMeasurementsUsage.incrementAndGet(); |
| 928 |
elapsedTimeUsage.addAndGet(elapsed); |
| 929 |
lastTimeUsage.set(elapsed); |
| 930 |
}else{ |
| 931 |
timeMeasurementsRemote.incrementAndGet(); |
| 932 |
elapsedTimeRemote.addAndGet(elapsed); |
| 933 |
lastTimeRemote.set(elapsed); |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
public final boolean skipNonCanonical; |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
static String getBody(HttpExchange t){ |
| 978 |
if(verbose2){System.err.println("getBody");} |
| 979 |
InputStream is=t.getRequestBody(); |
| 980 |
String s=ServerTools.readStream(is); |
| 981 |
return s; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
static String getRParam(HttpExchange t, boolean allowPost){ |
| 986 |
if(verbose2){System.err.println("getRParam");} |
| 987 |
String rparam = t.getRequestURI().toString(); |
| 988 |
|
| 989 |
|
| 990 |
while(rparam.startsWith("/")){ |
| 991 |
rparam = rparam.substring(1); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
while(rparam.endsWith("/")){ |
| 996 |
rparam = rparam.substring(0, rparam.length()-1); |
| 997 |
} |
| 998 |
|
| 999 |
if(allowPost && ("$POST".equalsIgnoreCase(rparam) || "POST".equalsIgnoreCase(rparam))){ |
| 1000 |
String body=getBody(t); |
| 1001 |
rparam=body; |
| 1002 |
} |
| 1003 |
|
| 1004 |
if(verbose){System.err.println(rparam==null || rparam.trim().length()<1 ? "usage" : rparam+"\t"+System.currentTimeMillis());} |
| 1005 |
return rparam; |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
String toResponse(boolean simple, String[] params, HttpExchange t){ |
| 1014 |
if(verbose2){System.err.println("toResponse");} |
| 1015 |
|
| 1016 |
boolean printNumChildren=false; |
| 1017 |
boolean printChildren=false; |
| 1018 |
boolean printPath=false; |
| 1019 |
boolean printSize=false; |
| 1020 |
boolean printRange=false; |
| 1021 |
boolean silvaHeader=false; |
| 1022 |
boolean plaintext=false, semicolon=false, path=false; |
| 1023 |
boolean mononomial=false; |
| 1024 |
boolean ancestor=false; |
| 1025 |
int source=SOURCE_REFSEQ; |
| 1026 |
|
| 1027 |
ArrayList<String> newParams=new ArrayList<String>(params.length); |
| 1028 |
for(int i=0; i<params.length-1; i++){ |
| 1029 |
String s=params[i]; |
| 1030 |
if(s.length()==0 || s.equals("tax")){ |
| 1031 |
|
| 1032 |
}else if(s.equals("printnumchildren") || s.equals("numchildren")){ |
| 1033 |
printNumChildren=true; |
| 1034 |
}else if(s.equals("printchildren") || s.equals("children")){ |
| 1035 |
printChildren=true; |
| 1036 |
}else if(s.equals("mononomial") || s.equals("cn") |
| 1037 |
|| s.equals("fixname") || s.equals("fn") || s.equals("mono") || s.equals("mononomial")){ |
| 1038 |
mononomial=true; |
| 1039 |
}else if(s.equals("printpath") || s.equals("pp")){ |
| 1040 |
printPath=true; |
| 1041 |
}else if(s.equals("printsize") || s.equals("size") || s.equals("ps")){ |
| 1042 |
printSize=true; |
| 1043 |
}else if(s.equals("printrange") || s.equals("range")){ |
| 1044 |
printRange=true; |
| 1045 |
}else if(s.equals("plaintext") || s.equals("pt")){ |
| 1046 |
plaintext=true; semicolon=false; path=false; |
| 1047 |
}else if(s.equals("semicolon") || s.equals("sc")){ |
| 1048 |
semicolon=true; plaintext=false; path=false; |
| 1049 |
}else if(s.equals("path") || s.equals("pa")){ |
| 1050 |
path=true; semicolon=false; plaintext=false; |
| 1051 |
}else if(s.equals("silva")){ |
| 1052 |
silvaHeader=true; |
| 1053 |
source=SOURCE_SILVA; |
| 1054 |
}else if(s.equals("refseq")){ |
| 1055 |
source=SOURCE_REFSEQ; |
| 1056 |
}else if(s.equals("ancestor")){ |
| 1057 |
ancestor=true; |
| 1058 |
}else if(s.equals("simple")){ |
| 1059 |
simple=true; |
| 1060 |
}else{ |
| 1061 |
newParams.add(s); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
newParams.add(params[params.length-1]); |
| 1065 |
params=newParams.toArray(new String[newParams.size()]); |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
if(params.length<2){ |
| 1070 |
if(params.length==1 && "advice".equalsIgnoreCase(params[0])){return TAX_ADVICE;} |
| 1071 |
if(logUsage){System.err.println("usage");} |
| 1072 |
return USAGE(USAGE); |
| 1073 |
} |
| 1074 |
if(params.length>3){ |
| 1075 |
if(logUsage){System.err.println("usage");} |
| 1076 |
return USAGE(USAGE); |
| 1077 |
} |
| 1078 |
|
| 1079 |
final String query=params[params.length-1]; |
| 1080 |
final String[] names=query.split(","); |
| 1081 |
if(names==null){return USAGE(USAGE);} |
| 1082 |
|
| 1083 |
if(names==null || names.length<2){ |
| 1084 |
firstChunkSingle.incrementAndGet(); |
| 1085 |
}else{ |
| 1086 |
firstChunkMulti.incrementAndGet(); |
| 1087 |
} |
| 1088 |
bulkCount.addAndGet(names.length); |
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
final int type; |
| 1093 |
|
| 1094 |
final int type2; |
| 1095 |
{ |
| 1096 |
String typeS=params[0]; |
| 1097 |
Integer value=typeMap.get(typeS); |
| 1098 |
if(value==null){ |
| 1099 |
if(typeS.equalsIgnoreCase("advice")){ |
| 1100 |
return TAX_ADVICE; |
| 1101 |
}else{ |
| 1102 |
return "{\"error\": \"Bad type ("+typeS+"); should be gi, taxid, or name.\"}"; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
int x=value.intValue(); |
| 1106 |
if((x&15)==HEADER && silvaHeader){x=SILVAHEADER;} |
| 1107 |
type=x; |
| 1108 |
type2=x&15; |
| 1109 |
if(type2==IMG){source=SOURCE_IMG;} |
| 1110 |
} |
| 1111 |
|
| 1112 |
plaintext=(type>=PT_BIT || plaintext); |
| 1113 |
semicolon=(type>=SC_BIT || semicolon); |
| 1114 |
path=(type>=PA_BIT || path); |
| 1115 |
if(semicolon || path){plaintext=false;} |
| 1116 |
if(path){semicolon=false;} |
| 1117 |
|
| 1118 |
final boolean internal=incrementQueries(t, false, false, simple, ancestor, |
| 1119 |
plaintext, semicolon, path, printChildren, printPath, printSize, type); |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
if(!internal && !allowRemoteFileAccess){ |
| 1127 |
path=printPath=false; |
| 1128 |
} |
| 1129 |
|
| 1130 |
if(verbose2){System.err.println("Type: "+type);} |
| 1131 |
if(type2==NAME || type2==HEADER || type2==SILVAHEADER){ |
| 1132 |
for(int i=0; i<names.length; i++){ |
| 1133 |
names[i]=PercentEncoding.codeToSymbol(names[i]); |
| 1134 |
if(type2==HEADER || type2==SILVAHEADER){ |
| 1135 |
if(names[i].startsWith("@") || names[i].startsWith(">")){names[i]=names[i].substring(1);} |
| 1136 |
} |
| 1137 |
} |
| 1138 |
if(verbose2){System.err.println("Revised: "+Arrays.toString(names));} |
| 1139 |
} |
| 1140 |
|
| 1141 |
if(ancestor){ |
| 1142 |
if(verbose2){System.err.println("toAncestor: "+Arrays.toString(names));} |
| 1143 |
return toAncestor(type, names, plaintext, semicolon, path, query, simple, !simple, printNumChildren, printChildren, printPath, printSize, printRange, mononomial, source); |
| 1144 |
} |
| 1145 |
|
| 1146 |
if(semicolon){ |
| 1147 |
return toSemicolon(type, names, simple, mononomial); |
| 1148 |
}else if(plaintext){ |
| 1149 |
return toText(type, names); |
| 1150 |
}else if(path){ |
| 1151 |
return toPath(type, names, source); |
| 1152 |
} |
| 1153 |
|
| 1154 |
JsonObject j=new JsonObject(); |
| 1155 |
for(String name : names){ |
| 1156 |
j.add(name, toJson(type, name, simple, !simple, printNumChildren, printChildren, |
| 1157 |
printPath, printSize, printRange, mononomial, source)); |
| 1158 |
} |
| 1159 |
return j.toString(); |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
String toAncestor(final int type, final String[] names, boolean plaintext, boolean semicolon, boolean path, |
| 1164 |
String query, final boolean skipNonCanonical, boolean originalLevel, boolean printNumChildren, |
| 1165 |
boolean printChildren, boolean printPath, boolean printSize, boolean printRange, boolean mononomial, |
| 1166 |
int source){ |
| 1167 |
IntList ilist=toIntList(type, names); |
| 1168 |
int id=FindAncestor.findAncestor(tree, ilist); |
| 1169 |
TaxNode tn=(id>-1 ? tree.getNode(id) : null); |
| 1170 |
if(tn==null){ |
| 1171 |
return new JsonObject("error","Not found.").toString(query); |
| 1172 |
} |
| 1173 |
if(semicolon){ |
| 1174 |
return tree.toSemicolon(tn, skipNonCanonical, mononomial); |
| 1175 |
}else if(plaintext){ |
| 1176 |
return ""+id; |
| 1177 |
}else if(path){ |
| 1178 |
return toPath(tn, source); |
| 1179 |
} |
| 1180 |
|
| 1181 |
JsonObject j=new JsonObject(); |
| 1182 |
|
| 1183 |
j.add("name", tn.name); |
| 1184 |
if(mononomial || true){ |
| 1185 |
String mono=tree.mononomial(tn); |
| 1186 |
if(tn.name!=mono){j.add("mononomial", mono);} |
| 1187 |
} |
| 1188 |
j.add("tax_id", tn.id); |
| 1189 |
if(printNumChildren){j.add("num_children", tn.numChildren);} |
| 1190 |
if(printPath){j.add("path", toPath(tn, source));} |
| 1191 |
if(printSize){ |
| 1192 |
j.add("size", tree.toSize(tn)); |
| 1193 |
j.add("cumulative_size", tree.toSizeC(tn)); |
| 1194 |
j.add("seqs", tree.toSeqs(tn)); |
| 1195 |
j.add("cumulative_seqs", tree.toSeqsC(tn)); |
| 1196 |
j.add("cumulative_nodes", tree.toNodes(tn)); |
| 1197 |
} |
| 1198 |
j.add("level", tn.levelStringExtended(originalLevel)); |
| 1199 |
if(tn.levelExtended<1 && printRange){ |
| 1200 |
j.add("maxDescendent", TaxTree.levelToStringExtended(tn.maxChildLevelExtended)); |
| 1201 |
j.add("minAncestor", TaxTree.levelToStringExtended(tn.minParentLevelExtended)); |
| 1202 |
} |
| 1203 |
|
| 1204 |
while(tn!=null && tn.levelExtended!=TaxTree.LIFE_E && tn.id!=TaxTree.CELLULAR_ORGANISMS_ID){ |
| 1205 |
if(!skipNonCanonical || tn.isSimple()){ |
| 1206 |
j.addAndRename(tn.levelStringExtended(originalLevel), toJson(tn, originalLevel, printNumChildren, printChildren, printPath, printSize, printRange, mononomial, source, -1)); |
| 1207 |
} |
| 1208 |
if(tn.pid==tn.id){break;} |
| 1209 |
tn=tree.getNode(tn.pid); |
| 1210 |
} |
| 1211 |
return j.toString(); |
| 1212 |
} |
| 1213 |
|
| 1214 |
JsonObject getChildren(final int id, boolean originalLevel, boolean printRange, boolean mononomial){ |
| 1215 |
TaxNode x=tree.getNode(id); |
| 1216 |
if(x==null || x.numChildren==0){return null;} |
| 1217 |
ArrayList<TaxNode> list=tree.getChildren(x); |
| 1218 |
return makeChildrenObject(list, originalLevel, printRange, mononomial); |
| 1219 |
} |
| 1220 |
|
| 1221 |
JsonObject makeChildrenObject(ArrayList<TaxNode> list, boolean originalLevel, boolean printRange, boolean mononomial){ |
| 1222 |
if(list==null || list.isEmpty()){return null;} |
| 1223 |
JsonObject j=new JsonObject(); |
| 1224 |
for(TaxNode tn : list){ |
| 1225 |
JsonObject child=new JsonObject(); |
| 1226 |
|
| 1227 |
child.add("name", tn.name); |
| 1228 |
if(mononomial || true){ |
| 1229 |
String mono=tree.mononomial(tn); |
| 1230 |
if(tn.name!=mono){child.add("mononomial", mono);} |
| 1231 |
} |
| 1232 |
child.add("tax_id", tn.id); |
| 1233 |
child.add("num_children", tn.numChildren); |
| 1234 |
child.add("level", tn.levelStringExtended(originalLevel)); |
| 1235 |
if(tn.levelExtended<1 && printRange){ |
| 1236 |
child.add("maxDescendent", TaxTree.levelToStringExtended(tn.maxChildLevelExtended)); |
| 1237 |
child.add("minAncestor", TaxTree.levelToStringExtended(tn.minParentLevelExtended)); |
| 1238 |
} |
| 1239 |
j.add(tn.id+"", child); |
| 1240 |
} |
| 1241 |
return j; |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
String toText(final int type, final String[] names){ |
| 1246 |
|
| 1247 |
StringBuilder sb=new StringBuilder(); |
| 1248 |
String comma=""; |
| 1249 |
|
| 1250 |
int type2=type&15; |
| 1251 |
if(type2==GI){ |
| 1252 |
for(String name : names){ |
| 1253 |
sb.append(comma); |
| 1254 |
TaxNode tn=getTaxNodeGi(Long.parseLong(name)); |
| 1255 |
if(tn==null){sb.append("-1");} |
| 1256 |
else{sb.append(tn.id);} |
| 1257 |
comma=","; |
| 1258 |
} |
| 1259 |
}else if(type2==NAME){ |
| 1260 |
for(String name : names){ |
| 1261 |
sb.append(comma); |
| 1262 |
TaxNode tn=getTaxNodeByName(name); |
| 1263 |
if(tn==null){sb.append("-1");} |
| 1264 |
else{sb.append(tn.id);} |
| 1265 |
comma=","; |
| 1266 |
} |
| 1267 |
}else if(type2==TAXID){ |
| 1268 |
for(String name : names){ |
| 1269 |
sb.append(comma); |
| 1270 |
TaxNode tn=getTaxNodeTaxid(Integer.parseInt(name)); |
| 1271 |
if(tn==null){sb.append("-1");} |
| 1272 |
else{sb.append(tn.id);} |
| 1273 |
comma=","; |
| 1274 |
} |
| 1275 |
}else if(type2==ACCESSION){ |
| 1276 |
for(String name : names){ |
| 1277 |
sb.append(comma); |
| 1278 |
int ncbi=accessionToTaxid(name); |
| 1279 |
sb.append(ncbi); |
| 1280 |
comma=","; |
| 1281 |
} |
| 1282 |
}else if(type2==HEADER || type2==SILVAHEADER){ |
| 1283 |
for(String name : names){ |
| 1284 |
sb.append(comma); |
| 1285 |
TaxNode tn=getTaxNodeHeader(name, type2==SILVAHEADER); |
| 1286 |
if(tn==null){sb.append("-1");} |
| 1287 |
else{sb.append(tn.id);} |
| 1288 |
comma=","; |
| 1289 |
} |
| 1290 |
}else if(type2==IMG){ |
| 1291 |
for(String name : names){ |
| 1292 |
sb.append(comma); |
| 1293 |
int ncbi=imgToTaxid(Long.parseLong(name)); |
| 1294 |
sb.append(ncbi); |
| 1295 |
comma=","; |
| 1296 |
} |
| 1297 |
}else{ |
| 1298 |
return "Bad type; should be pt_gi or pt_name; e.g. /pt_gi/1234"; |
| 1299 |
} |
| 1300 |
|
| 1301 |
return sb.toString(); |
| 1302 |
} |
| 1303 |
|
| 1304 |
private TaxNode toNode(final int type, final String name){ |
| 1305 |
int type2=type&15; |
| 1306 |
final TaxNode tn; |
| 1307 |
if(type2==GI){ |
| 1308 |
tn=getTaxNodeGi(Long.parseLong(name)); |
| 1309 |
}else if(type2==NAME){ |
| 1310 |
tn=getTaxNodeByName(name); |
| 1311 |
}else if(type2==TAXID){ |
| 1312 |
tn=getTaxNodeTaxid(Integer.parseInt(name)); |
| 1313 |
}else if(type2==ACCESSION){ |
| 1314 |
int ncbi=accessionToTaxid(name); |
| 1315 |
tn=(ncbi<0 ? null : tree.getNode(ncbi)); |
| 1316 |
}else if(type2==HEADER || type2==SILVAHEADER){ |
| 1317 |
tn=getTaxNodeHeader(name, type2==SILVAHEADER); |
| 1318 |
}else if(type2==IMG){ |
| 1319 |
int ncbi=imgToTaxid(Long.parseLong(name)); |
| 1320 |
tn=(ncbi<0 ? null : tree.getNode(ncbi)); |
| 1321 |
}else{ |
| 1322 |
tn=null; |
| 1323 |
} |
| 1324 |
return tn; |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
String toPath(final int type, final String[] names, final int source){ |
| 1329 |
|
| 1330 |
StringBuilder sb=new StringBuilder(); |
| 1331 |
String comma=""; |
| 1332 |
|
| 1333 |
int type2=type&15; |
| 1334 |
|
| 1335 |
for(String name : names){ |
| 1336 |
sb.append(comma); |
| 1337 |
if(type2==IMG){ |
| 1338 |
sb.append(toPathIMG(Long.parseLong(name))); |
| 1339 |
}else{ |
| 1340 |
TaxNode tn=toNode(type2, name); |
| 1341 |
sb.append(toPath(tn, source)); |
| 1342 |
} |
| 1343 |
comma=","; |
| 1344 |
} |
| 1345 |
|
| 1346 |
return sb.toString(); |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
String toSemicolon(final int type, final String[] names, boolean skipNonCanonical, boolean mononomial){ |
| 1351 |
|
| 1352 |
StringBuilder sb=new StringBuilder(); |
| 1353 |
String comma=""; |
| 1354 |
|
| 1355 |
int type2=type&15; |
| 1356 |
if(type2==GI){ |
| 1357 |
for(String name : names){ |
| 1358 |
sb.append(comma); |
| 1359 |
TaxNode tn=getTaxNodeGi(Long.parseLong(name)); |
| 1360 |
if(tn==null){sb.append("Not found");} |
| 1361 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1362 |
comma=","; |
| 1363 |
} |
| 1364 |
}else if(type2==NAME){ |
| 1365 |
for(String name : names){ |
| 1366 |
sb.append(comma); |
| 1367 |
TaxNode tn=getTaxNodeByName(name); |
| 1368 |
if(tn==null){sb.append("Not found");} |
| 1369 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1370 |
comma=","; |
| 1371 |
} |
| 1372 |
}else if(type2==TAXID){ |
| 1373 |
for(String name : names){ |
| 1374 |
sb.append(comma); |
| 1375 |
TaxNode tn=getTaxNodeTaxid(Integer.parseInt(name)); |
| 1376 |
|
| 1377 |
if(tn==null){sb.append("Not found");} |
| 1378 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1379 |
comma=","; |
| 1380 |
} |
| 1381 |
}else if(type2==ACCESSION){ |
| 1382 |
for(String name : names){ |
| 1383 |
sb.append(comma); |
| 1384 |
final int tid=accessionToTaxid(name); |
| 1385 |
TaxNode tn=tree.getNode(tid, true); |
| 1386 |
if(tn==null){sb.append("Not found");} |
| 1387 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1388 |
comma=","; |
| 1389 |
} |
| 1390 |
}else if(type2==HEADER || type2==SILVAHEADER){ |
| 1391 |
for(String name : names){ |
| 1392 |
sb.append(comma); |
| 1393 |
TaxNode tn=getTaxNodeHeader(name, type2==SILVAHEADER); |
| 1394 |
if(tn==null){sb.append("Not found");} |
| 1395 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1396 |
comma=","; |
| 1397 |
} |
| 1398 |
}else if(type2==IMG){ |
| 1399 |
for(String name : names){ |
| 1400 |
sb.append(comma); |
| 1401 |
final int tid=imgToTaxid(Long.parseLong(name)); |
| 1402 |
TaxNode tn=tree.getNode(tid, true); |
| 1403 |
if(tn==null){sb.append("Not found");} |
| 1404 |
else{sb.append(tree.toSemicolon(tn, skipNonCanonical, mononomial));} |
| 1405 |
comma=","; |
| 1406 |
} |
| 1407 |
}else{ |
| 1408 |
return "Bad type; should be sc_gi or sc_name; e.g. /sc_gi/1234"; |
| 1409 |
} |
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
return sb.toString(); |
| 1414 |
} |
| 1415 |
|
| 1416 |
|
| 1417 |
JsonObject toJson(final int type, final String name, boolean skipNonCanonical, boolean originalLevel, |
| 1418 |
boolean printNumChildren, boolean printChildren, boolean printPath, boolean printSize, |
| 1419 |
boolean printRange, boolean mononomial, int source){ |
| 1420 |
final TaxNode tn0; |
| 1421 |
TaxNode tn; |
| 1422 |
|
| 1423 |
long img=-1; |
| 1424 |
if(type==GI){ |
| 1425 |
tn0=getTaxNodeGi(Long.parseLong(name)); |
| 1426 |
}else if(type==NAME){ |
| 1427 |
tn0=getTaxNodeByName(name); |
| 1428 |
}else if(type==TAXID){ |
| 1429 |
tn0=getTaxNodeTaxid(Integer.parseInt(name)); |
| 1430 |
}else if(type==ACCESSION){ |
| 1431 |
int ncbi=accessionToTaxid(name); |
| 1432 |
tn0=(ncbi>=0 ? tree.getNode(ncbi) : null); |
| 1433 |
}else if(type==HEADER || type==SILVAHEADER){ |
| 1434 |
tn0=getTaxNodeHeader(name, type==SILVAHEADER); |
| 1435 |
}else if(type==IMG){ |
| 1436 |
img=Long.parseLong(name); |
| 1437 |
final int tid=imgToTaxid(img); |
| 1438 |
tn0=tree.getNode(tid, true); |
| 1439 |
}else{ |
| 1440 |
JsonObject j=new JsonObject("error","Bad type; should be gi, taxid, or name; e.g. /name/homo_sapiens"); |
| 1441 |
j.add("name", name); |
| 1442 |
j.add("type", type); |
| 1443 |
return j; |
| 1444 |
} |
| 1445 |
tn=tn0; |
| 1446 |
if(verbose2){System.err.println("Got node: "+tn);} |
| 1447 |
|
| 1448 |
if(tn!=null){ |
| 1449 |
JsonObject j=new JsonObject(); |
| 1450 |
|
| 1451 |
j.add("name", tn.name); |
| 1452 |
if(mononomial || true){ |
| 1453 |
String mono=tree.mononomial(tn); |
| 1454 |
if(tn.name!=mono){j.add("mononomial", mono);} |
| 1455 |
} |
| 1456 |
j.add("tax_id", tn.id); |
| 1457 |
if(printNumChildren){j.add("num_children", tn.numChildren);} |
| 1458 |
if(printPath){j.add("path", type==IMG ? toPathIMG(img) : toPath(tn, source));} |
| 1459 |
if(printSize){ |
| 1460 |
j.add("size", tree.toSize(tn)); |
| 1461 |
j.add("cumulative_size", tree.toSizeC(tn)); |
| 1462 |
j.add("seqs", tree.toSeqs(tn)); |
| 1463 |
j.add("cumulative_seqs", tree.toSeqsC(tn)); |
| 1464 |
j.add("cumulative_nodes", tree.toNodes(tn)); |
| 1465 |
} |
| 1466 |
j.add("level", tn.levelStringExtended(originalLevel)); |
| 1467 |
if(tn.levelExtended<1 && printRange){ |
| 1468 |
j.add("maxDescendent", TaxTree.levelToStringExtended(tn.maxChildLevelExtended)); |
| 1469 |
j.add("minAncestor", TaxTree.levelToStringExtended(tn.minParentLevelExtended)); |
| 1470 |
} |
| 1471 |
if(printChildren && (tn.id==tn.pid || tn.id==TaxTree.CELLULAR_ORGANISMS_ID)){j.add("children", getChildren(tn.id, originalLevel, printRange, mononomial));} |
| 1472 |
while(tn!=null && tn.levelExtended!=TaxTree.LIFE_E && tn.id!=TaxTree.CELLULAR_ORGANISMS_ID){ |
| 1473 |
|
| 1474 |
if(!skipNonCanonical || tn.isSimple()){ |
| 1475 |
j.addAndRename(tn.levelStringExtended(originalLevel), toJson(tn, originalLevel, printNumChildren, printChildren, printPath && tn==tn0, printSize, printRange, mononomial, source, img)); |
| 1476 |
|
| 1477 |
} |
| 1478 |
if(tn.pid==tn.id){break;} |
| 1479 |
tn=tree.getNode(tn.pid); |
| 1480 |
} |
| 1481 |
return j; |
| 1482 |
} |
| 1483 |
{ |
| 1484 |
JsonObject j=new JsonObject("error","Not found."); |
| 1485 |
j.add("name", name); |
| 1486 |
j.add("type", type); |
| 1487 |
return j; |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
JsonObject toJson(TaxNode tn, boolean originalLevel, boolean printNumChildren, |
| 1493 |
boolean printChildren, boolean printPath, boolean printSize, boolean printRange, |
| 1494 |
boolean mononomial, int source, long img){ |
| 1495 |
JsonObject j=new JsonObject(); |
| 1496 |
|
| 1497 |
j.add("name", tn.name); |
| 1498 |
if(mononomial || true){ |
| 1499 |
String mono=tree.mononomial(tn); |
| 1500 |
if(tn.name!=mono){j.add("mononomial", mono);} |
| 1501 |
} |
| 1502 |
j.add("tax_id", tn.id); |
| 1503 |
if(printNumChildren){j.add("num_children", tn.numChildren);} |
| 1504 |
if(printPath){j.add("path", source==SOURCE_IMG ? toPathIMG(img) : toPath(tn, source));} |
| 1505 |
if(printSize){ |
| 1506 |
j.add("size", tree.toSize(tn)); |
| 1507 |
j.add("cumulative_size", tree.toSizeC(tn)); |
| 1508 |
j.add("seqs", tree.toSeqs(tn)); |
| 1509 |
j.add("cumulative_seqs", tree.toSeqsC(tn)); |
| 1510 |
j.add("cumulative_nodes", tree.toNodes(tn)); |
| 1511 |
} |
| 1512 |
if(tn.levelExtended<1 && printRange){ |
| 1513 |
j.add("maxDescendent", TaxTree.levelToStringExtended(tn.maxChildLevelExtended)); |
| 1514 |
j.add("minAncestor", TaxTree.levelToStringExtended(tn.minParentLevelExtended)); |
| 1515 |
} |
| 1516 |
if(printChildren){ |
| 1517 |
JsonObject children=getChildren(tn.id, originalLevel, printRange, mononomial); |
| 1518 |
if(children!=null){j.add("children", children);} |
| 1519 |
} |
| 1520 |
return j; |
| 1521 |
} |
| 1522 |
|
| 1523 |
String toPath(TaxNode tn, int source){ |
| 1524 |
if(tn==null){return "null";} |
| 1525 |
String path; |
| 1526 |
if(source==SOURCE_REFSEQ){ |
| 1527 |
path=tree.toDir(tn, basePath)+"refseq_"+tn.id+".fa.gz"; |
| 1528 |
}else if(source==SOURCE_SILVA){ |
| 1529 |
path=tree.toDir(tn, basePath)+"silva_"+tn.id+".fa.gz"; |
| 1530 |
}else if(source==SOURCE_IMG){ |
| 1531 |
assert(false); |
| 1532 |
path="null"; |
| 1533 |
}else{ |
| 1534 |
assert(false); |
| 1535 |
path="null"; |
| 1536 |
} |
| 1537 |
if(!path.equals("null") && !new File(path).exists()){path="null";} |
| 1538 |
return path; |
| 1539 |
} |
| 1540 |
|
| 1541 |
String toPathIMG(long imgID){ |
| 1542 |
String path="/global/dna/projectdirs/microbial/img_web_data/taxon.fna/"+imgID+".fna"; |
| 1543 |
if(!new File(path).exists()){path="null";} |
| 1544 |
return path; |
| 1545 |
} |
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
IntList toIntList(final int type, final String[] names){ |
| 1553 |
IntList list=new IntList(names.length); |
| 1554 |
int type2=type&15; |
| 1555 |
if(type2==GI){ |
| 1556 |
for(String name : names){ |
| 1557 |
TaxNode tn=getTaxNodeGi(Long.parseLong(name)); |
| 1558 |
if(tn!=null){list.add(tn.id);} |
| 1559 |
else{notFound.incrementAndGet();} |
| 1560 |
} |
| 1561 |
}else if(type2==NAME){ |
| 1562 |
for(String name : names){ |
| 1563 |
TaxNode tn=getTaxNodeByName(name); |
| 1564 |
if(tn!=null){list.add(tn.id);} |
| 1565 |
else{notFound.incrementAndGet();} |
| 1566 |
} |
| 1567 |
}else if(type2==TAXID){ |
| 1568 |
for(String name : names){ |
| 1569 |
TaxNode tn=getTaxNodeTaxid(Integer.parseInt(name)); |
| 1570 |
if(tn!=null){list.add(tn.id);} |
| 1571 |
else{notFound.incrementAndGet();} |
| 1572 |
} |
| 1573 |
}else if(type2==ACCESSION){ |
| 1574 |
for(String name : names){ |
| 1575 |
int ncbi=accessionToTaxid(name); |
| 1576 |
if(ncbi>=0){list.add(ncbi);} |
| 1577 |
else{notFound.incrementAndGet();} |
| 1578 |
} |
| 1579 |
}else if(type2==IMG){ |
| 1580 |
for(String name : names){ |
| 1581 |
final int tid=imgToTaxid(Long.parseLong(name)); |
| 1582 |
if(tid>=0){list.add(tid);} |
| 1583 |
else{notFound.incrementAndGet();} |
| 1584 |
} |
| 1585 |
}else{ |
| 1586 |
throw new RuntimeException("{\"error\": \"Bad type\"}"); |
| 1587 |
} |
| 1588 |
return list; |
| 1589 |
} |
| 1590 |
|
| 1591 |
public static final String stripAccession(String s){ |
| 1592 |
if(s==null){return null;} |
| 1593 |
s=s.toUpperCase(); |
| 1594 |
for(int i=0; i<s.length(); i++){ |
| 1595 |
char c=s.charAt(i); |
| 1596 |
if(c=='.' || c==':'){return s.substring(0, i);} |
| 1597 |
} |
| 1598 |
return s; |
| 1599 |
} |
| 1600 |
|
| 1601 |
private final int imgToTaxid(String imgID) { |
| 1602 |
return imgToTaxid(Long.parseLong(imgID)); |
| 1603 |
} |
| 1604 |
private final int imgToTaxid(long imgID) { |
| 1605 |
int ncbi=-1; |
| 1606 |
if(imgFile!=null) { |
| 1607 |
ncbi=TaxTree.imgToTaxid(imgID); |
| 1608 |
if(ncbi>=0) {return ncbi;} |
| 1609 |
} |
| 1610 |
return AccessionToTaxid.getImg(imgID); |
| 1611 |
} |
| 1612 |
|
| 1613 |
private int accessionToTaxid(String accession){ |
| 1614 |
if(accession==null){return -1;} |
| 1615 |
int tid=AccessionToTaxid.get(accession); |
| 1616 |
if(tid<0 && distributed && serverNum==0){ |
| 1617 |
accession=stripAccession(accession); |
| 1618 |
int slaveNum=accession.hashCode()%serverCount; |
| 1619 |
if(slaveNum!=serverNum){ |
| 1620 |
String path=slaveAddress.get(slaveNum); |
| 1621 |
tid=TaxClient.accessionToTaxidSpecificServer(path, accession); |
| 1622 |
} |
| 1623 |
} |
| 1624 |
return tid; |
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
TaxNode getTaxNodeByName(String name){ |
| 1629 |
if(verbose2){System.err.println("Fetching node for "+name);} |
| 1630 |
List<TaxNode> list=tree.getNodesByNameExtended(name); |
| 1631 |
if(verbose2){System.err.println("Fetched "+list);} |
| 1632 |
if(list==null){ |
| 1633 |
if(verbose2){System.err.println("Fetched in common map "+name);} |
| 1634 |
String name2=commonMap.get(name); |
| 1635 |
if(verbose2){System.err.println("Fetched "+name2);} |
| 1636 |
if(name2!=null){list=tree.getNodesByName(name2);} |
| 1637 |
} |
| 1638 |
if(list==null){notFound.incrementAndGet();} |
| 1639 |
return list==null ? null : list.get(0); |
| 1640 |
} |
| 1641 |
|
| 1642 |
|
| 1643 |
TaxNode getTaxNodeGi(long gi){ |
| 1644 |
int ncbi=-1; |
| 1645 |
try { |
| 1646 |
ncbi=GiToTaxid.getID(gi); |
| 1647 |
} catch (Throwable e) { |
| 1648 |
if(verbose){e.printStackTrace();} |
| 1649 |
} |
| 1650 |
if(ncbi<0){notFound.incrementAndGet();} |
| 1651 |
return ncbi<0 ? null : getTaxNodeTaxid(ncbi); |
| 1652 |
} |
| 1653 |
|
| 1654 |
|
| 1655 |
TaxNode getTaxNodeHeader(String header, boolean silvaMode){ |
| 1656 |
TaxNode tn=silvaMode ? tree.getNodeSilva(header, true) : tree.parseNodeFromHeader(header, true); |
| 1657 |
if(tn==null){notFound.incrementAndGet();} |
| 1658 |
return tn; |
| 1659 |
} |
| 1660 |
|
| 1661 |
|
| 1662 |
TaxNode getTaxNodeTaxid(int ncbi){ |
| 1663 |
TaxNode tn=null; |
| 1664 |
try { |
| 1665 |
tn=tree.getNode(ncbi); |
| 1666 |
} catch (Throwable e) { |
| 1667 |
if(verbose){e.printStackTrace();} |
| 1668 |
} |
| 1669 |
if(tn==null){notFound.incrementAndGet();} |
| 1670 |
return tn; |
| 1671 |
} |
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
private static HashMap<String, Integer> makeTypeMap() { |
| 1678 |
HashMap<String, Integer> map=new HashMap<String, Integer>(63); |
| 1679 |
map.put("gi", GI); |
| 1680 |
|
| 1681 |
|
| 1682 |
map.put("name", NAME); |
| 1683 |
map.put("tax_id", TAXID); |
| 1684 |
map.put("ncbi", TAXID); |
| 1685 |
map.put("taxid", TAXID); |
| 1686 |
map.put("id", TAXID); |
| 1687 |
map.put("tid", TAXID); |
| 1688 |
map.put("header", HEADER); |
| 1689 |
map.put("accession", ACCESSION); |
| 1690 |
map.put("img", IMG); |
| 1691 |
map.put("silvaheader", SILVAHEADER); |
| 1692 |
|
| 1693 |
map.put("pt_gi", PT_GI); |
| 1694 |
|
| 1695 |
|
| 1696 |
map.put("pt_name", PT_NAME); |
| 1697 |
map.put("pt_tax_id", PT_TAXID); |
| 1698 |
map.put("pt_id", PT_TAXID); |
| 1699 |
map.put("pt_tid", PT_TAXID); |
| 1700 |
map.put("pt_ncbi", PT_TAXID); |
| 1701 |
map.put("pt_taxid", PT_TAXID); |
| 1702 |
map.put("pt_header", PT_HEADER); |
| 1703 |
map.put("pt_header", PT_HEADER); |
| 1704 |
map.put("pt_accession", PT_ACCESSION); |
| 1705 |
map.put("pt_img", PT_IMG); |
| 1706 |
map.put("pt_silvaheader", PT_SILVAHEADER); |
| 1707 |
|
| 1708 |
map.put("sc_gi", SC_GI); |
| 1709 |
|
| 1710 |
|
| 1711 |
map.put("sc_name", SC_NAME); |
| 1712 |
map.put("sc_tax_id", SC_TAXID); |
| 1713 |
map.put("sc_id", SC_TAXID); |
| 1714 |
map.put("sc_tid", SC_TAXID); |
| 1715 |
map.put("sc_ncbi", SC_TAXID); |
| 1716 |
map.put("sc_taxid", SC_TAXID); |
| 1717 |
map.put("sc_header", SC_HEADER); |
| 1718 |
map.put("sc_header", SC_HEADER); |
| 1719 |
map.put("sc_accession", SC_ACCESSION); |
| 1720 |
map.put("sc_silvaheader", SC_SILVAHEADER); |
| 1721 |
|
| 1722 |
return map; |
| 1723 |
} |
| 1724 |
|
| 1725 |
public static HashMap<String, String> makeCommonMap(){ |
| 1726 |
HashMap<String, String> map=new HashMap<String, String>(); |
| 1727 |
map.put("human", "homo sapiens"); |
| 1728 |
map.put("cat", "felis catus"); |
| 1729 |
map.put("dog", "canis lupus familiaris"); |
| 1730 |
map.put("mouse", "mus musculus"); |
| 1731 |
map.put("cow", "bos taurus"); |
| 1732 |
map.put("bull", "bos taurus"); |
| 1733 |
map.put("horse", "Equus ferus"); |
| 1734 |
map.put("pig", "Sus scrofa domesticus"); |
| 1735 |
map.put("sheep", "Ovis aries"); |
| 1736 |
map.put("goat", "Capra aegagrus"); |
| 1737 |
map.put("turkey", "Meleagris gallopavo"); |
| 1738 |
map.put("fox", "Vulpes vulpes"); |
| 1739 |
map.put("chicken", "Gallus gallus domesticus"); |
| 1740 |
map.put("wolf", "canis lupus"); |
| 1741 |
map.put("fruitfly", "drosophila melanogaster"); |
| 1742 |
map.put("zebrafish", "Danio rerio"); |
| 1743 |
map.put("catfish", "Ictalurus punctatus"); |
| 1744 |
map.put("trout", "Oncorhynchus mykiss"); |
| 1745 |
map.put("salmon", "Salmo salar"); |
| 1746 |
map.put("tilapia", "Oreochromis niloticus"); |
| 1747 |
map.put("e coli", "Escherichia coli"); |
| 1748 |
map.put("e.coli", "Escherichia coli"); |
| 1749 |
|
| 1750 |
map.put("lion", "Panthera leo"); |
| 1751 |
map.put("tiger", "Panthera tigris"); |
| 1752 |
map.put("bear", "Ursus arctos"); |
| 1753 |
map.put("deer", "Odocoileus virginianus"); |
| 1754 |
map.put("coyote", "Canis latrans"); |
| 1755 |
|
| 1756 |
map.put("corn", "Zea mays subsp. mays"); |
| 1757 |
map.put("maize", "Zea mays subsp. mays"); |
| 1758 |
map.put("oat", "Avena sativa"); |
| 1759 |
map.put("wheat", "Triticum aestivum"); |
| 1760 |
map.put("rice", "Oryza sativa"); |
| 1761 |
map.put("potato", "Solanum tuberosum"); |
| 1762 |
map.put("barley", "Hordeum vulgare"); |
| 1763 |
map.put("poplar", "Populus alba"); |
| 1764 |
map.put("lettuce", "Lactuca sativa"); |
| 1765 |
map.put("beet", "Beta vulgaris"); |
| 1766 |
map.put("strawberry", "Fragaria x ananassa"); |
| 1767 |
map.put("orange", "Citrus sinensis"); |
| 1768 |
map.put("lemon", "Citrus limon"); |
| 1769 |
map.put("soy", "Glycine max"); |
| 1770 |
map.put("soybean", "Glycine max"); |
| 1771 |
map.put("grape", "Vitis vinifera"); |
| 1772 |
map.put("olive", "Olea europaea"); |
| 1773 |
map.put("cotton", "Gossypium hirsutum"); |
| 1774 |
map.put("apple", "Malus pumila"); |
| 1775 |
map.put("bannana", "Musa acuminata"); |
| 1776 |
map.put("tomato", "Solanum lycopersicum"); |
| 1777 |
map.put("sugarcane", "Saccharum officinarum"); |
| 1778 |
map.put("bean", "Phaseolus vulgaris"); |
| 1779 |
map.put("onion", "Allium cepa"); |
| 1780 |
map.put("garlic", "Allium sativum"); |
| 1781 |
|
| 1782 |
map.put("pichu", "mus musculus"); |
| 1783 |
map.put("pikachu", "mus musculus"); |
| 1784 |
map.put("vulpix", "Vulpes vulpes"); |
| 1785 |
map.put("ninetails", "Vulpes vulpes"); |
| 1786 |
map.put("mareep", "Ovis aries"); |
| 1787 |
|
| 1788 |
return map; |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
private String makeUsagePrefix(){ |
| 1793 |
if(!sketchOnly){ |
| 1794 |
return "Welcome to the JGI taxonomy server!\n" |
| 1795 |
+ "This service provides taxonomy information from NCBI taxID numbers, gi numbers, organism names, and accessions.\n" |
| 1796 |
+ "The output is formatted as a Json object.\n\n" |
| 1797 |
+ "Usage:\n\n" |
| 1798 |
+ "All addresses below are assumed to be prefixed by "+domain+", e.g. /name/homo_sapiens implies a full URL of:\n" |
| 1799 |
+ domain+"/name/homo_sapiens\n" |
| 1800 |
+ "\n" |
| 1801 |
+ "/name/homo_sapiens will give taxonomy information for an organism name.\n" |
| 1802 |
+ "Names are case-insensitive and underscores are equivalent to spaces.\n" |
| 1803 |
+ "/id/9606 will give taxonomy information for an NCBI taxID.\n" |
| 1804 |
+ "/gi/1234 will give taxonomy information from an NCBI gi number.\n" |
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
+ "/accession/NZ_AAAA01000057.1 will give taxonomy information from an accession.\n" |
| 1811 |
+ "/header/ will accept an NCBI sequence header such as gi|7|emb|X51700.1| Bos taurus\n" |
| 1812 |
+ "/silvaheader/ will accept a Silva sequence header such as KC415233.1.1497 Bacteria;Spirochaetae;Spirochaetes\n" |
| 1813 |
+ "/img/ will accept an IMG id such as 2724679250\n" |
| 1814 |
+ "Vertical bars (|) may cause problems on the command line and can be replaced by tilde (~).\n" |
| 1815 |
+ "\nComma-delimited lists are accepted for bulk queries, such as tax/gi/1234,7000,42\n" |
| 1816 |
+ "For plaintext (non-Json) results, add the term /pt/ or /sc/.\n" |
| 1817 |
+ "pt will give just the taxID, while sc will give the whole lineage, semicolon-delimited. For example:\n" |
| 1818 |
+ "/pt/name/homo_sapiens\n" |
| 1819 |
+ "/sc/gi/1234\n\n" |
| 1820 |
+ "Additional supported display options are children, numchildren, range, simple, path, size, and ancestor.\n" |
| 1821 |
+ "The order is not important but they need to come before the query term. For example:\n" |
| 1822 |
+ "/children/numchildren/range/gi/1234\n" |
| 1823 |
+ "\nTo find the common ancestor of multiple organisms, add /ancestor/. For example:\n" |
| 1824 |
+ "/id/ancestor/1234,5678,42\n" |
| 1825 |
+ "/name/ancestor/homo_sapiens,canis_lupus,bos_taurus\n" |
| 1826 |
+ "\nFor a simplified taxonomic tree, add simple.\n" |
| 1827 |
+ "This will ignore unranked or uncommon levels like tribe and parvorder, and only display the following levels:\n" |
| 1828 |
+ "SUBSPECIES, SPECIES, GENUS, FAMILY, ORDER, CLASS, PHYLUM, KINGDOM, SUPERKINGDOM, DOMAIN\n" |
| 1829 |
+ "For example:\n" |
| 1830 |
+ "/simple/id/1234\n" |
| 1831 |
+ "\nTo print taxonomy from the command line in Linux, use curl:\n" |
| 1832 |
+ "curl https://taxonomy.jgi.doe.gov/id/9606\n" |
| 1833 |
+ "\nQueries longer than around 8kB can be sent via POST: curl https://taxonomy..doe.gov/POST" |
| 1834 |
+ "\n...where the data sent is, for example: name/e.coli,h.sapiens,c.lupus\n" |
| 1835 |
+ "\nLast restarted "+startTime+"\n" |
| 1836 |
+ "Running BBTools version "+Shared.BBTOOLS_VERSION_STRING+"\n"; |
| 1837 |
}else{ |
| 1838 |
StringBuilder sb=new StringBuilder(); |
| 1839 |
sb.append("Welcome to the JGI"+(SketchObject.defaultParams.dbName==null ? "" : " "+SketchObject.defaultParams.dbName)+" sketch server!\n"); |
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
sb.append("\nUsage:\n\n"); |
| 1844 |
sb.append("sendsketch.sh in=file.fasta"+(SketchObject.defaultParams.dbName==null ? "" : " "+SketchObject.defaultParams.dbName.toLowerCase())+"\n\n"); |
| 1845 |
sb.append("SendSketch creates a sketch from a local sequence file, and sends the sketch to this server.\n"); |
| 1846 |
sb.append("The server receives the sketch, compares it to all sketches in memory, and returns the results.\n"); |
| 1847 |
sb.append("For files on the same system as the server, the 'local' flag may be used to offload sketch creation to the server.\n"); |
| 1848 |
sb.append("For more details and parameters please run sendsketch.sh with no arguments.\n"); |
| 1849 |
sb.append("\n"); |
| 1850 |
if(SketchObject.useWhitelist()){ |
| 1851 |
sb.append("This server is running in whitelist mode; for best results, use local queries.\n"); |
| 1852 |
sb.append("Remote queries should specify a larger-than-normal sketch size.\n\n"); |
| 1853 |
}else if(SketchObject.blacklist()!=null){ |
| 1854 |
sb.append("This server is running in blacklist mode, using "+new File(SketchObject.blacklist()).getName()+".\n\n"); |
| 1855 |
} |
| 1856 |
sb.append("Last restarted "+startTime+"\n"); |
| 1857 |
sb.append("Running BBTools version "+Shared.BBTOOLS_VERSION_STRING+"\n"); |
| 1858 |
sb.append("Settings:\tk="+SketchObject.k+(SketchObject.k2>0 ? ","+SketchObject.k2 : "")); |
| 1859 |
if(SketchObject.amino){sb.append(" amino");} |
| 1860 |
if(SketchObject.makeIndex){sb.append(" index");} |
| 1861 |
if(SketchObject.useWhitelist()){sb.append(" whitelist");} |
| 1862 |
if(SketchObject.blacklist()!=null){sb.append(" blacklist="+new File(SketchObject.blacklist()).getName());} |
| 1863 |
sb.append('\n'); |
| 1864 |
return sb.toString(); |
| 1865 |
} |
| 1866 |
} |
| 1867 |
|
| 1868 |
private String makeUsageHtml(){ |
| 1869 |
String html=rawHtml; |
| 1870 |
html=html.replace("STATISTICSSTRING", makeStats()); |
| 1871 |
|
| 1872 |
|
| 1873 |
return html; |
| 1874 |
} |
| 1875 |
|
| 1876 |
private String loadRawHtml(){ |
| 1877 |
String path=Data.findPath("?tax_server.html"); |
| 1878 |
String html=ReadWrite.readString(path); |
| 1879 |
return html; |
| 1880 |
} |
| 1881 |
|
| 1882 |
private String makeStats(){ |
| 1883 |
ByteBuilder sb=new ByteBuilder(); |
| 1884 |
|
| 1885 |
if(!sketchOnly){ |
| 1886 |
sb.append("JGI taxonomy server stats:\n" |
| 1887 |
+ "\nLast restarted "+startTime+"\n" |
| 1888 |
+ "Running BBTools version "+Shared.BBTOOLS_VERSION_STRING+"\n"); |
| 1889 |
}else{ |
| 1890 |
sb.append("JGI"+(SketchObject.defaultParams.dbName==null ? "" : " "+SketchObject.defaultParams.dbName)+" sketch server stats:\n\n"); |
| 1891 |
|
| 1892 |
if(domain!=null) {sb.append("Domain: "+domain+"\n");} |
| 1893 |
if(SketchObject.useWhitelist()){ |
| 1894 |
sb.append("This server is running in whitelist mode; for best results, use local queries.\n"); |
| 1895 |
sb.append("Remote queries should specify a larger-than-normal sketch size.\n\n"); |
| 1896 |
}else if(SketchObject.blacklist()!=null){ |
| 1897 |
sb.append("This server is running in blacklist mode, using "+new File(SketchObject.blacklist()).getName()+".\n\n"); |
| 1898 |
} |
| 1899 |
sb.append("Last restarted "+startTime+"\n"); |
| 1900 |
sb.append("Running BBTools version "+Shared.BBTOOLS_VERSION_STRING+"\n"); |
| 1901 |
sb.append("Settings: k="+SketchObject.k+(SketchObject.k2>0 ? ","+SketchObject.k2 : "")); |
| 1902 |
if(SketchObject.amino){sb.append(" amino");} |
| 1903 |
if(SketchObject.makeIndex){sb.append(" index");} |
| 1904 |
if(SketchObject.useWhitelist()){sb.append(" whitelist");} |
| 1905 |
if(SketchObject.blacklist()!=null){sb.append(" blacklist="+new File(SketchObject.blacklist()).getName());} |
| 1906 |
} |
| 1907 |
sb.nl().nl(); |
| 1908 |
sb.append(basicStats()); |
| 1909 |
if(sketchOnly){sb.append(makeExtendedStats());} |
| 1910 |
|
| 1911 |
return sb.toString(); |
| 1912 |
} |
| 1913 |
|
| 1914 |
public String makeExtendedStats(){ |
| 1915 |
ByteBuilder sb=new ByteBuilder(); |
| 1916 |
sb.append('\n'); |
| 1917 |
|
| 1918 |
{ |
| 1919 |
sb.append("\nVersion\tCount\n"); |
| 1920 |
ArrayList<String> list=new ArrayList<String>(); |
| 1921 |
for(Entry<String, StringNum> e : versionMap.entrySet()){ |
| 1922 |
list.add(e.getValue().toString()); |
| 1923 |
} |
| 1924 |
Collections.sort(list); |
| 1925 |
for(String s : list){ |
| 1926 |
sb.append(s).append('\n'); |
| 1927 |
} |
| 1928 |
} |
| 1929 |
|
| 1930 |
{ |
| 1931 |
sb.append("\nSketchs\tCount\tAvgTime\n"); |
| 1932 |
for(int i=0; i<timesByCount.length(); i++){ |
| 1933 |
double a=timesByCount.get(i)/1000000.0; |
| 1934 |
long b=queryCounts.get(i); |
| 1935 |
if(b>0){ |
| 1936 |
sb.append(i).append('\t').append(b).append('\t').append(a/b, 3).append('\n'); |
| 1937 |
} |
| 1938 |
} |
| 1939 |
sb.append('\n'); |
| 1940 |
} |
| 1941 |
return sb.toString(); |
| 1942 |
} |
| 1943 |
|
| 1944 |
public String USAGE(String prefix){ |
| 1945 |
if(!countQueries){return prefix;} |
| 1946 |
String basicStats=basicStats(); |
| 1947 |
return (prefix==null ? basicStats : prefix+"\n"+basicStats); |
| 1948 |
} |
| 1949 |
|
| 1950 |
public String basicStats(){ |
| 1951 |
if(!countQueries){return "";} |
| 1952 |
StringBuilder sb=new StringBuilder(500); |
| 1953 |
|
| 1954 |
final long uq=usageQueries.getAndIncrement(); |
| 1955 |
final long mq=malformedQueries.get(); |
| 1956 |
final long pt=plaintextQueries.get(), sc=semicolonQueries.get(), pa=pathQueries.get(), pp=printPathQueries.get(), ps=printSizeQueries.get(); |
| 1957 |
final long iq=internalQueries.get(); |
| 1958 |
final long lq=localQueries.get(); |
| 1959 |
final long rfq=refQueries.get(); |
| 1960 |
final long q=queries.get(); |
| 1961 |
final long nf=notFound.get(); |
| 1962 |
final double avgTimeDL=.000001*(elapsedTimeLocal.get()/(Tools.max(1.0, timeMeasurementsLocal.get()))); |
| 1963 |
final double lastTimeDL=.000001*lastTimeLocal.get(); |
| 1964 |
final double avgTimeDR=.000001*(elapsedTimeRemote.get()/(Tools.max(1.0, timeMeasurementsRemote.get()))); |
| 1965 |
final double lastTimeDR=.000001*lastTimeRemote.get(); |
| 1966 |
final double avgTimeDRF=.000001*(elapsedTimeReference.get()/(Tools.max(1.0, timeMeasurementsReference.get()))); |
| 1967 |
final double lastTimeDRF=.000001*lastTimeReference.get(); |
| 1968 |
final double avgTimeDU=.000001*(elapsedTimeUsage.get()/(Tools.max(1.0, timeMeasurementsUsage.get()))); |
| 1969 |
final double lastTimeDU=.000001*lastTimeUsage.get(); |
| 1970 |
final long exq=q-iq; |
| 1971 |
final long rmq=q-lq; |
| 1972 |
|
| 1973 |
sb.append('\n').append("Queries: ").append(q); |
| 1974 |
sb.append('\n').append("Usage: ").append(uq); |
| 1975 |
if(sketchOnly){ |
| 1976 |
sb.append('\n').append("Invalid: ").append(mq); |
| 1977 |
sb.append('\n').append("Avg time: ").append(Tools.format("%.3f ms (local queries)", avgTimeDL)); |
| 1978 |
sb.append('\n').append("Last time: ").append(Tools.format("%.3f ms (local queries)", lastTimeDL)); |
| 1979 |
sb.append('\n').append("Avg time: ").append(Tools.format("%.3f ms (remote queries)", avgTimeDR)); |
| 1980 |
sb.append('\n').append("Last time: ").append(Tools.format("%.3f ms (remote queries)", lastTimeDR)); |
| 1981 |
sb.append('\n').append("Avg time: ").append(Tools.format("%.3f ms (ref queries)", avgTimeDRF)); |
| 1982 |
sb.append('\n').append("Last time: ").append(Tools.format("%.3f ms (ref queries)", lastTimeDRF)); |
| 1983 |
}else{ |
| 1984 |
sb.append('\n').append("Avg time: ").append(Tools.format("%.3f ms", avgTimeDR)); |
| 1985 |
sb.append('\n').append("Last time: ").append(Tools.format("%.3f ms", lastTimeDR)); |
| 1986 |
sb.append('\n').append("Avg time: ").append(Tools.format("%.3f ms (usage queries)", avgTimeDU)); |
| 1987 |
sb.append('\n').append("Last time: ").append(Tools.format("%.3f ms (usage queries)", lastTimeDU)); |
| 1988 |
} |
| 1989 |
sb.append('\n'); |
| 1990 |
sb.append('\n').append("Internal: ").append(iq); |
| 1991 |
sb.append('\n').append("External: ").append(exq); |
| 1992 |
if(!sketchOnly){sb.append('\n').append("NotFound: ").append(nf);} |
| 1993 |
sb.append('\n'); |
| 1994 |
|
| 1995 |
if(sketchOnly){ |
| 1996 |
sb.append('\n').append("Local: ").append(lq); |
| 1997 |
sb.append('\n').append("Remote: ").append(rmq); |
| 1998 |
sb.append('\n').append("Reference: ").append(rfq); |
| 1999 |
sb.append('\n'); |
| 2000 |
sb.append('\n').append("Depth: ").append(depthQueries.get()); |
| 2001 |
sb.append('\n'); |
| 2002 |
sb.append('\n').append("Sketches: ").append(querySketches.get()); |
| 2003 |
sb.append('\n').append("BytesIn: ").append(bytesIn.get()); |
| 2004 |
sb.append('\n').append("BytesOut: ").append(bytesOut.get()); |
| 2005 |
sb.append('\n'); |
| 2006 |
sb.append('\n').append("Single: ").append(firstChunkSingle.get()); |
| 2007 |
sb.append('\n').append("Bulk: ").append(firstChunkMulti.get()); |
| 2008 |
sb.append('\n').append("UnknownS: ").append(unknownChunkSingle.get()); |
| 2009 |
sb.append('\n').append("UnknownB: ").append(unknownChunkMulti.get()); |
| 2010 |
sb.append('\n').append("Total: ").append(bulkCount.get()); |
| 2011 |
}else{ |
| 2012 |
sb.append('\n').append("gi: ").append(giQueries.get()); |
| 2013 |
sb.append('\n').append("Name: ").append(nameQueries.get()); |
| 2014 |
sb.append('\n').append("TaxID: ").append(taxidQueries.get()); |
| 2015 |
sb.append('\n').append("Header: ").append(headerQueries.get()); |
| 2016 |
sb.append('\n').append("Accession: ").append(accessionQueries.get()); |
| 2017 |
sb.append('\n').append("IMG: ").append(imgQueries.get()); |
| 2018 |
sb.append('\n').append("Silva: ").append(silvaHeaderQueries.get()); |
| 2019 |
sb.append('\n'); |
| 2020 |
sb.append('\n').append("Simple: ").append(simpleQueries.get()); |
| 2021 |
sb.append('\n').append("Ancestor: ").append(ancestorQueries.get()); |
| 2022 |
sb.append('\n').append("Children: ").append(childrenQueries.get()); |
| 2023 |
sb.append('\n'); |
| 2024 |
sb.append('\n').append("Json: ").append(q-pt-sc-pa); |
| 2025 |
sb.append('\n').append("Plaintext: ").append(pt); |
| 2026 |
sb.append('\n').append("Semicolon: ").append(sc); |
| 2027 |
sb.append('\n').append("Path: ").append(pa+pp); |
| 2028 |
sb.append('\n').append("Size: ").append(ps); |
| 2029 |
sb.append('\n').append("Single: ").append(firstChunkSingle.get()); |
| 2030 |
sb.append('\n').append("Bulk: ").append(firstChunkMulti.get()); |
| 2031 |
sb.append('\n').append("Total: ").append(bulkCount.get()); |
| 2032 |
} |
| 2033 |
sb.append('\n'); |
| 2034 |
return sb.toString(); |
| 2035 |
} |
| 2036 |
|
| 2037 |
public boolean incrementQueries(HttpExchange t, boolean local, boolean refMode, boolean simple, boolean ancestor, |
| 2038 |
boolean plaintext, boolean semicolon, boolean path, boolean printChildren, boolean printPath, boolean printSize, int type){ |
| 2039 |
final boolean internal=ServerTools.isInternalQuery(t, addressPrefix, allowLocalHost, printIP, printHeaders); |
| 2040 |
|
| 2041 |
if(!countQueries){return internal;} |
| 2042 |
queries.incrementAndGet(); |
| 2043 |
if(local){localQueries.incrementAndGet();} |
| 2044 |
else if(refMode){localQueries.incrementAndGet();} |
| 2045 |
|
| 2046 |
if(type>=0){ |
| 2047 |
int type2=type&15; |
| 2048 |
if(type2==GI){ |
| 2049 |
giQueries.incrementAndGet(); |
| 2050 |
}else if(type2==NAME){ |
| 2051 |
nameQueries.incrementAndGet(); |
| 2052 |
}else if(type2==TAXID){ |
| 2053 |
taxidQueries.incrementAndGet(); |
| 2054 |
}else if(type2==ACCESSION){ |
| 2055 |
accessionQueries.incrementAndGet(); |
| 2056 |
}else if(type2==IMG){ |
| 2057 |
imgQueries.incrementAndGet(); |
| 2058 |
}else if(type2==HEADER){ |
| 2059 |
headerQueries.incrementAndGet(); |
| 2060 |
}else if(type2==UNKNOWN){ |
| 2061 |
unknownQueries.incrementAndGet(); |
| 2062 |
}else if(type2==SILVAHEADER){ |
| 2063 |
silvaHeaderQueries.incrementAndGet(); |
| 2064 |
} |
| 2065 |
|
| 2066 |
if(simple){simpleQueries.incrementAndGet();} |
| 2067 |
if(ancestor){ancestorQueries.incrementAndGet();} |
| 2068 |
|
| 2069 |
if(plaintext){plaintextQueries.incrementAndGet();} |
| 2070 |
else if(semicolon){semicolonQueries.incrementAndGet();} |
| 2071 |
else if(path){pathQueries.incrementAndGet();} |
| 2072 |
|
| 2073 |
if(printChildren){childrenQueries.incrementAndGet();} |
| 2074 |
if(printPath){printPathQueries.incrementAndGet();} |
| 2075 |
if(printSize){printSizeQueries.incrementAndGet();} |
| 2076 |
} |
| 2077 |
|
| 2078 |
if(internal){internalQueries.incrementAndGet();} |
| 2079 |
|
| 2080 |
return internal; |
| 2081 |
} |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
String compare(ArrayList<Sketch> inSketches, DisplayParams params){ |
| 2086 |
boolean success=true; |
| 2087 |
final int inSize=inSketches.size(); |
| 2088 |
querySketches.addAndGet(inSize); |
| 2089 |
if(Shared.threads()<2 || maxConcurrentSketchCompareThreads<2 || inSize<4){ |
| 2090 |
ByteBuilder sb=new ByteBuilder(); |
| 2091 |
success=searcher.compare(inSketches, sb, params, maxConcurrentSketchCompareThreads); |
| 2092 |
return sb.toString(); |
| 2093 |
}else{ |
| 2094 |
final int threads=Tools.min(maxConcurrentSketchCompareThreads, (inSize+4)/4); |
| 2095 |
|
| 2096 |
ByteBuilder[] out=new ByteBuilder[inSize]; |
| 2097 |
ArrayList<CompareThread> alct=new ArrayList<CompareThread>(threads); |
| 2098 |
AtomicInteger next=new AtomicInteger(0); |
| 2099 |
for(int i=0; i<threads; i++){ |
| 2100 |
alct.add(new CompareThread(inSketches, i, next, out, params)); |
| 2101 |
} |
| 2102 |
for(CompareThread ct : alct){ct.start();} |
| 2103 |
for(CompareThread ct : alct){ |
| 2104 |
|
| 2105 |
|
| 2106 |
while(ct.getState()!=Thread.State.TERMINATED){ |
| 2107 |
try { |
| 2108 |
|
| 2109 |
ct.join(); |
| 2110 |
} catch (InterruptedException e) { |
| 2111 |
e.printStackTrace(); |
| 2112 |
} |
| 2113 |
} |
| 2114 |
|
| 2115 |
synchronized(ct){ |
| 2116 |
success&=ct.success; |
| 2117 |
} |
| 2118 |
} |
| 2119 |
alct=null; |
| 2120 |
|
| 2121 |
int len=0; |
| 2122 |
for(ByteBuilder bb : out){len=len+bb.length;} |
| 2123 |
ByteBuilder bb2=new ByteBuilder(len); |
| 2124 |
for(int i=0; i<out.length; i++){ |
| 2125 |
ByteBuilder bb=out[i]; |
| 2126 |
bb2.append(bb); |
| 2127 |
out[i]=null; |
| 2128 |
} |
| 2129 |
return bb2.toString(); |
| 2130 |
} |
| 2131 |
} |
| 2132 |
|
| 2133 |
private class CompareThread extends Thread { |
| 2134 |
|
| 2135 |
CompareThread(final ArrayList<Sketch> inSketches_, final int tid_, final AtomicInteger nextSketch_, ByteBuilder[] out_, DisplayParams params_){ |
| 2136 |
inSketches=inSketches_; |
| 2137 |
tid=tid_; |
| 2138 |
nextSketch=nextSketch_; |
| 2139 |
out=out_; |
| 2140 |
params=params_; |
| 2141 |
} |
| 2142 |
|
| 2143 |
@Override |
| 2144 |
public void run(){ |
| 2145 |
success=false; |
| 2146 |
final int inLim=inSketches.size(); |
| 2147 |
final boolean json=params.json(); |
| 2148 |
|
| 2149 |
for(int inNum=nextSketch.getAndIncrement(); inNum<inLim; inNum=nextSketch.getAndIncrement()){ |
| 2150 |
Sketch a=inSketches.get(inNum); |
| 2151 |
assert(buffer.cbs==null); |
| 2152 |
SketchResults sr=searcher.processSketch(a, buffer, fakeID, map, params, 1); |
| 2153 |
a.clearRefHitCounts(); |
| 2154 |
|
| 2155 |
ByteBuilder bb=sr.toText(params); |
| 2156 |
if(out!=null){ |
| 2157 |
if(json && inLim>1){ |
| 2158 |
if(inNum==0){ |
| 2159 |
bb.insert(0, (byte)'['); |
| 2160 |
} |
| 2161 |
if(inNum<inLim-1){ |
| 2162 |
bb.append(','); |
| 2163 |
}else{ |
| 2164 |
bb.append(']'); |
| 2165 |
} |
| 2166 |
} |
| 2167 |
synchronized(out){ |
| 2168 |
out[inNum]=bb; |
| 2169 |
} |
| 2170 |
} |
| 2171 |
} |
| 2172 |
synchronized(this){success=true;} |
| 2173 |
} |
| 2174 |
|
| 2175 |
private final ArrayList<Sketch> inSketches; |
| 2176 |
private final int tid; |
| 2177 |
private final CompareBuffer buffer=new CompareBuffer(false); |
| 2178 |
private final DisplayParams params; |
| 2179 |
private final ByteBuilder[] out; |
| 2180 |
|
| 2181 |
private final AtomicInteger nextSketch; |
| 2182 |
private final AtomicInteger fakeID=new AtomicInteger(SketchObject.minFakeID); |
| 2183 |
private ConcurrentHashMap<Integer, Comparison> map=new ConcurrentHashMap<Integer, Comparison>(101); |
| 2184 |
|
| 2185 |
boolean success=false; |
| 2186 |
|
| 2187 |
} |
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
public boolean sketchOnly=false; |
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
private HashMap<String, StringNum> versionMap=new HashMap<String, StringNum>(); |
| 2201 |
private AtomicLongArray timesByCount=new AtomicLongArray(10000); |
| 2202 |
private AtomicLongArray queryCounts=new AtomicLongArray(10000); |
| 2203 |
|
| 2204 |
private AtomicLong notFound=new AtomicLong(0); |
| 2205 |
private AtomicLong queries=new AtomicLong(0); |
| 2206 |
|
| 2207 |
private AtomicLong internalQueries=new AtomicLong(0); |
| 2208 |
|
| 2209 |
private AtomicLong localQueries=new AtomicLong(0); |
| 2210 |
private AtomicLong refQueries=new AtomicLong(0); |
| 2211 |
|
| 2212 |
private AtomicLong depthQueries=new AtomicLong(0); |
| 2213 |
|
| 2214 |
private AtomicLong iconQueries=new AtomicLong(0); |
| 2215 |
|
| 2216 |
private AtomicLong querySketches=new AtomicLong(0); |
| 2217 |
|
| 2218 |
private AtomicLong unknownChunkSingle=new AtomicLong(0); |
| 2219 |
private AtomicLong unknownChunkMulti=new AtomicLong(0); |
| 2220 |
private AtomicLong firstChunkSingle=new AtomicLong(0); |
| 2221 |
private AtomicLong firstChunkMulti=new AtomicLong(0); |
| 2222 |
private AtomicLong nthChunkSingle=new AtomicLong(0); |
| 2223 |
private AtomicLong nthChunkMulti=new AtomicLong(0); |
| 2224 |
|
| 2225 |
private AtomicLong singleQueries=new AtomicLong(0); |
| 2226 |
private AtomicLong bulkQueries=new AtomicLong(0); |
| 2227 |
private AtomicLong bulkCount=new AtomicLong(0); |
| 2228 |
|
| 2229 |
private AtomicLong giQueries=new AtomicLong(0); |
| 2230 |
private AtomicLong nameQueries=new AtomicLong(0); |
| 2231 |
private AtomicLong taxidQueries=new AtomicLong(0); |
| 2232 |
private AtomicLong headerQueries=new AtomicLong(0); |
| 2233 |
private AtomicLong accessionQueries=new AtomicLong(0); |
| 2234 |
private AtomicLong imgQueries=new AtomicLong(0); |
| 2235 |
private AtomicLong unknownQueries=new AtomicLong(0); |
| 2236 |
private AtomicLong silvaHeaderQueries=new AtomicLong(0); |
| 2237 |
|
| 2238 |
private AtomicLong plaintextQueries=new AtomicLong(0); |
| 2239 |
private AtomicLong semicolonQueries=new AtomicLong(0); |
| 2240 |
private AtomicLong pathQueries=new AtomicLong(0); |
| 2241 |
private AtomicLong printPathQueries=new AtomicLong(0); |
| 2242 |
private AtomicLong printSizeQueries=new AtomicLong(0); |
| 2243 |
private AtomicLong childrenQueries=new AtomicLong(0); |
| 2244 |
|
| 2245 |
private AtomicLong simpleQueries=new AtomicLong(0); |
| 2246 |
private AtomicLong ancestorQueries=new AtomicLong(0); |
| 2247 |
|
| 2248 |
private AtomicLong usageQueries=new AtomicLong(0); |
| 2249 |
private AtomicLong bytesIn=new AtomicLong(0); |
| 2250 |
private AtomicLong bytesOut=new AtomicLong(0); |
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
private AtomicLong elapsedTimeUsage=new AtomicLong(0); |
| 2257 |
private AtomicLong timeMeasurementsUsage=new AtomicLong(0); |
| 2258 |
private AtomicLong lastTimeUsage=new AtomicLong(0); |
| 2259 |
|
| 2260 |
private AtomicLong elapsedTimeRemote=new AtomicLong(0); |
| 2261 |
private AtomicLong timeMeasurementsRemote=new AtomicLong(0); |
| 2262 |
private AtomicLong lastTimeRemote=new AtomicLong(0); |
| 2263 |
|
| 2264 |
private AtomicLong elapsedTimeLocal=new AtomicLong(0); |
| 2265 |
private AtomicLong timeMeasurementsLocal=new AtomicLong(0); |
| 2266 |
private AtomicLong lastTimeLocal=new AtomicLong(0); |
| 2267 |
|
| 2268 |
private AtomicLong elapsedTimeReference=new AtomicLong(0); |
| 2269 |
private AtomicLong timeMeasurementsReference=new AtomicLong(0); |
| 2270 |
private AtomicLong lastTimeReference=new AtomicLong(0); |
| 2271 |
|
| 2272 |
private AtomicLong malformedQueries=new AtomicLong(0); |
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
public boolean printIP=false; |
| 2279 |
public boolean printHeaders=false; |
| 2280 |
public boolean countQueries=true; |
| 2281 |
public float prealloc=0; |
| 2282 |
public boolean useHtml=false; |
| 2283 |
|
| 2284 |
|
| 2285 |
private String giTableFile=null; |
| 2286 |
|
| 2287 |
private String taxTreeFile="auto"; |
| 2288 |
|
| 2289 |
private String accessionFile=null; |
| 2290 |
|
| 2291 |
private String imgFile=null; |
| 2292 |
|
| 2293 |
private String patternFile=null; |
| 2294 |
|
| 2295 |
private String sizeFile=null; |
| 2296 |
|
| 2297 |
|
| 2298 |
private String basePath="/global/cfs/cdirs/bbtools/tree/"; |
| 2299 |
|
| 2300 |
|
| 2301 |
private final TaxTree tree; |
| 2302 |
|
| 2303 |
|
| 2304 |
private final HashMap<String, Integer> typeMap; |
| 2305 |
|
| 2306 |
private final HashMap<String, String> commonMap; |
| 2307 |
|
| 2308 |
|
| 2309 |
private boolean hashNames=true; |
| 2310 |
private boolean hashDotFormat=true; |
| 2311 |
|
| 2312 |
|
| 2313 |
private String oldKillCode=null; |
| 2314 |
|
| 2315 |
private String oldAddress=null; |
| 2316 |
|
| 2317 |
|
| 2318 |
public String domain=null; |
| 2319 |
|
| 2320 |
public int maxConcurrentSketchCompareThreads=8; |
| 2321 |
public int maxConcurrentSketchLoadThreads=4; |
| 2322 |
public int handlerThreads=-1; |
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
private final boolean distributed; |
| 2329 |
private final int serverNum; |
| 2330 |
private final int serverCount; |
| 2331 |
private ArrayList<String> slaveAddress; |
| 2332 |
|
| 2333 |
public final String favIconPath=Data.findPath("?favicon.ico"); |
| 2334 |
public final byte[] favIcon=ReadWrite.readRaw(favIconPath); |
| 2335 |
|
| 2336 |
private final String startTime=new Date().toString(); |
| 2337 |
|
| 2338 |
|
| 2339 |
public final int port; |
| 2340 |
|
| 2341 |
public final String killCode; |
| 2342 |
|
| 2343 |
public final HttpServer httpServer; |
| 2344 |
|
| 2345 |
|
| 2346 |
public static final int PT_BIT=16; |
| 2347 |
|
| 2348 |
public static final int SC_BIT=32; |
| 2349 |
|
| 2350 |
public static final int PA_BIT=64; |
| 2351 |
|
| 2352 |
public static final int UNKNOWN=0, GI=1, NAME=2, TAXID=3, HEADER=4, ACCESSION=5, IMG=6, SILVAHEADER=7; |
| 2353 |
|
| 2354 |
public static final int PT_GI=GI+PT_BIT, PT_NAME=NAME+PT_BIT, PT_TAXID=TAXID+PT_BIT, |
| 2355 |
PT_HEADER=HEADER+PT_BIT, PT_ACCESSION=ACCESSION+PT_BIT, PT_IMG=IMG+PT_BIT, PT_SILVAHEADER=SILVAHEADER+PT_BIT; |
| 2356 |
|
| 2357 |
public static final int SC_GI=GI+SC_BIT, SC_NAME=NAME+SC_BIT, SC_TAXID=TAXID+SC_BIT, |
| 2358 |
SC_HEADER=HEADER+SC_BIT, SC_ACCESSION=ACCESSION+SC_BIT, SC_IMG=IMG+SC_BIT, SC_SILVAHEADER=SILVAHEADER+PT_BIT; |
| 2359 |
|
| 2360 |
public static final int SOURCE_REFSEQ=1, SOURCE_SILVA=2, SOURCE_IMG=3; |
| 2361 |
|
| 2362 |
|
| 2363 |
public static final String TAX_ADVICE="This site does not give tax advice."; |
| 2364 |
|
| 2365 |
public static final String BAD_CODE="Incorrect code."; |
| 2366 |
|
| 2367 |
public final String USAGE; |
| 2368 |
|
| 2369 |
|
| 2370 |
public final String rawHtml; |
| 2371 |
|
| 2372 |
|
| 2373 |
public final SketchSearcher searcher=new SketchSearcher(); |
| 2374 |
|
| 2375 |
public final boolean hasSketches; |
| 2376 |
|
| 2377 |
final boolean allowRemoteFileAccess; |
| 2378 |
final boolean allowLocalHost; |
| 2379 |
final String addressPrefix; |
| 2380 |
private boolean clearMem=true; |
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
private PrintStream outstream=System.err; |
| 2388 |
|
| 2389 |
public static boolean verbose=false, verbose2=false, logUsage=false; |
| 2390 |
|
| 2391 |
public boolean errorState=false; |
| 2392 |
|
| 2393 |
} |