ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/branches/aglappe-jung/reconstruct.java
(Generate patch)
# Line 2 | Line 2
2  
3   import java.io.File;
4   import java.io.FileNotFoundException;
5 + import java.io.FileOutputStream;
6   import java.io.IOException;
7 + import java.io.PrintWriter;
8   import java.sql.SQLException;
9   import java.util.Formatter;
10  
11 + import proteinstructure.AAinfo;
12   import proteinstructure.ConformationsNotSameSizeError;
13   import proteinstructure.Graph;
14   import proteinstructure.Pdb;
# Line 93 | Line 96
96                          System.exit(1);
97                  }
98                  
99 +                if (baseName.contains(".")) {
100 +                        System.err.println("Basename can't contain a dot (not allowed by tinker). Exiting");
101 +                        System.exit(1);
102 +                }
103 +                
104 +                if (!AAinfo.isValidContactType(ct) || ct.contains("ALL")) {
105 +                        System.err.println("Invalid contact type specified. Exiting");
106 +                        System.exit(1);
107 +                }
108 +                
109 +                if (n>999) {
110 +                        System.err.println("Maximum number of models is 999. Specify a lower value. Exiting");
111 +                        System.exit(1);
112 +                }
113 +                
114                  boolean doublecm = false;
115                  String ct1 = ct;
116                  String ct2 = ct;
# Line 144 | Line 162
162  
163                  
164                  // defining files
165 <                File logFile = new File(outputDir,"tinker.log");
165 >                File logFile = new File(outputDir,baseName+".tinker.log");
166                  File prmFile = new File(PRMFILE);
167                  File xyzFile = new File(outputDir,baseName+".xyz");
168                  File seqFile = new File(outputDir,baseName+".seq");
169                  File pdbFile = new File(outputDir,baseName+".pdb");
170                  File keyFile = new File(outputDir,baseName+".key");
171 +                File reportFile = new File(outputDir,baseName+".report");
172                  
173                  // creating TinkerRunner object
174                  TinkerRunner tr = null;
# Line 196 | Line 215
215                          System.err.println("pdb file "+pdbFile.getAbsolutePath()+" converted from "+xyzFile.getAbsolutePath()+" doesn't seem to be in the right format. Check log? ("+logFile.getAbsolutePath()+"). Exiting");
216                          System.exit(1);
217                  }
218 <                try {
219 <                        cm.createConstraints(graph1);
220 <                        if (doublecm) cm.createConstraints(graph2);
221 <                        if (cross) cm.createConstraints(graph3);
222 <                } catch (Exception e2) {
204 <                        System.err.println("Invalid contact type for writing constraints.");
205 <                        System.err.println("Error: "+e2.getMessage());
206 <                        System.err.println("Exiting");
207 <                        System.exit(1);
208 <                }
218 >
219 >                cm.createConstraints(graph1);
220 >                if (doublecm) cm.createConstraints(graph2);
221 >                if (cross) cm.createConstraints(graph3);
222 >
223                  cm.closeKeyFile();
224  
225                  // 3. run tinker's distgeom
# Line 220 | Line 234
234                          System.err.println("Couldn't read files "+xyzFile.getAbsolutePath()+" or write 'distgeom' output files to output dir "+outputDir);
235                          System.err.println("Exiting");
236                          System.exit(1);
237 +                } catch(InterruptedException e) {
238 +                        System.err.println("Distgeom was interrupted:" + e.getMessage());
239 +                        System.err.println("Exiting.");
240 +                        System.exit(1);
241                  }
242                  
243                  double[] mubv = tr.getMaxUpperBoundViol();
# Line 238 | Line 256
256  
257                  double[] rmsds = new double[n+1];              
258                  
259 <                        for (int i = 1; i<=n; i++) {
260 <                                String ext = new Formatter().format(".%03d",i).toString();
261 <                                File outputXyzFile = new File(outputDir, baseName+ext);
262 <                                File outputPdbFile = new File(outputDir, baseName+ext+".pdb");
263 <                                try {
264 <                                        tr.runXyzpdb(outputXyzFile, seqFile, outputPdbFile);
265 <                                        
266 <                                        Pdb outputPdb = new PdbfilePdb(outputPdbFile.getAbsolutePath(),"NULL");
267 <                                        rmsds[i] = pdb.rmsd(outputPdb, "Ca");
268 <
269 <                                } catch (IOException e) {
270 <                                        System.err.println("Couldn't read file "+outputXyzFile.getAbsolutePath()+", or "+seqFile.getAbsolutePath()+", or write to "+outputPdbFile.getAbsolutePath()+" while converting with 'xyzpdb'");
271 <                                        System.err.println("Can't calculate rmsd for it");
272 <                                } catch (TinkerError e) {
273 <                                        System.err.println("Tinker error while running 'xyzpdb' to convert"+outputXyzFile.getAbsolutePath()+", check log file "+logFile.getAbsolutePath());
274 <                                        System.err.println("Can't calculate rmsd for it");
275 <                                }
276 <                                catch (PdbfileFormatError e) {
277 <                                        System.err.println("Output pdb file "+outputPdbFile.getAbsolutePath()+" doesn't seem to be in the correcet format. Can't calculate rmsd for it");
278 <                                } catch (PdbChainCodeNotFoundError e) {
279 <                                        // this shouldn't happen, chain code is hard coded, we throw stack trace and continue if it happens
280 <                                        e.printStackTrace();
281 <                                } catch (ConformationsNotSameSizeError e) {
282 <                                        System.err.println(pdbFile.getAbsolutePath()+" and "+outputPdbFile.getAbsolutePath()+" don't have the same conformation size, can't calculate rmsd for them.");
283 <                                }                              
284 <                                
285 <                                tr.closeLog();
286 <                        }                                      
259 >                for (int i = 1; i<=n; i++) {
260 >                        String ext = new Formatter().format(".%03d",i).toString();
261 >                        File outputXyzFile = new File(outputDir, baseName+ext);
262 >                        File outputPdbFile = new File(outputDir, baseName+ext+".pdb");
263 >                        try {
264 >                                tr.runXyzpdb(outputXyzFile, seqFile, outputPdbFile);
265 >
266 >                                Pdb outputPdb = new PdbfilePdb(outputPdbFile.getAbsolutePath(),"NULL");
267 >                                rmsds[i] = pdb.rmsd(outputPdb, "Ca");
268 >
269 >                        } catch (IOException e) {
270 >                                System.err.println("Couldn't read file "+outputXyzFile.getAbsolutePath()+", or "+seqFile.getAbsolutePath()+", or write to "+outputPdbFile.getAbsolutePath()+" while converting with 'xyzpdb'");
271 >                                System.err.println("Can't calculate rmsd for it");
272 >                        } catch (TinkerError e) {
273 >                                System.err.println("Tinker error while running 'xyzpdb' to convert"+outputXyzFile.getAbsolutePath()+", check log file "+logFile.getAbsolutePath());
274 >                                System.err.println("Can't calculate rmsd for it");
275 >                        }
276 >                        catch (PdbfileFormatError e) {
277 >                                System.err.println("Output pdb file "+outputPdbFile.getAbsolutePath()+" doesn't seem to be in the correcet format. Can't calculate rmsd for it");
278 >                        } catch (PdbChainCodeNotFoundError e) {
279 >                                // this shouldn't happen, chain code is hard coded, we throw stack trace and continue if it happens
280 >                                e.printStackTrace();
281 >                        } catch (ConformationsNotSameSizeError e) {
282 >                                System.err.println(pdbFile.getAbsolutePath()+" and "+outputPdbFile.getAbsolutePath()+" don't have the same conformation size, can't calculate rmsd for them.");
283 >                        }                              
284 >
285 >                        tr.closeLog();
286 >                }                                      
287  
288                  
289                  // 6. report
290 <                System.out.println("accession_code\tchain_pdb_code\tcutoff\tcutoff2\tcutoff3\tct\tct2\tct3" +
291 <                                "\tresult_id\tup_bound_viol\tlow_bound_viol\tmax_bound_up\tmax_bound_low\trms_bound" +
292 <                                "\tup_viol\tlow_viol\tmax_up\tmax_low\trms_viol\trmsd_to_orig");
293 <                
294 <                for (int i=1;i<=n;i++){
295 <                        System.out.println(pdbCode+"\t"+pdbChainCode+"\t"+cutoff1+"\t"+cutoff2+"\t"+cutoff3+"\t"+ct1+"\t"+ct2+"\t"+ct3+"\t"+
296 <                                        i+"\t"+nubv[i]+"\t"+nlbv[i]+"\t"+mubv[i]+"\t"+mlbv[i]+"\t"+muv[i]+"\t"+mlv[i]+"\t"+rbv[i]+"\t"+
297 <                                        "\t"+nuv[i]+"\t"+nlv[i]+"\t"+rrv[i]+"\t"+rmsds[i]);
290 >                try {
291 >                        PrintWriter reportOut = new PrintWriter(new FileOutputStream(reportFile));
292 >                        reportOut.println("accession_code\tchain_pdb_code\tcutoff\tcutoff2\tcutoff3\tct\tct2\tct3" +
293 >                                                "\tresult_id\tup_bound_viol\tlow_bound_viol\tmax_bound_up\tmax_bound_low\trms_bound" +
294 >                                                "\tup_viol\tlow_viol\tmax_up\tmax_low\trms_viol\trmsd_to_orig");
295 >
296 >                        for (int i=1;i<=n;i++){
297 >                                reportOut.println(pdbCode+"\t"+pdbChainCode+"\t"+cutoff1+"\t"+cutoff2+"\t"+cutoff3+"\t"+ct1+"\t"+ct2+"\t"+ct3+"\t"+
298 >                                                i+"\t"+nubv[i]+"\t"+nlbv[i]+"\t"+mubv[i]+"\t"+mlbv[i]+"\t"+muv[i]+"\t"+mlv[i]+"\t"+rbv[i]+"\t"+
299 >                                                nuv[i]+"\t"+nlv[i]+"\t"+rrv[i]+"\t"+rmsds[i]);
300 >                        }
301 >                        reportOut.close();
302 >                } catch (FileNotFoundException e) {
303 >                        System.err.println("Couldn't write to report file "+reportFile.getAbsolutePath() +". Error: "+e.getMessage());
304                  }
305                  
306          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines