ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/writeTargetMoves.java
Revision: 492
Committed: Wed Jan 2 13:18:57 2008 UTC (16 years, 10 months ago) by duarte
File size: 10441 byte(s)
Log Message:
Copied the aglappe-jung branch into trunk.

Line User Rev File contents
1 lappe 273 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 lappe 293 static String backgrndDB = "CASP_decoys";
19 lappe 273 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     try {
32     conn = new MySQLConnection("white",user,"nieve", backgrndDB); // the UPPERCASE DB!
33 lappe 293 System.out.println("Writing Target neighborhoods v.0.2. (SC&BB)");
34 lappe 273 // retrieve node_id | cid | res | sstype defined by graph_id, num
35 lappe 294 // sql = "select node_id, cid, num, res, sstype from "+targetNodes+" where graph_id="+graph_id+" limit 3;";
36     sql = "select graph_id, node_id, cid, num, res, sstype from "+targetNodes+";"; // +" limit 1;";
37 lappe 273 mstmt = conn.createStatement();
38     mrsst = mstmt.executeQuery(sql);
39     while (mrsst.next()) {
40     // this is the central node -> get type and secondary structure
41 lappe 294 graph_id = mrsst.getInt( 1);
42     node_id = mrsst.getInt( 2);
43     cid = mrsst.getString( 3);
44     num = mrsst.getInt( 4);
45     res = mrsst.getString( 5).toUpperCase();
46     sstype= mrsst.getString( 6).toUpperCase();
47 lappe 273 System.out.println("GraphID "+graph_id+" Chain "+cid+", Central residue ("+node_id+") "+res+":"+num+":"+sstype);
48     writeMoves( graph_id, node_id, cid, num, res, sstype);
49     } // end if central residue
50     mrsst.close();
51     mstmt.close();
52     } catch (SQLException e) {
53     e.printStackTrace();
54     System.err.println("SQLException: " + e.getMessage());
55     System.err.println("SQLState: " + e.getSQLState());
56     } // end try/catch
57     System.out.println("fin.");
58     } // end main
59    
60    
61    
62     public static void writeMoves( int cgraph_id, int cnode_id, String ccid, int cnum, String cres, String csstype) {
63 lappe 294 int n1=0, n2=0, ni=0, nj=0, i=0, j=0, j_num=0, j_shell=0, j_cnsize=0, j_bb, j_sc;
64 lappe 273 int minus, mcn, plus, pcn;
65 lappe 313 String sql, j_res, j_sec, mres, mss, pres, pss, nn, nb, nextn, lastn="", iks;
66 lappe 273 boolean overx = false;
67     Statement stmt, mst;
68     ResultSet rsst;
69    
70     try {
71    
72     // retrieve the original nbhood into orig_shell
73     System.out.println("retrieving first shell ... ");
74     stmt = conn.createStatement();
75     stmt.executeUpdate("drop table if exists temp_shell;");
76     stmt.close();
77    
78     stmt = conn.createStatement();
79 lappe 294 // 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+";");
80     stmt.executeUpdate("create table temp_shell as select i_num, i_res, j_num, j_res, j_sstype, 1 as shell, weight_bb as BB, weight_SC as SC " +
81     "from "+targetEdges+" where graph_id="+cgraph_id+" and i_cid='"+ccid+"' and i_num="+cnum+";");
82 lappe 273 stmt.close();
83    
84     System.out.println("adding the 2nd shell ...");
85     sql = "select j_num from temp_shell where shell=1;";
86     stmt = conn.createStatement();
87     rsst = stmt.executeQuery(sql);
88     i=0;
89     while (rsst.next()) {
90     i++;
91     j_num = rsst.getInt(1);
92     System.out.println(i+":"+j_num);
93     mst = conn.createStatement();
94 lappe 294 sql = "insert into temp_shell select i_num, i_res, j_num, j_res, j_sstype, 2 as shell, weight_bb as BB, weight_SC as SC " +
95     "from "+targetEdges+" where graph_id="+cgraph_id+" and i_cid='"+ccid+"' and i_num="+j_num+";";
96 lappe 273 // System.out.println(">"+sql);
97     mst.executeUpdate( sql);
98     mst.close();
99     } // end while
100     rsst.close();
101     stmt.close();
102    
103     System.out.println("retrieving the entire nbhood (1st and 2nd shell)");
104 lappe 294 sql = "select j_num, j_res, j_sstype, min(shell) as shell, count(*) as cn, max(BB) as BB, max(SC) as SC " +
105     "from temp_shell where j_num!="+cnum+" group by j_num order by j_num;";
106 lappe 273 stmt = conn.createStatement();
107     rsst = stmt.executeQuery(sql);
108     n1=0;
109     n2=0;
110     while (rsst.next()) {
111     if ( rsst.getInt( 4)==1) { // count 1st shell entry
112     n1++;
113     System.out.print("1#"+n1);
114     } // end if 2st shell
115     if ( rsst.getInt( 4)==2) { // count 2nd shell entry
116     n2++;
117     System.out.print("2#"+n2);
118     } // end if 2nd shell
119 lappe 294 System.out.println(" :\t"+rsst.getInt( 1)+"\t"+rsst.getString( 2)+"\t"+rsst.getString( 3)+"\t"+rsst.getInt( 4)+"\t"+rsst.getInt( 5)+"\t"+rsst.getInt( 6)+"\t"+rsst.getInt( 7));
120 lappe 273 } // end while
121    
122     System.out.println("|1st shell|="+n1+" \tx\t |2nd shell|="+n2);
123     mst = conn.createStatement();
124 lappe 313 sql = "delete from target_short where graph_id="+cgraph_id+" and node_id="+cnode_id+" and cid='"+ccid+"' and num="+cnum+";";
125 lappe 273 System.out.println(">"+sql);
126     mst.executeUpdate( sql);
127     mst.close();
128    
129     cn1 = new int[n1+1];
130     cn2 = new int[n2+1];
131     // minus | mres | mss | mcn | plus | pres | pss | pcn | nn
132     for (j=0; j<=n2; j++) { // outer loop through all indirect contacts
133     for (i=0; i<=n1; i++) { // inner loop through all direct contacts
134     overx = false;
135     if (VL>=1) {
136     System.out.print("("+i+","+j+")\t");
137     }
138     minus = 0;
139     mres = "";
140     mss = "";
141     mcn = n1;
142     plus = 0;
143     pres = "";
144     pss = "";
145     pcn = n1;
146     nn="%";
147 lappe 293 nb="%";
148 lappe 313 ni=0; nj=0;
149     lastn="??";
150     nextn="";
151     iks="";
152 lappe 273 rsst.beforeFirst();
153 lappe 294
154 lappe 273 while (rsst.next()) {
155     j_num = rsst.getInt(1);
156     j_res = rsst.getString(2);
157 lappe 293 j_sec = rsst.getString(3);
158 lappe 273 j_shell = rsst.getInt(4);
159     j_cnsize = rsst.getInt(5);
160 lappe 294 j_bb = rsst.getInt(6);
161     j_sc = rsst.getInt(7);
162 lappe 313
163 lappe 294 if (VL>=2) System.out.print("\n"+rsst.getInt( 1)+"\t"+rsst.getString( 2)+"\t"+rsst.getString( 3)+"\t"+rsst.getInt( 4)+"\t"+rsst.getInt( 5)+"\t"+rsst.getInt( 6)+"\t"+rsst.getInt( 7));
164 lappe 293
165 lappe 313 iks="";
166 lappe 273 if (j_num>cnum) { // we are over central residue
167     if (!overx) {
168 lappe 313 iks="x%";
169 lappe 293 nb+="x%";
170 lappe 273 overx=true;
171     } // end if over x
172     } // END IF J > X
173    
174     if (j_shell==1) { // a direct 1st shell neighbour
175     ni++;
176 lappe 293 if (ni!=i) {// if this is NOT the one direct nb 2B dropped
177 lappe 294 if (j_sc>=j_bb) { // SC dominated
178 lappe 313 nextn=j_res.toUpperCase()+"%"; // it is included
179 lappe 294 nb+=j_res.toUpperCase()+"%";
180     } else { // BB dominated
181 lappe 313 nextn=xlateSS( j_sec)+"%"; // it is included
182 lappe 294 nb+=xlateSS( j_sec)+"%";
183     } // end if SC/BB domin.
184 lappe 273 } else { // this one IS dropped
185     minus = j_num;
186     mres = j_res;
187     mss = j_sec;
188     mcn = j_cnsize;
189     } // end if ni!=i
190    
191     } else { // 2nd shell neighbour
192     nj++;
193     if (nj==j) { // this is the 2nd shell nb 2B included
194 lappe 313 if (j_sc>=j_bb) {
195     nextn=j_res.toUpperCase()+"%"; // SC dominated
196     nb += j_res.toUpperCase()+"%";
197     }
198     else {
199     nextn=xlateSS(j_sec)+"%";
200     nb+=xlateSS( j_sec)+"%";
201     }
202 lappe 273 plus = j_num;
203     pres = j_res;
204     pss = j_sec;
205     pcn = j_cnsize;
206     } // end if
207    
208     } // end if 1st/2nd shell
209 lappe 313 nn+=iks;
210     if (!lastn.equals( nextn)) {
211     nn+=nextn;
212     }
213     lastn = nextn;
214     nextn="";
215 lappe 273 } // end while through the entire nbhood
216     if (!overx) { // in case x is the very last we haven't seen it yet
217 lappe 293 nn+="x%"; // add it in the end
218     nb+="x%";
219 lappe 273 overx=true;
220     } // end if over x
221 lappe 313
222 lappe 273 if (VL>=1) {
223 lappe 293 System.out.print("("+nn+")\t("+nb+")\t");
224 lappe 273 }
225    
226 lappe 293 // Store the resulting moves (nn for +SC, nb for +BB contact)
227 lappe 313 // insert into target_short values ( 1, 2, 'C', 0, 'A', 'H', 1, 2, 112, 'V', 'H', 3, 123, 'P', 'O', 2, 'TESTIT', 283, 12, 0, 0.00);
228 lappe 294 // SC move into resulting table
229 lappe 273 mst = conn.createStatement();
230 lappe 313 sql = "insert into target_short values ( "+cgraph_id+", "+cnode_id+", '"+ccid+"', "+cnum+"," +
231 lappe 273 " '"+cres+"', '"+csstype+"', "+i+", "+j+", "+
232     minus+", '"+mres+"', '"+mss+"', "+mcn+", "+
233 lappe 298 plus +", '"+pres+"', '"+pss+"', "+pcn+", "+
234 lappe 273 "'"+nn+"', 0, 0, 0, 0.00);";
235    
236 lappe 313 if (VL>=2) System.out.println(">"+sql);
237 lappe 273 mst.executeUpdate( sql);
238 lappe 293 mst.close();
239 lappe 298
240 lappe 273 } // close inner loop (i)
241     if (VL>=1) {
242     System.out.println(".");
243     } else {
244     System.out.print(".");
245     }
246     } // next outerloop (j)
247    
248     rsst.close();
249     stmt.close();
250    
251     } catch (SQLException e) {
252     e.printStackTrace();
253     System.err.println("SQLException: " + e.getMessage());
254     System.err.println("SQLState: " + e.getSQLState());
255     } // end try/catch
256    
257     } // end writeMoves
258    
259 lappe 293 public static String xlateSS( String sstype) { // xlate SecSTructure-Symbol
260     String SSymbol = "o";
261     sstype=sstype.toUpperCase();
262     if (sstype.equals("H")) SSymbol="z"; // Helix
263     if (sstype.equals("S")) SSymbol="b"; // beta strand
264     return SSymbol;
265     } // end xlateSS
266    
267 lappe 273 } // end class
268    
269    
270     /*
271     drop table target_score;
272     CREATE TABLE `target_score` (
273     `graph_id` int(10) unsigned NOT NULL,
274     `node_id` int(10) unsigned DEFAULT NULL,
275     `cid` varchar(6) COLLATE latin1_general_cs NOT NULL,
276     `num` int(10) unsigned NOT NULL,
277     `res` char(1) COLLATE latin1_general_cs DEFAULT NULL,
278     `sstype` char(1) COLLATE latin1_general_cs DEFAULT NULL,
279     `i` int(2) NOT NULL DEFAULT '0',
280     `j` int(2) NOT NULL DEFAULT '0',
281     `minus` int(2) NOT NULL DEFAULT '0',
282     `mres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
283     `mss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
284     `mcn` int(2) NOT NULL DEFAULT '0',
285     `plus` int(2) NOT NULL DEFAULT '0',
286     `pres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
287     `pss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
288     `pcn` int(2) NOT NULL DEFAULT '0',
289     `nn` varchar(50) COLLATE latin1_general_cs,
290     `total` int(8) NOT NULL DEFAULT '0',
291     `rank` int(3) NOT NULL DEFAULT '0',
292     `deltarank` int(3) NOT NULL DEFAULT '0',
293     `score` decimal(6,2) NOT NULL DEFAULT '0.00'
294     ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
295    
296    
297     */