1 |
import java.io.*; |
2 |
import java.util.*; |
3 |
import proteinstructure.*; |
4 |
|
5 |
public class testGraphAverager { |
6 |
|
7 |
/** |
8 |
* @param args |
9 |
*/ |
10 |
public static void main(String[] args) { |
11 |
// Plan: |
12 |
// use getopt to parse the following parameters |
13 |
// - original structure (optional, for benchmarking) |
14 |
// - file with list of structures for averaging (required) |
15 |
// - contact type & distance cutoff (both required) |
16 |
// - consensus edge threshold (defaults to 0.5?) |
17 |
// - run tinker or not |
18 |
// - parameters for tinker model picking (optional) |
19 |
// - number of tinker models to output (only if run tinker is set, defaults to one) |
20 |
// - output benchmark result (graph comparison or structure comparison, only if original structure is specified) |
21 |
// - output file for resulting graph (optional) |
22 |
|
23 |
// take pdb files from command line (later: use getopt) |
24 |
// create trivial alignment (check alignment) |
25 |
// create graphAverager |
26 |
// create consensus graph |
27 |
// compare with graph for native structure (first argument) |
28 |
|
29 |
// do tinker reconstruction |
30 |
// compare with native structure |
31 |
|
32 |
// benchmarking: |
33 |
// - use score of best model vs. native (either graph based or structure based) |
34 |
// - use matlab to optimize input parameters |
35 |
// - create matlab executable for optimizing command line parameters: |
36 |
// * specify command line to be run and constant parameters |
37 |
// * specify parameter ranges to be optimized (discrete numerical, continuous numerical with steps, discrete set) |
38 |
// * specify regexp to parse result from output (stdout or file) |
39 |
// * specify optimization procedure (use default matlab ones, e.g. each parameter separate, genetic algorithm, simul. annealing, ...) |
40 |
// * specify convergence threshold or timeout |
41 |
// * run on cluster? |
42 |
|
43 |
|
44 |
// read command line parameters |
45 |
if(args.length < 4) { |
46 |
System.out.println("Usage: testGraphAverager <targetPdbFile> <ChainCode> <ListOfPredictionFiles> <edgeThreshold>"); |
47 |
System.exit(1); |
48 |
} |
49 |
|
50 |
File targetFile = new File(args[0]); |
51 |
File listFile = new File(args[2]); |
52 |
String chainCode = args[1]; |
53 |
String thresholdStr = args[3]; |
54 |
Pdb target = null; |
55 |
Graph targetGraph = null; |
56 |
Vector<String> modelFileNames = new Vector<String>(); |
57 |
Vector<Graph> models = new Vector<Graph>(); |
58 |
String contactType = "Cb"; |
59 |
double distCutoff = 7.0; |
60 |
double graphAveragingThreshold = Double.parseDouble(thresholdStr); |
61 |
|
62 |
if(!targetFile.canRead()) { |
63 |
System.err.println("Can not read from file " + targetFile.getAbsolutePath()); |
64 |
System.exit(1); |
65 |
} |
66 |
if(!listFile.canRead()) { |
67 |
System.err.println("Can not read from file " + listFile.getAbsolutePath()); |
68 |
System.exit(1); |
69 |
} |
70 |
|
71 |
// read input files |
72 |
try { |
73 |
target = new PdbfilePdb(targetFile.getAbsolutePath(), chainCode); |
74 |
targetGraph = target.get_graph(contactType, distCutoff); |
75 |
} catch(PdbChainCodeNotFoundError e) { |
76 |
System.err.println("Chain code " + chainCode + " not found in file " + targetFile.getAbsolutePath()); |
77 |
System.exit(1); |
78 |
} catch(PdbfileFormatError e) { |
79 |
System.err.println("Formating error in file " + targetFile.getAbsolutePath()); |
80 |
System.exit(1); |
81 |
} catch (FileNotFoundException e) { |
82 |
System.err.println("File " + targetFile.getAbsolutePath() + " not found"); |
83 |
System.exit(1); |
84 |
} catch(IOException e) { |
85 |
System.err.println("Error reading from file " + targetFile.getAbsolutePath()); |
86 |
System.exit(1); |
87 |
} |
88 |
|
89 |
try { |
90 |
BufferedReader in = new BufferedReader(new FileReader(listFile)); |
91 |
String line; |
92 |
File file; |
93 |
Pdb pdb; |
94 |
Graph graph; |
95 |
while ((line = in.readLine() ) != null) { |
96 |
file = new File(line); |
97 |
if(!file.canRead()) { |
98 |
System.err.println("File " + line + " not found."); |
99 |
System.exit(1); |
100 |
} else { |
101 |
modelFileNames.add(line); |
102 |
try { |
103 |
pdb = new PdbfilePdb(file.getAbsolutePath(),Pdb.NULL_CHAIN_CODE); |
104 |
graph = pdb.get_graph(contactType, distCutoff); |
105 |
models.add(graph); |
106 |
} catch(PdbChainCodeNotFoundError e) { |
107 |
System.err.println("Chain code " + chainCode + " not found in file " + file.getAbsolutePath()); |
108 |
System.exit(1); |
109 |
} catch(PdbfileFormatError e) { |
110 |
System.err.println("Formating error in file " + file.getAbsolutePath()); |
111 |
System.exit(1); |
112 |
} catch (FileNotFoundException e) { |
113 |
System.err.println("File " + file.getAbsolutePath() + " not found"); |
114 |
System.exit(1); |
115 |
} catch(IOException e) { |
116 |
System.err.println("Error reading from file " + file.getAbsolutePath()); |
117 |
System.exit(1); |
118 |
} |
119 |
} |
120 |
} |
121 |
in.close(); |
122 |
|
123 |
} catch(FileNotFoundException e) { |
124 |
System.err.println("File " + listFile.getAbsolutePath() + " not found."); |
125 |
System.exit(1); |
126 |
} catch(IOException e) { |
127 |
System.err.println("Error reading from file " + listFile.getAbsolutePath()); |
128 |
System.exit(1); |
129 |
} |
130 |
|
131 |
// create alignment |
132 |
TreeMap<String,String> sequences = new TreeMap<String, String>(); |
133 |
TreeMap<String, Graph> templateGraphs = new TreeMap<String, Graph>(); |
134 |
sequences.put(targetFile.getAbsolutePath(), targetGraph.getSequence()); |
135 |
for(int i=0; i < models.size(); i++) { |
136 |
sequences.put(modelFileNames.get(i), models.get(i).getSequence()); |
137 |
templateGraphs.put(modelFileNames.get(i), models.get(i)); |
138 |
} |
139 |
Alignment al = new Alignment(sequences); |
140 |
|
141 |
// create GraphAverager |
142 |
GraphAverager grav = new GraphAverager(targetGraph.getSequence(), al, templateGraphs, targetFile.getAbsolutePath()); |
143 |
Graph resultGraph = grav.doAveraging(graphAveragingThreshold); |
144 |
|
145 |
// compare prediction with target |
146 |
PredEval eval = resultGraph.evaluatePrediction(targetGraph); |
147 |
eval.print(); |
148 |
|
149 |
// write result graph to file |
150 |
try { |
151 |
resultGraph.write_graph_to_file("predictedGraph.cm"); |
152 |
} catch (IOException e) { |
153 |
// TODO Auto-generated catch block |
154 |
e.printStackTrace(); |
155 |
} |
156 |
|
157 |
} |
158 |
} |