Debian Codegraph @

current/bin/FileRenamer.java

raw symbols SCIP
1 package bin;
2
3 import java.io.File;
4 import java.util.ArrayList;
5
6 import json.JsonObject;
7 import shared.PreParser;
8 import sketch.DisplayParams;
9 import sketch.SendSketch;
10 import sketch.Sketch;
11 import sketch.SketchIdComparator;
12 import sketch.SketchObject;
13 import sketch.SketchTool;
14
15 /** Renames files with top sketch hit taxid */
16 public class FileRenamer {
17
18 public static void main(String[] args) {
19 PreParser pp=new PreParser(args, null, false);
20 args=pp.args;
21 DisplayParams params=new DisplayParams();
22 params.format=DisplayParams.FORMAT_JSON;
23 SketchObject.postParse();
24 SketchTool tool=new SketchTool(10000, params);
25 ArrayList<Sketch> inSketches=tool.loadSketches_MT(params, args);
26 assert(inSketches.size()==args.length) : inSketches.size()+" != "+args.length;
27 final int numLoaded=(inSketches.size());
28 if(numLoaded>1 && params.mode==Sketch.PER_FILE){
29 inSketches.sort(SketchIdComparator.comparator);//Otherwise they come out disordered
30 }
31
32 ArrayList<JsonObject> results=SendSketch.sendSketches(inSketches, "refseq", params);
33 assert(results.size()==inSketches.size()) : inSketches.size()+" != "+results.size();
34 for(int i=0; i<args.length; i++) {
35 String fname=args[i];
36 JsonObject result=results.get(i);
37
38 JsonObject top=null;
39 if(result!=null && result.jmapSize()>0) {
40 for(String key : result.jmap.keySet()){
41 top=result.jmap.get(key);
42 break;
43 }
44 }
45 SketchRecord topHit=(top==null ? null : new SketchRecord(top));
46 int taxid=(topHit==null ? -1 : topHit.taxid);
47
48 File f=new File(fname);
49 String fname2="tid_"+taxid+"_"+fname;
50 File f2=new File(fname2);
51 assert(f.exists());
52 assert(!f2.exists());
53 f.renameTo(f2);
54 }
55 }
56
57 }