Debian Codegraph @

current/align2/ReformatBatchOutput.java

raw symbols SCIP
1 package align2;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5
6 import fileIO.TextFile;
7 import shared.Tools;
8
9 public class ReformatBatchOutput {
10
11 // Elapsed: 31.7
12 //
13 // Mapping Statistics for 0s_default.sam:
14 // mapped: 100.00%
15 // retained: 96.06%
16 // discarded: 0.00%
17 // ambiguous: 3.94%
18 //
19 // Strict correctness (both ends exactly correct):
20 // true positive: 96.06%
21 // false positive: 0.00%
22 //
23 // Loose correctness (one end approximately correct):
24 // true positive: 96.06%
25 // false positive: 0.00%
26 //
27 // false negative: 0.00%
28 // Elapsed: 2.34
29 // Elapsed: 20.51
30
31
32 // Elapsed: 0.33
33 //
34 // Mapping Statistics for bwa_0S_0I_0D_0U_0N_r100.sam:
35 // primary alignments: 100 found of 100 expected
36 // secondary alignments: 0 found
37 // mapped: 100.000%
38 // retained: 97.000%
39 // discarded: 0.000%
40 // ambiguous: 3.000%
41 //
42 // Strict correctness (both ends exactly correct):
43 // true positive: 97.000%
44 // false positive: 0.000%
45 //
46 // Loose correctness (one end approximately correct):
47 // true positive: 97.000%
48 // false positive: 0.000%
49 //
50 // false negative: 0.000%
51
52
53 public static void main(String[] args){
54 TextFile tf=new TextFile(args[0], false);
55 String[] lines=tf.toStringLines();
56 ArrayList<String> list=new ArrayList<String>();
57
58 int mode=0;
59
60 System.out.println(header());
61
62 for(String s : lines){
63 if(s.startsWith("Elapsed:")){
64 if(!list.isEmpty()){
65 process(list); //failure
66 list.clear();
67 mode=0;
68 }
69 mode++;
70 }
71
72 if(mode>0){
73 list.add(s);
74 if(s.startsWith("false negative:")){
75 process(list);
76 list.clear();
77 mode=0;
78 }
79 }
80 }
81 }
82
83
84 public static String header() {
85 return("program\tfile\tvartype\tcount\treads\tprimary\tsecondary\ttime\tmapped\tretained\tdiscarded\tambiguous\ttruePositive\t" +
86 "falsePositive\ttruePositiveL\tfalsePositiveL\tfalseNegative");
87 }
88
89 //bwa_1S_0I_0D_0U_0N_r400000x100.sam
90 public static int getReads(String name){
91 // String[] split=name.substring(0, name.length()-4).split("_");
92 String[] split=name.split("_");
93 String r=(split[split.length-1]);
94 if(r.charAt(0)=='r' && Tools.isDigit(r.charAt(r.length()-1))){
95 assert(r.charAt(0)=='r') : Arrays.toString(split)+", "+name;
96 r=r.substring(1);
97 if(r.contains("x")){
98 r=r.substring(0, r.indexOf('x'));
99 }
100 return Integer.parseInt(r);
101 }else{
102 for(String s : split){
103 if(s.endsWith("bp") && s.contains("x") && Tools.isDigit(s.charAt(0))){
104 r=s.substring(0, s.indexOf('x')-1);
105 return Integer.parseInt(r);
106 }
107 }
108 }
109 return 0;
110 }
111
112 public static char getVarType(String name){
113 // String[] split=name.substring(0, name.length()-4).split("_");
114 String[] split=name.split("_");
115 for(String s : split){
116 char c=s.charAt(0);
117 if(Tools.isDigit(c) && c!='0' && !s.endsWith("bp")){
118 return s.charAt(s.length()-1);
119 }
120 }
121 return '?';
122 }
123
124 public static int getCount(String name){
125 // String[] split=name.substring(0, name.length()-4).split("_");
126 String[] split=name.split("_");
127 for(String s : split){
128 char c=s.charAt(0);
129 if(Tools.isDigit(c) && c!='0' && !s.endsWith("bp")){
130 String r=s.substring(0, s.length()-1);
131 return Integer.parseInt(r);
132 }
133 }
134 return 0;
135 }
136
137 public static String getProgram(String name){
138 return name.substring(0, name.indexOf('_'));
139 }
140
141
142
143 public static void process(ArrayList<String> list){
144
145 String name=null;
146 // String count=null;
147 String time=null;
148 StringBuilder sb=new StringBuilder();
149
150 int primary=0;
151 int secondary=0;
152 int expected=0;
153
154 for(String s : list){
155 String[] split=s.split("\t");
156 String a=split[0];
157 String b=split.length>1 ? split[1] : null;
158 if(a.equals("Elapsed:")){
159 time=b;
160 }else if(a.startsWith("lines:")){
161 //do nothing
162 }else if(a.startsWith("Mapping Statistics for ")){
163 name=a.replace("Mapping Statistics for ", "").replace(".sam:", "");
164 }else if(a.startsWith("primary alignments:")){
165 assert(b!=null) : "Bad line: "+s;
166 b=b.replace(" found of ", "_");
167 b=b.replace(" expected", "");
168 String[] split2=b.split("_");
169 primary=Integer.parseInt(split2[0]);
170 expected=Integer.parseInt(split2[1]);
171 }else if(a.startsWith("secondary alignments:")){
172 assert(b!=null) : "Bad line: "+s;
173 b=b.replace(" found", "");
174 secondary=Integer.parseInt(b);
175 }else if(b!=null){
176 assert(!b.contains("found")) : "\na='"+a+"'\nb='"+b+"'\n"+a.equals("primary alignments:");
177 sb.append('\t').append(b.replace("%", ""));
178 }
179
180 }
181
182 // if(name!=null){
183 // count="";
184 //
185 // String[] split=name.split("_");
186 //
187 // for(String s : split){
188 // if(s!=null && s.length()>0 && s.charAt(0)!='0'){
189 // for(int i=0; i<s.length(); i++){
190 // char c=s.charAt(i);
191 // if(Tools.isDigit(c)){count=count+c;}
192 // else{break;}
193 // }
194 // }
195 // if(count.length()>0){break;}
196 // }
197 // }
198
199 String prg=null;
200 char type='S';
201 int reads=1;
202 int vars=0;
203
204 if(name!=null){
205 try {
206 prg=getProgram(name);
207 type=getVarType(name);
208 reads=getReads(name);
209 vars=getCount(name);
210 } catch (Exception e) {
211 // TODO Auto-generated catch block
212 e.printStackTrace();
213 }
214 }
215
216 System.out.println(prg+"\t"+name+"\t"+type+"\t"+vars+"\t"+reads+"\t"+primary+"\t"+secondary+"\t"+time+sb);
217
218 }
219
220 }