ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/rewriteNBHood.java
Revision: 492
Committed: Wed Jan 2 13:18:57 2008 UTC (16 years, 8 months ago) by duarte
File size: 6363 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 {
8
9 /**
10 * rewriting the nbhoodstring such that BB dominated nbs are represented by SSType
11 * only single gapsymbol is used for nbhood and fullstring _With _Gaps (nwg and fwg)
12 * output to stdout such that it can be read by
13 * mysql> load data infile '/scratch/local/cullpdb/cullpdb_20.nbhoods' into table nbstrings;
14 * see bottom for table definition
15 * @author lappe
16 */
17
18 static String user = "lappe", fullnbs="", gapnbs="", nums="", gaphood=""; // change user name!!
19 static MySQLConnection conn;
20 static int k=0, k_sc=0, k_bb=0;
21 static int minDmeansSC=10; // above this threshold contacts are assumed to be SC dominated
22 static String backgrndDB = "cullpdb_90";
23
24 public static void main(String[] args) throws SQLException {
25 String nbhood = "", msql, cid, res, sectype;
26 int graph_id=0, node_id=0, resnr=0;
27 // System.out.println("rewriteNBHood v.0.2");
28 conn = new MySQLConnection("white",user,"nieve", backgrndDB);
29 Statement mstmt;
30 ResultSet mrsst;
31
32 try {
33 msql = "select graph_id, node_id, cid, num, res, sstype from single_model_node where sstype is not null;";
34 // System.out.println("nodes> "+ msql);
35 mstmt = conn.createStatement();
36 mrsst = mstmt.executeQuery(msql);
37
38 while (mrsst.next()) {
39 // System.out.print(">");
40 graph_id=mrsst.getInt(1);
41 node_id =mrsst.getInt(2);
42 cid =mrsst.getString(3);
43 resnr =mrsst.getInt(4);
44 res =mrsst.getString(5);
45 sectype =mrsst.getString(6);
46 System.out.print(graph_id); // graph
47 System.out.print("\t"+node_id); // node
48 System.out.print("\t"+cid); // cid
49 System.out.print("\t"+resnr); // num
50 System.out.print("\t"+res); // res
51 System.out.print("\t"+sectype); // sstype
52
53 nbhood= getSSNbHoodString( graph_id, cid, resnr);
54 System.out.print("\t"+k);
55 System.out.print("\t"+k_bb);
56 System.out.print("\t"+k_sc);
57 System.out.print("\t"+nbhood);
58 System.out.print("\t"+gaphood);
59 System.out.print("\t"+fullnbs);
60 System.out.print("\t"+gapnbs);
61 // System.out.print("\t"+nums);
62 System.out.println();
63
64 }
65 mrsst.close();
66 mstmt.close();
67
68 } catch (SQLException e) {
69 e.printStackTrace();
70 System.err.println("SQLException: " + e.getMessage());
71 System.err.println("SQLState: " + e.getSQLState());
72 }
73
74 // System.out.println("fin.");
75 }
76
77 public static String getSSNbHoodString( int gid, String cid, int num ) {
78 int j_num, j_bb, j_sc, lastnum=0;
79 boolean overx=false;
80 String sql, nbs="", j_res, j_ss, nextnb, gapsym="", xgapsym="";
81 Statement stmt;
82 ResultSet rsst;
83
84 try {
85 k=0; k_sc=0; k_bb=0; // initialising the degreecounts with 0
86 sql = "select j_num, j_res, j_sstype, weight_BB, weight_SC from single_model_edge where graph_id="+gid+" and i_cid='"+cid+"' and i_num="+num+" order by j_num;";
87 stmt = conn.createStatement();
88 rsst = stmt.executeQuery(sql);
89 fullnbs="";
90 gapnbs="";
91 gaphood="";
92 nums="";
93 while (rsst.next()) {
94 gapsym="";
95 xgapsym="";
96 j_num = rsst.getInt(1);
97 j_res = rsst.getString(2);
98 j_ss = rsst.getString(3);
99 j_bb = rsst.getInt(4);
100 j_sc = rsst.getInt(5);
101 // System.out.print("\n-> "+j_res+" "+j_num+" "+j_ss+" "+"("+j_sc+"/"+j_bb+")");
102 nextnb="?";
103 if (lastnum>0 && ((j_num-lastnum)>=2)) gapsym="%";
104 if (!overx && j_num>num) {
105 overx=true;
106 nbs+="x";
107 fullnbs+="x";
108 nums+=(" ("+num+") ");
109 if (lastnum>0 && ((num-lastnum)>2)) xgapsym="%";
110 gapnbs+=xgapsym+"x";
111 gaphood+=xgapsym+"x";
112 gapsym="";
113 if ((j_num-num)>=2) gapsym="%";
114 }
115 // conversion of BB dominated contacts
116 if (j_sc==0 && j_bb==0) { // both values are 0 -> decide by sequence sparation
117 // System.out.print("SC&BB=0");
118 if ( Math.abs( num-j_num)>=minDmeansSC) {
119 nextnb=j_res;
120 k_sc++;
121 // System.out.print(" -> SC ");
122 } else {
123 nextnb=xlateSS( j_ss);
124 k_bb++;
125 // System.out.print(" -> BB ");
126 } // end if Math.abs( num-j_num)>=minDmeansSC
127 } else { // at least 1 value is non zero
128 // System.out.print("SC>0 or BB>0");
129 if ( (j_bb>j_sc) ) { // bb dominated -> only symbol for sstype
130 k_bb++;
131 nextnb=xlateSS( j_ss);
132 // System.out.print(" -> BB ");
133 } else { // sc dominated contact
134 k_sc++;
135 nextnb=j_res;
136 // System.out.print(" -> SC ");
137 } // end if bb dominated
138 } // end if we have non-zero entries
139 // System.out.print(" : "+nextnb);
140 nbs+= nextnb;
141 nums+=" "+j_num;
142 fullnbs+= j_res;
143 k++;
144
145 gapnbs+=gapsym+j_res;
146 gaphood+=gapsym+nextnb;
147 lastnum=j_num;
148 // System.out.print( nextnb);
149 }
150 rsst.close();
151 stmt.close();
152 if (!overx) {
153 nbs+="x"; // add if last in string == not seen yet
154 fullnbs+="x";
155 if (lastnum>0 && ((num-lastnum)==2)) xgapsym="_";
156 if (lastnum>0 && ((num-lastnum)>2)) xgapsym="%";
157 gapnbs+=xgapsym+"x";
158 gaphood+=xgapsym+"x";
159 }
160
161 } catch (SQLException e) {
162 e.printStackTrace();
163 System.err.println("SQLException: " + e.getMessage());
164 System.err.println("SQLState: " + e.getSQLState());
165 }
166 return nbs;
167 } // end of getnbhoodstring
168
169 public static String xlateSS( String sstype) { // xlate SecSTructure-Symbol
170 String SSymbol = "o";
171 sstype=sstype.toUpperCase();
172 if (sstype.equals("H")) SSymbol="z"; // Helix
173 if (sstype.equals("S")) SSymbol="b"; // beta strand
174 return SSymbol;
175 } // end xlateSS
176
177 } // end
178
179 /* table definition for the results
180
181 CREATE TABLE `nbstrings` (
182 `graph_id` int(10) unsigned DEFAULT NULL,
183 `node_id` int(10) unsigned DEFAULT NULL,
184 `cid` varchar(6) COLLATE latin1_general_cs DEFAULT NULL,
185 `num` int(10) unsigned DEFAULT NULL,
186 `res` char(1) COLLATE latin1_general_cs DEFAULT NULL,
187 `sstype` char(1) COLLATE latin1_general_cs DEFAULT NULL,
188 `k` int(10) unsigned DEFAULT NULL,
189 `k_BB` int(10) unsigned DEFAULT NULL,
190 `k_SC` int(10) unsigned DEFAULT NULL,
191 `n` varchar(30) COLLATE latin1_general_cs DEFAULT NULL,
192 `nwg` varchar(40) COLLATE latin1_general_cs DEFAULT NULL,
193 `f` varchar(30) COLLATE latin1_general_cs DEFAULT NULL,
194 `fwg` varchar(40) COLLATE latin1_general_cs DEFAULT NULL
195 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
196
197 */