| 1 |
package hmm; |
| 2 |
|
| 3 |
import java.io.PrintStream; |
| 4 |
import java.util.ArrayList; |
| 5 |
import java.util.HashMap; |
| 6 |
|
| 7 |
import fileIO.ByteFile; |
| 8 |
import fileIO.ByteFile1; |
| 9 |
import fileIO.ByteFile2; |
| 10 |
import fileIO.ByteStreamWriter; |
| 11 |
import fileIO.FileFormat; |
| 12 |
import fileIO.ReadWrite; |
| 13 |
import shared.Parse; |
| 14 |
import shared.Parser; |
| 15 |
import shared.PreParser; |
| 16 |
import shared.Shared; |
| 17 |
import shared.Timer; |
| 18 |
import shared.Tools; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class HMMSearchReport { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public static void main(String[] args){ |
| 37 |
|
| 38 |
Timer t=new Timer(); |
| 39 |
|
| 40 |
|
| 41 |
HMMSearchReport x=new HMMSearchReport(args); |
| 42 |
|
| 43 |
|
| 44 |
x.process(t); |
| 45 |
|
| 46 |
|
| 47 |
Shared.closeStream(x.outstream); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public HMMSearchReport(String[] args){ |
| 55 |
|
| 56 |
{ |
| 57 |
PreParser pp=new PreParser(args, null, false); |
| 58 |
args=pp.args; |
| 59 |
outstream=pp.outstream; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
{ |
| 65 |
final Parser parser=parse(args); |
| 66 |
parser.out1="stdout.txt"; |
| 67 |
overwrite=parser.overwrite; |
| 68 |
append=parser.append; |
| 69 |
|
| 70 |
in=parser.in1; |
| 71 |
|
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
fixExtensions(); |
| 76 |
checkFileExistence(); |
| 77 |
checkStatics(); |
| 78 |
|
| 79 |
|
| 80 |
ffin=FileFormat.testInput(in, FileFormat.TXT, null, true, true); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
private Parser parse(String[] args){ |
| 89 |
|
| 90 |
Parser parser=new Parser(); |
| 91 |
for(int i=0; i<args.length; i++){ |
| 92 |
String arg=args[i]; |
| 93 |
String[] split=arg.split("="); |
| 94 |
String a=split[0].toLowerCase(); |
| 95 |
String b=split.length>1 ? split[1] : null; |
| 96 |
if(b!=null && b.equalsIgnoreCase("null")){b=null;} |
| 97 |
|
| 98 |
if(a.equals("verbose")){ |
| 99 |
verbose=Parse.parseBoolean(b); |
| 100 |
ByteFile1.verbose=verbose; |
| 101 |
ByteFile2.verbose=verbose; |
| 102 |
ReadWrite.verbose=verbose; |
| 103 |
}else if(parser.parse(arg, a, b)){ |
| 104 |
|
| 105 |
}else{ |
| 106 |
outstream.println("Unknown parameter "+args[i]); |
| 107 |
assert(false) : "Unknown parameter "+args[i]; |
| 108 |
|
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
return parser; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
private void fixExtensions(){ |
| 117 |
in=Tools.fixExtension(in); |
| 118 |
if(in==null){throw new RuntimeException("Error - at least one input file is required.");} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
private void checkFileExistence(){ |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
if(!Tools.testInputFiles(false, true, in)){ |
| 131 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
private static void checkStatics(){ |
| 142 |
|
| 143 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 144 |
ByteFile.FORCE_MODE_BF2=true; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void process(Timer t){ |
| 153 |
|
| 154 |
ByteFile bf=ByteFile.makeByteFile(ffin); |
| 155 |
ByteStreamWriter bsw=null; |
| 156 |
|
| 157 |
|
| 158 |
if(bsw!=null){ |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
processInner(bf, bsw); |
| 163 |
|
| 164 |
errorState|=bf.close(); |
| 165 |
if(bsw!=null){errorState|=bsw.poisonAndWait();} |
| 166 |
|
| 167 |
t.stop(); |
| 168 |
|
| 169 |
outstream.println(Tools.timeLinesBytesProcessed(t, linesProcessed, bytesProcessed, 8)); |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
if(errorState){ |
| 176 |
throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
private void processInner(ByteFile bf, ByteStreamWriter bsw){ |
| 185 |
ArrayList<HMMSearchLine> lines=load(bf); |
| 186 |
for(HMMSearchLine line : lines){ |
| 187 |
addToMap(line); |
| 188 |
System.err.println(line); |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
private void addToMap(HMMSearchLine line){ |
| 193 |
ProteinSummary ps=map.get(line.name); |
| 194 |
if(ps==null){ |
| 195 |
ps=new ProteinSummary(line.name); |
| 196 |
map.put(line.name, ps); |
| 197 |
} |
| 198 |
ps.add(line); |
| 199 |
} |
| 200 |
|
| 201 |
private ArrayList<HMMSearchLine> load(ByteFile bf){ |
| 202 |
byte[] line=bf.nextLine(); |
| 203 |
|
| 204 |
ArrayList<HMMSearchLine> lines=new ArrayList<HMMSearchLine>(); |
| 205 |
while(line!=null){ |
| 206 |
if(line.length>0){ |
| 207 |
linesProcessed++; |
| 208 |
bytesProcessed+=(line.length+1); |
| 209 |
|
| 210 |
if(line[0]!='#'){ |
| 211 |
HMMSearchLine hline=new HMMSearchLine(line); |
| 212 |
lines.add(hline); |
| 213 |
} |
| 214 |
} |
| 215 |
line=bf.nextLine(); |
| 216 |
} |
| 217 |
return lines; |
| 218 |
} |
| 219 |
|
| 220 |
private static ByteStreamWriter makeBSW(FileFormat ff){ |
| 221 |
if(ff==null){return null;} |
| 222 |
ByteStreamWriter bsw=new ByteStreamWriter(ff); |
| 223 |
bsw.start(); |
| 224 |
return bsw; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
private String in=null; |
| 232 |
|
| 233 |
|
| 234 |
public HashMap<String, ProteinSummary> map=new HashMap<String, ProteinSummary>(); |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
private long linesProcessed=0; |
| 239 |
private long bytesProcessed=0; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
private final FileFormat ffin; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
private PrintStream outstream=System.err; |
| 255 |
public static boolean verbose=false; |
| 256 |
public boolean errorState=false; |
| 257 |
private boolean overwrite=true; |
| 258 |
private boolean append=false; |
| 259 |
|
| 260 |
} |