Automated Evaluation of Homoloy Models

From Bioinformatikpedia
Revision as of 15:21, 10 June 2011 by Meier (talk | contribs)

Source code for Eval.java

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Eval { public static String USAGE = "java -jar Eval.jar <modelContainer> <modelDir> <refContainer> <refDir>" + "\n\t <modelContainer> contains in each line one id of the used models (the filename before the .pdb)" + "\n\t <modelDir> the directory where the model-files lie" + "\n\t <refContainer> contains in each line one id of the used reference structures (the filename before the .pdb)" + "\n\t <refDir> the directory where the model-files lie"; public static void main(String[] args) { if(args.length != 4) { System.out.println(Eval.USAGE); System.exit(1); } File modelContainer = new File(args[0]); File modelDir = new File(args[1]); File refContainer = new File(args[2]); File refDir = new File(args[3]); ArrayList <String> modelIds = Eval.readContainer(modelContainer); ArrayList <String> refIds = Eval.readContainer(refContainer); for(String modelId : modelIds) { File model = Eval.getPDB(modelDir, modelId); for(String refId : refIds) { System.out.println(modelId+" vs. " +refId); File reference = Eval.getPDB(refDir, refId); System.out.println("RMSD: "+Eval.calcRMSD(reference, model)); System.out.println("TM: "+Eval.calcTM(reference, model)); System.out.println("ALL RMSD: "+Eval.calcFeRMSD(reference, model)); } } } public static String calcRMSD(File reference, File model) { String res = ""; try { Process p = Runtime.getRuntime().exec("sap "+reference.getAbsolutePath()+" "+model.getAbsolutePath()); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while((line = in.readLine()) != null) { if(line.startsWith("Un-weighted RMSd =")) { int off = line.indexOf("over all matched atoms"); if(off != -1) { res = line.substring(18, off); res.replaceAll(" ", ""); } } } } catch (IOException e) { e.printStackTrace(); } return res; } public static String calcAllRMSD(File reference, File model) { String res = ""; try { Process p = Runtime.getRuntime().exec("rms.pl -out all "+reference.getAbsolutePath()+" "+model.getAbsolutePath()); p.waitFor(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while((line = in.readLine()) != null) { res = line.replaceAll(" all", ""); res = res.replaceAll(" ", ""); } in.close(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return res; } public static String calcTM(File reference, File model) { String res = ""; try { Process p = Runtime.getRuntime().exec("TMS "+reference.getAbsolutePath()+" "+model.getAbsolutePath()); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while((line = in.readLine()) != null) { res = line.substring(5); } } catch (IOException e) { e.printStackTrace(); } return res; } public static String calcFeRMSD(File reference, File model) { String res = ""; try { File reftemp = File.createTempFile("reftemp", ".pdb"); reftemp.deleteOnExit(); File modtemp = File.createTempFile("modtemp", ".pdb"); modtemp.deleteOnExit(); File script = Eval.writePythonScript(reference, model, reftemp, modtemp); Process p = Runtime.getRuntime().exec("pymol "+script.getAbsolutePath()); p.waitFor(); res = Eval.calcAllRMSD(reftemp, modtemp); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return res; } public static File writePythonScript(File reference, File model, File reftemp, File modtemp) { File script = null; try { script = File.createTempFile("fesel", ".pml"); script.deleteOnExit(); BufferedWriter out = new BufferedWriter(new FileWriter(script)); out.write("load "+reference.getAbsolutePath()+", reference\n"); out.write("load "+model.getAbsolutePath()+", mod\n"); out.write("select fe, name fe\n"); out.write("align mod, reference\n"); out.write("select near_7, fe around 7\n"); out.write("select ref_near_7, (fe around 7) and reference\n"); out.write("save "+reftemp.getAbsolutePath()+", ref_near_7\n"); out.write("select mod_near_7, (fe around 7) and mod\n"); out.write("save "+modtemp.getAbsolutePath()+", mod_near_7\n"); out.write("quit\n"); out.close(); } catch (IOException e) { e.printStackTrace(); } return script; } public static File getPDB(File dir, String name) { return new File(dir, name+".pdb"); } public static ArrayList<String> readContainer(File f) { ArrayList <String> ids = new ArrayList<String>(); try { BufferedReader in = new BufferedReader(new FileReader(f)); String line; while((line = in.readLine()) != null) { ids.add(line); } in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ids; } }