| 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 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 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); |
| 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 |
|
| 90 |
public static int getReads(String name){ |
| 91 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 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 |
|
| 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 |
} |