ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/iterateNbhood.java
Revision: 166
Committed: Thu May 24 16:19:00 2007 UTC (17 years, 9 months ago) by lappe
File size: 3483 byte(s)
Log Message:
First version of exchange routine contact vs. CN - non functional 
Line User Rev File contents
1 lappe 166 import tools.MySQLConnection;
2    
3     import java.sql.SQLException;
4     import java.sql.Statement;
5     import java.sql.ResultSet;
6    
7     public class iterateNbhood {
8    
9     /**
10     *
11     * exchange of one neighbor at a time by a common neighbor
12     * @author lappe
13     */
14    
15     static String user = "lappe" ; // change user name!!
16     static MySQLConnection conn;
17    
18    
19     public static void main(String[] args) {
20    
21     if (args.length<2){
22     System.err.println("The graph_id and residue-nr. needs to be given .... i.e. 9 28");
23     System.exit(1);
24     }
25     int graphid = Integer.parseInt( args[0]);
26     int resnr = Integer.parseInt( args[1]);
27     int n1=0, n2=0, ni=0, nj=0, j_num=0, lastNum=0, i, j;
28     conn = new MySQLConnection("white",user,"nieve","pdb_reps_graph_4_2_a");
29     String sql, j_res;
30     Statement stmt, jst;
31     ResultSet rsst, jrs;
32    
33     try {
34     System.out.println("getting direct neighborhood ... ");
35     stmt = conn.createStatement();
36     stmt.executeUpdate("drop table if exists temp_shell;");
37     stmt.close();
38    
39     stmt = conn.createStatement();
40     stmt.executeUpdate("create table temp_shell as select i_num, i_res, j_num, j_res, j_sstype, 1 as shell from single_model_edge where graph_id="+graphid+" and i_num="+resnr+";");
41     stmt.close();
42    
43     System.out.println("building the 2nd shell");
44     sql = "select j_num, j_res, j_sstype from temp_shell where shell=1;";
45     stmt = conn.createStatement();
46     rsst = stmt.executeQuery(sql);
47     while (rsst.next()) {
48     n1++;
49     j_num = rsst.getInt(1);
50     System.out.println(n1+":"+j_num);
51     jst = conn.createStatement();
52     sql = "insert into temp_shell select i_num, i_res, j_num, j_res, j_sstype, 2 as shell from single_model_edge where graph_id="+graphid+" and i_num="+j_num+";";
53     // System.out.println(">"+sql);
54     jst.executeUpdate( sql);
55     jst.close();
56     } // end while
57     rsst.close();
58     stmt.close();
59    
60     System.out.println("geting the entire 2st and 2nd shell");
61     sql = "select j_num, j_res, j_sstype, min(shell) as shell, count(*) as cn from temp_shell group by j_num;";
62     stmt = conn.createStatement();
63     rsst = stmt.executeQuery(sql);
64     // counting shell2
65     n2=0;
66     while (rsst.next()) {
67     if ( rsst.getInt( 4)==2) n2++;
68     System.out.println(n2+":"+rsst.getInt( 1)+"\t"+rsst.getString( 2)+"\t"+rsst.getString( 3)+"\t"+rsst.getInt( 4)+"\t"+rsst.getInt( 5));
69     } // end while
70     System.out.println("SIZE 1st shell "+n1);
71     System.out.println("SIZE 2nd shell "+n2);
72    
73     for (i=0; i<=n1; i++) { // 1st loop through all direct contacts
74     System.out.print(i+" - ");
75     for (j=1; j<=n2; j++) { // 2nd loop through all indirect contacts
76     System.out.print(j+":");
77    
78     // if j_num == resnr -> then x
79     /*
80     lastNum=0;
81     nj = 0;
82     rsst.beforeFirst();
83     while (rsst.next()) {
84     nj++;
85     j_num = rsst.getInt( 1);
86     j_res = rsst.getString(2);
87     if (nj!=i) { // this is the neighbor 2 B dropped
88     if (lastNum<resnr && resnr<j_num) {
89     System.out.print("%"+nj+"x");
90     }
91     System.out.print("%"+j_res);
92     }
93     lastNum = j_num;
94     } // end while
95     */
96    
97    
98     } // close for loop 2 (j)
99     System.out.println(".");
100     } // next loop 1 (i)
101     rsst.close();
102     stmt.close();
103    
104     // Summarize
105    
106    
107    
108     } catch (SQLException e) {
109     e.printStackTrace();
110     System.err.println("SQLException: " + e.getMessage());
111     System.err.println("SQLState: " + e.getSQLState());
112     } // end try/catch
113     System.out.println("fin.");
114     }
115    
116    
117    
118     }