Debian Codegraph @

current/driver/SummarizeCoverage.java

raw symbols SCIP
1 package driver;
2
3 import java.io.File;
4 import java.util.ArrayList;
5
6 import fileIO.TextFile;
7 import fileIO.TextStreamWriter;
8 import shared.Parser;
9 import shared.PreParser;
10 import shared.Tools;
11
12 /**
13 * @author Brian Bushnell
14 * @date Apr 29, 2015
15 *
16 */
17 public class SummarizeCoverage {
18
19 /**
20 * Code entrance from the command line.
21 * @param args Command line arguments
22 */
23 public static void main(String[] args){
24 //Create a new instance
25 SummarizeCoverage x=new SummarizeCoverage(args);
26
27 ///And run it
28 x.process();
29 }
30
31 public SummarizeCoverage(String[] args){
32
33 {//Preparse block for help, config files, and outstream
34 PreParser pp=new PreParser(args, getClass(), false);
35 args=pp.args;
36 //outstream=pp.outstream;
37 }
38
39 ArrayList<String> names=new ArrayList<String>();
40 Parser parser=new Parser();
41
42 /* Parse arguments */
43 for(int i=0; i<args.length; i++){
44
45 final String arg=args[i];
46 String[] split=arg.split("=");
47 String a=split[0].toLowerCase();
48 String b=split.length>1 ? split[1] : null;
49
50 if(parser.parse(arg, a, b)){
51 //do nothing
52 }else if(!arg.contains("=")){
53 String[] x=(new File(arg).exists() ? new String[] {arg} : arg.split(","));
54 for(String x2 : x){names.add(x2);}
55 }else{
56 throw new RuntimeException("Unknown parameter "+arg);
57 }
58 }
59
60 {//Process parser fields
61 out=(parser.out1==null ? "stdout" : parser.out1);
62 if(parser.in1!=null){
63 String[] x=(new File(parser.in1).exists() ? new String[] {parser.in1} : parser.in1.split(","));
64 for(String x2 : x){names.add(x2);}
65 }
66 }
67
68 in=new ArrayList<String>();
69 for(String s : names){
70 Tools.getFileOrFiles(s, in, false, false, false, true);
71 }
72 }
73
74 public void process(){
75 TextStreamWriter tsw=new TextStreamWriter(out, true, false, false);
76 tsw.start();
77 tsw.print("#File\tPrimary_Name\tPrimary_Count\tOther_Count\tPrimary_MB\tOther_MB\n");
78 for(String fname : in){
79 String pname=null;
80 long pcount=0, ocount=0;
81 double pmb=0, omb=0;
82 TextFile tf=new TextFile(fname);
83 for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){
84 if(!line.startsWith("#")){
85 String[] split=line.split("\t");
86 long count=Long.parseLong(split[5]);
87 double mb=Double.parseDouble(split[2]);
88 if(pcount==0 || mb>pmb || (mb==pmb && count>pcount)){
89 pname=split[0];
90 ocount+=pcount;
91 omb+=pmb;
92 pcount=count;
93 pmb=mb;
94 }else{
95 ocount+=count;
96 omb+=mb;
97 }
98 }
99 }
100 tf.close();
101 tsw.print(Tools.format("%s\t%s\t%d\t%d\t%.5f\t%.5f\n", fname, pname, pcount, ocount, pmb, omb));
102 }
103 tsw.poisonAndWait();
104 }
105
106 final ArrayList<String> in;
107 final String out;
108
109 }