ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/testGraph2Pml.java
Revision: 50
Committed: Tue Mar 28 15:05:31 2006 UTC (18 years, 6 months ago) by filippis
File size: 15457 byte(s)
Log Message:
More examples added and the current ones modified according to Graph2Pml changes
Line File contents
1 import java.sql.*;
2 import java.io.*;
3 import tools.*;
4
5 /**
6 * Package: tools
7 * Class: testGraph2Pml
8 * Author: Ioannis Filippis, filippis@molgen.mpg.de
9 * Date: 21/03/2006
10 *
11 * Simple test class for visualizing contact graphs using Graph2Pml class plus
12 * PyMol class. Run PyMol with the -R option to run the server.
13 *
14 * Notes:
15 * - You can find the results from all examples here in
16 * /project/StruPPi/ioannis/workspace/aglappe/vis_examples/
17 *
18 * Changelog:
19 * 28/03/06 modified by IF (more examples added)
20 * 27/03/06 modified by IF (functional with comments - added cgo examples)
21 * 21/03/06 first created by IF (non functional)
22 */
23
24 public class testGraph2Pml {
25
26 public static void main(String[] args) {
27
28 String connFile = "/project/StruPPi/ioannis/cnfs/msdgraph.my.cnf", pdbFileName = "", molObjName = "";
29 Graph2Pml graphPml = null;
30 PyMol pml = null;
31
32 mySQLConnect SQLC = new mySQLConnect();
33 SQLC.readConnectionFile(connFile);
34 Connection conn = SQLC.openConnection();
35
36 //Create a new output stream to the pymol server running at the localhost
37 //all commands will be send there
38 PrintWriter serverOutPw = new PrintWriter(new PymolServerOutputStream("http://"+Machine.getClient()+":9123"), true);
39 pml = new PyMol(serverOutPw);
40
41 pml.openLog("test", "/home/filippis/Desktop");
42
43 //Edges as lines
44 //export the pdb file directly from msdsd and load it in pymol
45 pdbFileName = Msdsd2Pdb.export2File("1rx4", 20717, 52567, 9, "/project/StruPPi/ioannis/tmp");
46 molObjName = pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
47 System.out.println(molObjName);
48
49 //create a pymol contact graph object for the graph 33729
50 //use only SC_SC edges with SC_SC edge weight and nodes that have SC_SC edges
51 //no further filtering in the edges based on the contact range is applied
52 //no user based graph filtering is applied
53 //the graph comes from msdsd
54 //normal edges will be utilised
55 //the graph will not be visualised as "directed"
56 graphPml = new Graph2Pml(serverOutPw, molObjName, 33729, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, false, false, conn);
57 //draw nodes, edges, special residues but not surface
58 //the node size will be calculated based on the SC_SC_out field on asc order
59 //the node color will be calculated based on the BB_BB_out field not discretised
60 //all ALA nodes will be transparent
61 //all residues that do not have any SC interactions will be the special ones colored green
62 //all edges will be lines of width determined by the SC_SC field in asc order
63 //all edges lines will have color calculated based on the BB_BB_out field not discretised
64 //all edges lines with adjacent ALA's will have gaps
65 graphPml.draw(true, true, true, false);
66 graphPml.setNodeSizeMethod("SC_SC_out", false);
67 graphPml.setNodeColorMethod("BB_BB_out", false);
68 graphPml.setNodeTranspCondition("(res = \"ALA\")");
69 graphPml.setSpecialRes("green", "SELECT cid, num FROM newmsdgraph.nodes WHERE (graph_id = 33729) AND (sc_sc_in+sc_sc_out = 0);");
70 graphPml.setEdgeSizeMethod("SC_SC", false);
71 graphPml.setEdgeColorMethod("BB_BB", false);
72 graphPml.setEdgeGapCondition("(i_res = \"ALA\" OR j_res = \"ALA\")");
73 //create the contact graph
74 graphPml.outputGraph();
75 //save the image not ray-traced
76 pml.saveImage("test1", "/home/filippis/Desktop", false);
77 //if you want later to read the view from a log file
78 //pml.openLog("test1_log","/home/filippis/Desktop");
79 //get the view
80 pml.getView("test1_view");
81 //pml.closeLog();
82
83 // delete all and reload the structure
84 pml.delete("all", false);
85 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
86
87 //to check reversibility in setNodeSizeMethod, setEdgeSizeMethod
88 //and discretised coloring in setNodeColorMethod, setEdgeColorMethod
89 graphPml.setNodeSizeMethod("SC_SC_out", true);
90 graphPml.setNodeColorMethod("BB_BB_out", true);
91 graphPml.setEdgeSizeMethod("SC_SC", true);
92 graphPml.setEdgeColorMethod("BB_BB", true);
93 graphPml.outputGraph();
94 //set view by reading a log file
95 //pml.getFileView("test2_view", "/home/filippis/Desktop/test1_log.pml");
96 //pml.setView("test2_view");
97 //set view based on the view of the first structure so that you can compare
98 //different graphs for the same structure
99 pml.setView("test1_view");
100 pml.saveImage("test2","/home/filippis/Desktop", false);
101
102 // delete all and reload the structure
103 pml.delete("all", false);
104 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
105
106 //just check user defined set/discretised colors
107 //all green nodes must become red
108 graphPml.setNodeColors(new String[] {"red", "magenta", "orange", "chocolate"});
109 //switched red-green, yellow-blue
110 graphPml.setEdgeColors(new String[] {"red", "green", "yellow", "blue", "violet", "cyan", "salmon", "lime", "pink", "slate", "magenta", "orange", "marine", "olive", "purple", "teal", "forest", "firebrick", "chocolate", "wheat", "white", "grey"});
111 graphPml.outputGraph();
112 pml.setView("test1_view");
113 pml.saveImage("test2a","/home/filippis/Desktop", false);
114
115 pml.delete("all", false);
116 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
117
118 //to check node method for edge coloring when nodeColor method not discretised
119 graphPml.setUniformNodeSize(0.6);
120 graphPml.setNodeColorMethod("BB_BB_out", false);
121 graphPml.setUniformEdgeSize(4);
122 graphPml.setEdgeColorMethod("node", true);
123 graphPml.outputGraph();
124 pml.setView("test1_view");
125 pml.saveImage("test3","/home/filippis/Desktop", false);
126
127 pml.delete("all", false);
128 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
129
130 //to check node method for edge coloring when nodeColor method is discretised
131 graphPml.setUniformNodeSize(0.6);
132 graphPml.setNodeColorMethod("BB_BB_out", true);
133 graphPml.setUniformEdgeSize(4);
134 graphPml.setEdgeColorMethod("node", true);
135 graphPml.outputGraph();
136 pml.setView("test1_view");
137 pml.saveImage("test4","/home/filippis/Desktop", false);
138
139 pml.delete("all", false);
140 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
141
142 //to check node method for edge coloring when nodeColor method is uniform
143 graphPml.setUniformNodeSize(0.6);
144 graphPml.setUniformNodeColor("blue");
145 graphPml.setUniformEdgeSize(4);
146 graphPml.setEdgeColorMethod("node", true);
147 graphPml.outputGraph();
148 pml.setView("test1_view");
149 pml.saveImage("test5","/home/filippis/Desktop", false);
150
151 pml.delete("all", false);
152 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
153
154 //to check the trick of directionality with gapped lines for "half" edges
155 //for this purpose a SC_BB graph model is used that doesn't ensure bidirectionality
156 graphPml = new Graph2Pml(serverOutPw, molObjName, 33729, "SC_BB", "SC_BB_in+SC_BB_out", "SC_BB", "true", "true", true, false, true, conn);
157 graphPml.outputGraph();
158 pml.setView("test1_view");
159 pml.saveImage("test6","/home/filippis/Desktop", false);
160
161
162 pml.delete("all", false);
163
164 //test multi-chain macromolecule with RNA also
165 pdbFileName = Msdsd2Pdb.export2File("1a0a", 1107, 2560, 1, "/project/StruPPi/ioannis/tmp");
166 molObjName = pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
167 System.out.println(molObjName);
168
169 graphPml = new Graph2Pml(serverOutPw, molObjName, 95, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, false, false, conn);
170 graphPml.draw(true, true, false, false);
171 //color nodes based on the chains they belong to
172 graphPml.setChainNodeColor();
173 graphPml.setNodeTransp(0.2);
174 graphPml.setUniformEdgeColor("red");
175 graphPml.setUniformEdgeSize(4.5);
176 graphPml.setEdgeGap(0.5);
177 graphPml.outputGraph();
178 pml.saveImage("test7","/home/filippis/Desktop", false);
179 pml.getView("test2_view");
180
181 pml.delete("all", false);
182 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
183
184 //color edges based on the chains they belong to
185 graphPml.draw(true, true, false, false);
186 graphPml.setUniformNodeColor("red");
187 graphPml.setChainEdgeColor();
188 graphPml.outputGraph();
189 pml.setView("test2_view");
190 pml.saveImage("test8","/home/filippis/Desktop", false);
191
192 pml.delete("all", false);
193 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
194
195 //to check node method for edge coloring when nodeColor method is based on chain coloring
196 //also check the user defined chain colors for nodes
197 graphPml.setChainNodeColor(new String[] {"blue"});
198 graphPml.setEdgeColorMethod("node", true);
199 graphPml.outputGraph();
200 pml.setView("test2_view");
201 pml.saveImage("test9","/home/filippis/Desktop", false);
202
203 pml.delete("all", false);
204 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
205
206 //draw also surface - you can not see the graph anymore
207 graphPml.draw(true, true, false, true);
208 graphPml.setSurfTransp(0.7);
209 graphPml.outputGraph();
210 pml.setView("test2_view");
211 pml.saveImage("test10","/home/filippis/Desktop", false);
212
213 try { Thread.sleep(10000); } catch (Exception e) {}
214
215 //hide the surface, show the RNA also
216 //change the color of the nodes for each chain using the pymol defined list of nodes for each chain
217 pml.hideWhat("surface", "graphMol", false);
218 pml.showWhat("lines", "restMol", false);
219 graphPml.setNodesColorUniform("nodes_cidA","red");
220 graphPml.setNodesColorUniform("nodes_cidA","yellow");
221
222 try { Thread.sleep(10000); } catch (Exception e) {}
223
224 //if you believe that the objects contained in the list won't exceed the pymol command length limit,
225 //you can concatenate all objects as a single string selection and handle them all together
226 pml.concatList("nodes", "+", "nodesStr");
227 pml.setNodeColor("blue", "nodesStr", true);
228 pml.selPml("nodes", "nodesStr", true, true);
229
230 pml.delete("all", false);
231 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
232
233 //check a graph model with only inter-secondary-structure-elements SC_SC edges
234 //remember that all the nodes with SC_SC will be selected
235 //use default behaviour
236 graphPml = new Graph2Pml(serverOutPw, molObjName, 95, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "(!((i_ssid = j_ssid) AND (i_sstype = j_sstype)))", "true", true, false, false, conn);
237 graphPml.draw(true, true, false, false);
238 graphPml.outputGraph();
239 pml.setView("test2_view");
240 pml.saveImage("test11","/home/filippis/Desktop", false);
241
242 pml.delete("all", false);
243
244 //CGO EDGES SECTION
245 pdbFileName = Msdsd2Pdb.export2File("1kj0", 21698, 55132, 9, "/project/StruPPi/ioannis/tmp");
246 molObjName = pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
247
248 //Cgo makes sense to be used with directed graph
249 graphPml = new Graph2Pml(serverOutPw, molObjName, 35666, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, true, true, conn);
250 graphPml.draw(true, true, false, false);
251 graphPml.outputGraph();
252 pml.saveImage("test12","/home/filippis/Desktop", false);
253 pml.getView("test3_view");
254
255 // delete all edges
256 pml.iterateList("edges", "edge");
257 pml.delete("edge", true);
258
259 graphPml.draw(false, true, false, false);
260 graphPml.setUniformCgoEdgeSize(0.2);
261 graphPml.setEdgeColorMethod("node", true);
262 graphPml.outputGraph();
263 pml.setView("test3_view");
264 pml.saveImage("test13","/home/filippis/Desktop", false);
265
266 // delete all edges
267 pml.iterateList("edges", "edge");
268 pml.delete("edge", true);
269
270 graphPml.setEdgeSizeMethod("SC_SC", false);
271 graphPml.setEdgeColorMethod("BB_BB", false);
272 graphPml.outputGraph();
273 pml.setView("test3_view");
274 pml.saveImage("test14","/home/filippis/Desktop", false);
275
276 pml.iterateList("edges", "edge");
277 pml.delete("edge", true);
278
279 graphPml.setEdgeSizeMethod("SC_SC", true);
280 graphPml.setEdgeColorMethod("BB_BB", true);
281 graphPml.outputGraph();
282 pml.setView("test3_view");
283 pml.saveImage("test15","/home/filippis/Desktop", false);
284
285 pml.delete("all", false);
286 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
287
288 //to check node method for edge coloring when nodeColor method not discretised
289 graphPml.draw(true, true, false, false);
290 graphPml.setUniformNodeSize(0.6);
291 graphPml.setNodeColorMethod("BB_BB_out", false);
292 graphPml.setUniformEdgeSize(0.4);
293 graphPml.setEdgeColorMethod("node", true);
294 graphPml.outputGraph();
295 pml.setView("test3_view");
296 pml.saveImage("test16","/home/filippis/Desktop", false);
297
298 pml.delete("all", false);
299 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
300
301 //to check node method for edge coloring when nodeColor method not discretised
302 graphPml.setUniformNodeSize(0.6);
303 graphPml.setNodeColorMethod("BB_BB_out", true);
304 graphPml.setUniformEdgeSize(0.4);
305 graphPml.setEdgeColorMethod("node", true);
306 graphPml.outputGraph();
307 pml.setView("test3_view");
308 pml.saveImage("test17","/home/filippis/Desktop", false);
309
310 pml.delete("all", false);
311 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
312
313 //see "real" half-edges
314 graphPml = new Graph2Pml(serverOutPw, molObjName, 35666, "SC_BB", "SC_BB_in+SC_BB_out", "SC_BB", "true", "true", true, true, true, conn);
315 graphPml.outputGraph();
316 pml.setView("test3_view");
317 pml.saveImage("test18","/home/filippis/Desktop", false);
318
319 pml.delete("all", false);
320
321 //test multi-chain macromolecule with RNA also
322 pdbFileName = "1a0a_1107_2560.pdb";
323 molObjName = pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
324 System.out.println(molObjName);
325
326 graphPml = new Graph2Pml(serverOutPw, molObjName, 95, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, true, true, conn);
327 graphPml.draw(true, true, false, false);
328 graphPml.setNodeColorMethod("SC_SC_out", false);
329 graphPml.setNodeTransp(0);
330 graphPml.setEdgeSizeMethod("SC_SC", false);
331 graphPml.setChainEdgeColor(new String[] {"yellow","red"});
332 graphPml.outputGraph();
333 pml.saveImage("test19","/home/filippis/Desktop", false);
334
335 pml.delete("all", false);
336
337 pdbFileName = "1rx4_20717_52567.pdb";
338 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
339
340 graphPml = new Graph2Pml(serverOutPw, molObjName, 33729, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, true, true, conn);
341 graphPml.draw(true, true, false, false);
342 graphPml.setNodeSizeMethod("SC_SC_out", false);
343 graphPml.setNodeColorMethod("SC_SC_out", false);
344 graphPml.setNodeTransp(0.6);
345 graphPml.setEdgeSizeMethod("SC_SC", false);
346 graphPml.setEdgeColorMethod("SC_SC", false);
347 graphPml.outputGraph();
348 pml.saveImage("test20","/home/filippis/Desktop", false);
349
350 pml.delete("all", false);
351 pdbFileName = "1kj0_21698_55132.pdb";
352 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
353
354 //check the setNodeSizeRange method
355 graphPml = new Graph2Pml(serverOutPw, molObjName, 35666, "SC_SC", "SC_SC_in+SC_SC_out", "SC_SC", "true", "true", true, true, true, conn);
356 graphPml.draw(true, false, false, false);
357 graphPml.setChainColors(new String[] {"red"});
358 graphPml.setNodeSizeMethod("SC_SC_out", false);
359 graphPml.setNodeSizeRange(new double[] {0.6, 1.2});
360 graphPml.outputGraph();
361 pml.saveImage("test21","/home/filippis/Desktop", false);
362
363 pml.delete("all", false);
364 pdbFileName = "1kj0_21698_55132.pdb";
365 pml.loadPDB(pdbFileName, "/project/StruPPi/ioannis/tmp");
366
367 //check the setDefaults method
368 graphPml.setDefaults(new String[] {"nodeSizeRange", "chainColors"});
369 graphPml.outputGraph();
370 pml.saveImage("test22","/home/filippis/Desktop", false);
371
372 pml.closeLog();
373
374 SQLC.closeConnection(conn);
375
376 }
377
378 } // end of class testGraph2Pml