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