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

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 rewriteNBHood_parallel {
8
9 /**
10 * reriting the nbhoodstring such that BB dominated nbs are represented by SSType
11 *
12 * @author lappe
13 */
14
15 static String user = "lappe" ; // change user name!!
16 static MySQLConnection conn;
17 static int k=0, k_sc=0, k_bb=0;
18 static String process, cid, res, sectype, fullnbs;
19 static int graph_id=0, node_id=0, resnr=0;
20
21
22 public static void main(String[] args) throws SQLException {
23 String nbhood = "", isql;
24 Statement istmt;
25
26 System.out.println("rewriteNBHood");
27 if (args.length!=1){
28 System.err.println("The processname has to be given .... i.e. tla01");
29 System.exit(1);
30 }
31 process = args[0];
32 System.out.println("processID="+process);
33
34 try {
35
36 conn = new MySQLConnection("white",user,"nieve","pdb_reps_graph_4_2");
37 node_id = getNextNode();
38 while (node_id>0) {
39 System.out.print(graph_id); // graph
40 System.out.print("\t"+node_id); // node
41 System.out.print("\t"+cid); // cid
42 System.out.print("\t"+resnr); // num
43 System.out.print("\t"+res); // res
44 System.out.print("\t"+sectype); // sstype
45 fullnbs = "";
46 nbhood= getSSNbHoodString( graph_id, node_id, resnr);
47
48 System.out.println("\t"+nbhood+"\t"+fullnbs);
49 istmt = conn.createStatement();
50 isql = "update single_model_cofull set k="+k+", k_bb="+k_bb+", k_sc="+k_sc+", n=\'"+nbhood+"\', nf=\'"+fullnbs+"\'" +
51 " where ( graph_id="+graph_id+" and node_id="+node_id+");";
52 // System.out.println("i>"+isql);
53 istmt.executeUpdate( isql);
54
55 node_id = getNextNode();
56 } // end while we have another node
57
58 } catch (SQLException e) {
59 e.printStackTrace();
60 System.err.println("SQLException: " + e.getMessage());
61 System.err.println("SQLState: " + e.getSQLState());
62 }
63
64 System.out.println("fin.");
65 }
66
67 public static int getNextNode() {
68 String sql;
69 Statement stmt;
70 ResultSet rsst;
71
72 graph_id=0;
73 node_id =0;
74 try {
75 sql = "update single_model_cofull set n=\'>"+process+"\' where length(n)=0 limit 1;";
76 stmt = conn.createStatement();
77 stmt.executeUpdate(sql);
78 sql = "select graph_id, node_id, cid, num, res, sstype from single_model_cofull where n=\'>"+process+"\';";
79 // System.out.println("node> "+ sql);
80 stmt = conn.createStatement();
81 rsst = stmt.executeQuery(sql);
82
83 if (rsst.next()) {
84 // System.out.print(">");
85 graph_id=rsst.getInt(1);
86 node_id =rsst.getInt(2);
87 cid =rsst.getString(3);
88 resnr =rsst.getInt(4);
89 res =rsst.getString(5);
90 sectype =rsst.getString(6);
91 }
92 } catch (SQLException e) {
93 e.printStackTrace();
94 System.err.println("SQLException: " + e.getMessage());
95 System.err.println("SQLState: " + e.getSQLState());
96 }
97 return node_id;
98 } // end of getnbhoodstring
99
100
101 public static String getSSNbHoodString( int gid, int nid, int num ) {
102 int j_num, j_bb, j_sc;
103 boolean overx=false;
104 String sql, nbs="", j_res, j_ss, nextnb;
105 Statement stmt;
106 ResultSet rsst;
107
108 try {
109 k=0; k_sc=0; k_bb=0;
110 sql = "select j_num, j_res, j_sstype, BB, SC from chain_edge where graph_id="+gid+" and i_node_id="+nid+" order by j_num;";
111 stmt = conn.createStatement();
112 rsst = stmt.executeQuery(sql);
113 fullnbs="";
114 while (rsst.next()) {
115 j_num = rsst.getInt(1);
116 j_res = rsst.getString(2);
117 j_ss = rsst.getString(3);
118 j_bb = rsst.getInt(4);
119 j_sc = rsst.getInt(5);
120 nextnb="?";
121 if (!overx && j_num>num) {
122 overx=true;
123 nbs+="x";
124 fullnbs+="x";
125 }
126 if ( (j_bb>j_sc) ) { // bb dominated -> only symbol for sstype
127 k_bb++;
128 nextnb="o"; // for "other"
129 if (j_ss.equals("H")) nextnb="z"; // Helix
130 if (j_ss.equals("S")) nextnb="b"; // beta strand
131 } else { // sc dominated contact
132 k_sc++;
133 nextnb=j_res;
134 } // end if bb dominated
135 nbs+= nextnb;
136 fullnbs+= j_res;
137 k++;
138 // System.out.print( nextnb);
139 }
140 rsst.close();
141 stmt.close();
142 if (!overx) {
143 nbs+="x"; // add if last in string == not seen yet
144 fullnbs+="x";
145 }
146
147 } catch (SQLException e) {
148 e.printStackTrace();
149 System.err.println("SQLException: " + e.getMessage());
150 System.err.println("SQLState: " + e.getSQLState());
151 }
152 return nbs;
153 } // end of getnbhoodstring
154 }