Difference between revisions of "Automated Evaluation of Homoloy Models"

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

Revision as of 15:25, 10 June 2011

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;
}
}