ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/writeTargetMoves.java
Revision: 273
Committed: Tue Aug 14 09:13:07 2007 UTC (17 years, 2 months ago) by lappe
File size: 9293 byte(s)
Log Message:
Line File contents
1 import tools.MySQLConnection;
2
3 import java.sql.SQLException;
4 import java.sql.Statement;
5 import java.sql.ResultSet;
6
7 public class writeTargetMoves {
8
9 /**
10 * writes all the moves for a given residue for later scoring.
11 * @author lappe
12 */
13 static int maxRank = 21; // value to replace for non-existence of central redue in the resultvector (rank=0)
14 // higher values should penalize non-existence more
15 static int VL=1; // Verbosity Level
16 static String user = "lappe" ; // change user name!!
17 static MySQLConnection conn;
18 static String backgrndDB = "test_targets";
19 static String targetNodes = "single_model_node";
20 static String targetEdges = "single_model_edge";
21 static String targetScore = "single_model_score";
22 static int cn1[], cn2[];
23
24 public static void main(String[] args) {
25 int graph_id=0, num=0, node_id=0;
26 String cid="", res="", sstype="";
27 String sql;
28 Statement mstmt;
29 ResultSet mrsst;
30
31 if (args.length<1){
32 System.err.println("The graph_id needs to be given .... i.e. 7");
33 System.exit(1);
34 }
35 graph_id = Integer.parseInt( args[0]);
36 try {
37 conn = new MySQLConnection("white",user,"nieve", backgrndDB); // the UPPERCASE DB!
38 System.out.println("Writing Target neighborhoods v.0.1. ");
39 // retrieve node_id | cid | res | sstype defined by graph_id, num
40 sql = "select node_id, cid, num, res, sstype from "+targetNodes+" where graph_id="+graph_id+";";
41 mstmt = conn.createStatement();
42 mrsst = mstmt.executeQuery(sql);
43 while (mrsst.next()) {
44 // this is the central node -> get type and secondary structure
45 node_id = mrsst.getInt( 1);
46 cid = mrsst.getString( 2);
47 num = mrsst.getInt( 3);
48 res = mrsst.getString( 4).toUpperCase();
49 sstype = "";
50 // sstype= mrsst.getString( 5).toUpperCase();
51 System.out.println("GraphID "+graph_id+" Chain "+cid+", Central residue ("+node_id+") "+res+":"+num+":"+sstype);
52 writeMoves( graph_id, node_id, cid, num, res, sstype);
53 } // end if central residue
54 mrsst.close();
55 mstmt.close();
56 } catch (SQLException e) {
57 e.printStackTrace();
58 System.err.println("SQLException: " + e.getMessage());
59 System.err.println("SQLState: " + e.getSQLState());
60 } // end try/catch
61 System.out.println("fin.");
62 } // end main
63
64
65
66 public static void writeMoves( int cgraph_id, int cnode_id, String ccid, int cnum, String cres, String csstype) {
67 int n1=0, n2=0, ni=0, nj=0, i=0, j=0, j_num=0, j_shell=0, j_cnsize=0;
68 int minus, mcn, plus, pcn;
69 String sql, j_res, j_sec, mres, mss, pres, pss, nn;
70 boolean overx = false;
71 Statement stmt, mst;
72 ResultSet rsst;
73
74 try {
75
76 // retrieve the original nbhood into orig_shell
77 System.out.println("retrieving first shell ... ");
78 stmt = conn.createStatement();
79 stmt.executeUpdate("drop table if exists temp_shell;");
80 stmt.close();
81
82 stmt = conn.createStatement();
83 //stmt.executeUpdate("create table temp_shell as select i_num, i_res, j_num, j_res, j_sstype, 1 as shell from "+targetEdges+" where graph_id="+cgraph_id+" and i_num="+cnum+";");
84 stmt.executeUpdate("create table temp_shell as select i_num, i_res, j_num, j_res, '' as j_sstype, 1 as shell from "+targetEdges+" where graph_id="+cgraph_id+" and i_num="+cnum+";");
85 stmt.close();
86
87 System.out.println("adding the 2nd shell ...");
88 sql = "select j_num from temp_shell where shell=1;";
89 stmt = conn.createStatement();
90 rsst = stmt.executeQuery(sql);
91 i=0;
92 while (rsst.next()) {
93 i++;
94 j_num = rsst.getInt(1);
95 System.out.println(i+":"+j_num);
96 mst = conn.createStatement();
97 // sql = "insert into temp_shell select i_num, i_res, j_num, j_res, j_sstype, 2 as shell from "+targetEdges+" where graph_id="+cgraph_id+" and i_num="+j_num+";";
98 sql = "insert into temp_shell select i_num, i_res, j_num, j_res, '', 2 as shell from "+targetEdges+" where graph_id="+cgraph_id+" and i_num="+j_num+";";
99 // System.out.println(">"+sql);
100 mst.executeUpdate( sql);
101 mst.close();
102 } // end while
103 rsst.close();
104 stmt.close();
105
106 System.out.println("retrieving the entire nbhood (1st and 2nd shell)");
107 // sql = "select j_num, j_res, j_sstype, min(shell) as shell, count(*) as cn from temp_shell where j_num!="+cnum+" group by j_num order by j_num;";
108 sql = "select j_num, j_res, '' as jsstype, min(shell) as shell, count(*) as cn from temp_shell where j_num!="+cnum+" group by j_num order by j_num;";
109 stmt = conn.createStatement();
110 rsst = stmt.executeQuery(sql);
111 n1=0;
112 n2=0;
113 while (rsst.next()) {
114 if ( rsst.getInt( 4)==1) { // count 1st shell entry
115 n1++;
116 System.out.print("1#"+n1);
117 } // end if 2st shell
118 if ( rsst.getInt( 4)==2) { // count 2nd shell entry
119 n2++;
120 System.out.print("2#"+n2);
121 } // end if 2nd shell
122 System.out.println(" :\t"+rsst.getInt( 1)+"\t"+rsst.getString( 2)+"\t"+rsst.getString( 3)+"\t"+rsst.getInt( 4)+"\t"+rsst.getInt( 5));
123 } // end while
124
125 System.out.println("|1st shell|="+n1+" \tx\t |2nd shell|="+n2);
126 mst = conn.createStatement();
127 sql = "delete from target_score where graph_id="+cgraph_id+" and node_id="+cnode_id+" and cid='"+ccid+"' and num="+cnum+";";
128 System.out.println(">"+sql);
129 mst.executeUpdate( sql);
130 mst.close();
131
132 cn1 = new int[n1+1];
133 cn2 = new int[n2+1];
134 // minus | mres | mss | mcn | plus | pres | pss | pcn | nn
135 for (j=0; j<=n2; j++) { // outer loop through all indirect contacts
136 for (i=0; i<=n1; i++) { // inner loop through all direct contacts
137 overx = false;
138 if (VL>=1) {
139 System.out.print("("+i+","+j+")\t");
140 }
141 minus = 0;
142 mres = "";
143 mss = "";
144 mcn = n1;
145 plus = 0;
146 pres = "";
147 pss = "";
148 pcn = n1;
149 nn="%";
150 ni=0; nj=0;
151 rsst.beforeFirst();
152 while (rsst.next()) {
153 j_num = rsst.getInt(1);
154 j_res = rsst.getString(2);
155 //j_sec = rsst.getString(3);
156 j_sec="";
157 j_shell = rsst.getInt(4);
158 j_cnsize = rsst.getInt(5);
159
160 if (j_num>cnum) { // we are over central residue
161 if (!overx) {
162 nn+="x%";
163 overx=true;
164 } // end if over x
165 } // END IF J > X
166
167 if (j_shell==1) { // a direct 1st shell neighbour
168 ni++;
169 if (ni!=i) {// if this is NOT the one direct nb 2B dropped
170 nn+=j_res.toUpperCase()+"%"; // it is included
171 } else { // this one IS dropped
172 minus = j_num;
173 mres = j_res;
174 mss = j_sec;
175 mcn = j_cnsize;
176 } // end if ni!=i
177
178 } else { // 2nd shell neighbour
179 nj++;
180 if (nj==j) { // this is the 2nd shell nb 2B included
181 nn+=j_res.toUpperCase()+"%";
182 plus = j_num;
183 pres = j_res;
184 pss = j_sec;
185 pcn = j_cnsize;
186 } // end if
187
188 } // end if 1st/2nd shell
189
190 } // end while through the entire nbhood
191 if (!overx) { // in case x is the very last we haven't seen it yet
192 nn+="x%"; // add it in the end
193 overx=true;
194 } // end if over x
195 if (VL>=1) {
196 System.out.print("("+nn+")\t");
197 }
198
199 // Store the resulting move/nn
200 // insert into target_score values ( 1, 2, 'C', 0, 'A', 'H', 1, 2, 112, 'V', 'H', 3, 123, 'P', 'O', 2, 'TESTIT', 283, 12, 0, 0.00);
201 mst = conn.createStatement();
202
203 sql = "insert into target_score values ( "+cgraph_id+", "+cnode_id+", '"+ccid+"', "+cnum+"," +
204 " '"+cres+"', '"+csstype+"', "+i+", "+j+", "+
205 minus+", '"+mres+"', '"+mss+"', "+mcn+", "+
206 plus +", '"+pres+"', '"+pss+"', "+pcn+", "+
207 "'"+nn+"', 0, 0, 0, 0.00);";
208
209 // System.out.println(">"+sql);
210 mst.executeUpdate( sql);
211 mst.close();
212
213 } // close inner loop (i)
214 if (VL>=1) {
215 System.out.println(".");
216 } else {
217 System.out.print(".");
218 }
219 } // next outerloop (j)
220
221 rsst.close();
222 stmt.close();
223
224 } catch (SQLException e) {
225 e.printStackTrace();
226 System.err.println("SQLException: " + e.getMessage());
227 System.err.println("SQLState: " + e.getSQLState());
228 } // end try/catch
229
230 } // end writeMoves
231
232
233 } // end class
234
235
236 /*
237 drop table target_score;
238 CREATE TABLE `target_score` (
239 `graph_id` int(10) unsigned NOT NULL,
240 `node_id` int(10) unsigned DEFAULT NULL,
241 `cid` varchar(6) COLLATE latin1_general_cs NOT NULL,
242 `num` int(10) unsigned NOT NULL,
243 `res` char(1) COLLATE latin1_general_cs DEFAULT NULL,
244 `sstype` char(1) COLLATE latin1_general_cs DEFAULT NULL,
245 `i` int(2) NOT NULL DEFAULT '0',
246 `j` int(2) NOT NULL DEFAULT '0',
247 `minus` int(2) NOT NULL DEFAULT '0',
248 `mres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
249 `mss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
250 `mcn` int(2) NOT NULL DEFAULT '0',
251 `plus` int(2) NOT NULL DEFAULT '0',
252 `pres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
253 `pss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
254 `pcn` int(2) NOT NULL DEFAULT '0',
255 `nn` varchar(50) COLLATE latin1_general_cs,
256 `total` int(8) NOT NULL DEFAULT '0',
257 `rank` int(3) NOT NULL DEFAULT '0',
258 `deltarank` int(3) NOT NULL DEFAULT '0',
259 `score` decimal(6,2) NOT NULL DEFAULT '0.00'
260 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
261
262
263 */