ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/writeTargetMoves.java
Revision: 298
Committed: Wed Aug 22 14:55:01 2007 UTC (17 years, 6 months ago) by lappe
File size: 10102 byte(s)
Log Message:
only one out of both BB/SC insertion per moves based
on sc/bb domin. out of temp shell 
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 293 String sql, j_res, j_sec, mres, mss, pres, pss, nn, nb;
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     sql = "delete from target_score where graph_id="+cgraph_id+" and node_id="+cnode_id+" and cid='"+ccid+"' and num="+cnum+";";
125     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 273 ni=0; nj=0;
149     rsst.beforeFirst();
150 lappe 294
151 lappe 273 while (rsst.next()) {
152     j_num = rsst.getInt(1);
153     j_res = rsst.getString(2);
154 lappe 293 j_sec = rsst.getString(3);
155 lappe 273 j_shell = rsst.getInt(4);
156     j_cnsize = rsst.getInt(5);
157 lappe 294 j_bb = rsst.getInt(6);
158     j_sc = rsst.getInt(7);
159     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));
160 lappe 293
161 lappe 273 if (j_num>cnum) { // we are over central residue
162     if (!overx) {
163 lappe 293 nn+="x%";
164     nb+="x%";
165 lappe 273 overx=true;
166     } // end if over x
167     } // END IF J > X
168    
169     if (j_shell==1) { // a direct 1st shell neighbour
170     ni++;
171 lappe 293 if (ni!=i) {// if this is NOT the one direct nb 2B dropped
172 lappe 294 if (j_sc>=j_bb) { // SC dominated
173     nn+=j_res.toUpperCase()+"%"; // it is included
174     nb+=j_res.toUpperCase()+"%";
175     } else { // BB dominated
176     nn+=xlateSS( j_sec)+"%"; // it is included
177     nb+=xlateSS( j_sec)+"%";
178     } // end if SC/BB domin.
179 lappe 273 } else { // this one IS dropped
180     minus = j_num;
181     mres = j_res;
182     mss = j_sec;
183     mcn = j_cnsize;
184     } // end if ni!=i
185    
186     } else { // 2nd shell neighbour
187     nj++;
188     if (nj==j) { // this is the 2nd shell nb 2B included
189 lappe 298 if (j_sc>=j_bb) nn+=j_res.toUpperCase()+"%"; // SC dominated
190     else nn+=xlateSS(j_sec)+"%";
191 lappe 273 plus = j_num;
192     pres = j_res;
193     pss = j_sec;
194     pcn = j_cnsize;
195     } // end if
196    
197     } // end if 1st/2nd shell
198    
199     } // end while through the entire nbhood
200     if (!overx) { // in case x is the very last we haven't seen it yet
201 lappe 293 nn+="x%"; // add it in the end
202     nb+="x%";
203 lappe 273 overx=true;
204     } // end if over x
205     if (VL>=1) {
206 lappe 293 System.out.print("("+nn+")\t("+nb+")\t");
207 lappe 273 }
208    
209 lappe 293 // Store the resulting moves (nn for +SC, nb for +BB contact)
210 lappe 273 // 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);
211 lappe 294 // SC move into resulting table
212 lappe 273 mst = conn.createStatement();
213     sql = "insert into target_score values ( "+cgraph_id+", "+cnode_id+", '"+ccid+"', "+cnum+"," +
214     " '"+cres+"', '"+csstype+"', "+i+", "+j+", "+
215     minus+", '"+mres+"', '"+mss+"', "+mcn+", "+
216 lappe 298 plus +", '"+pres+"', '"+pss+"', "+pcn+", "+
217 lappe 273 "'"+nn+"', 0, 0, 0, 0.00);";
218    
219     // System.out.println(">"+sql);
220     mst.executeUpdate( sql);
221 lappe 293 mst.close();
222 lappe 298
223 lappe 273 } // close inner loop (i)
224     if (VL>=1) {
225     System.out.println(".");
226     } else {
227     System.out.print(".");
228     }
229     } // next outerloop (j)
230    
231     rsst.close();
232     stmt.close();
233    
234     } catch (SQLException e) {
235     e.printStackTrace();
236     System.err.println("SQLException: " + e.getMessage());
237     System.err.println("SQLState: " + e.getSQLState());
238     } // end try/catch
239    
240     } // end writeMoves
241    
242 lappe 293 public static String xlateSS( String sstype) { // xlate SecSTructure-Symbol
243     String SSymbol = "o";
244     sstype=sstype.toUpperCase();
245     if (sstype.equals("H")) SSymbol="z"; // Helix
246     if (sstype.equals("S")) SSymbol="b"; // beta strand
247     return SSymbol;
248     } // end xlateSS
249    
250 lappe 273 } // end class
251    
252    
253     /*
254     drop table target_score;
255     CREATE TABLE `target_score` (
256     `graph_id` int(10) unsigned NOT NULL,
257     `node_id` int(10) unsigned DEFAULT NULL,
258     `cid` varchar(6) COLLATE latin1_general_cs NOT NULL,
259     `num` int(10) unsigned NOT NULL,
260     `res` char(1) COLLATE latin1_general_cs DEFAULT NULL,
261     `sstype` char(1) COLLATE latin1_general_cs DEFAULT NULL,
262     `i` int(2) NOT NULL DEFAULT '0',
263     `j` int(2) NOT NULL DEFAULT '0',
264     `minus` int(2) NOT NULL DEFAULT '0',
265     `mres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
266     `mss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
267     `mcn` int(2) NOT NULL DEFAULT '0',
268     `plus` int(2) NOT NULL DEFAULT '0',
269     `pres` char(1) COLLATE latin1_general_cs DEFAULT NULL,
270     `pss` char(1) COLLATE latin1_general_cs DEFAULT NULL,
271     `pcn` int(2) NOT NULL DEFAULT '0',
272     `nn` varchar(50) COLLATE latin1_general_cs,
273     `total` int(8) NOT NULL DEFAULT '0',
274     `rank` int(3) NOT NULL DEFAULT '0',
275     `deltarank` int(3) NOT NULL DEFAULT '0',
276     `score` decimal(6,2) NOT NULL DEFAULT '0.00'
277     ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
278    
279    
280     */