ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/AA.java
Revision: 135
Committed: Mon May 14 09:49:04 2007 UTC (17 years, 4 months ago) by duarte
File size: 7097 byte(s)
Log Message:
NEW FUNCTIONALITY: reading of graph from db is fully implemented for all cases

New chain member variable in the Info classes, read in get_asym_id (Pdbase) and in get_chain_id (Msdsd)
Reading chain also in Pdb in read_pdb_data_from_file
Not reading chain anymore in read_atomData of PdbaseInfo
Added oneletter2threeletter and getoneletter2threeletter to AA class
Changes in Graph:
- added db static vars and getUserName method
- new member variables graphid and sm_id
- new method read_graph_from_db to read contacts, nodes (and sequence from nodes) from db
- new method getgraphid
New Exception class GraphIdNotFoundError
Line User Rev File contents
1 duarte 123 package proteinstructure;
2     import java.sql.ResultSet;
3     import java.sql.SQLException;
4     import java.sql.Statement;
5     import java.util.HashMap;
6     import java.util.ArrayList;
7     import tools.MySQLConnection;
8    
9     public class AA {
10    
11     public final static String MYSQLSERVER="white";
12 duarte 126 public final static String MYSQLUSER=getUserName();
13 duarte 123 public final static String MYSQLPWD="nieve";
14     public final static String DB = "aa_info";
15    
16     //public static final ArrayList<String> AAS = aas();
17     //public static final HashMap<String,String> THREELETTER2ONELETTER = threeletter2oneletter();
18 duarte 126
19     /** get user name from operating system (for use as database username) */
20     private static String getUserName() {
21     String user = null;
22     user = System.getProperty("user.name");
23     if(user == null) {
24     System.err.println("Could not get user name from operating system. Exiting");
25     System.exit(1);
26     }
27     return user;
28     }
29 duarte 123
30     public static HashMap<String,String> getThreeletter2oneletter() {
31     HashMap<String,String> three2oneletter = new HashMap<String,String>();
32     three2oneletter.put("CYS", "C");
33     three2oneletter.put("ASP", "D");
34     three2oneletter.put("SER", "S");
35     three2oneletter.put("GLN", "Q");
36     three2oneletter.put("LYS", "K");
37     three2oneletter.put("ILE", "I");
38     three2oneletter.put("PRO", "P");
39     three2oneletter.put("THR", "T");
40     three2oneletter.put("PHE", "F");
41     three2oneletter.put("ALA", "A");
42     three2oneletter.put("GLY", "G");
43     three2oneletter.put("HIS", "H");
44     three2oneletter.put("GLU", "E");
45     three2oneletter.put("LEU", "L");
46     three2oneletter.put("ARG", "R");
47     three2oneletter.put("TRP", "W");
48     three2oneletter.put("VAL", "V");
49     three2oneletter.put("ASN", "N");
50     three2oneletter.put("TYR", "Y") ;
51     three2oneletter.put("MET", "M");
52     return three2oneletter;
53     }
54    
55     public static String threeletter2oneletter(String three) {
56     HashMap<String,String> three2oneletter = getThreeletter2oneletter();
57     return three2oneletter.get(three);
58     }
59    
60 duarte 135 public static HashMap<String,String> getOneletter2Threeletter(){
61     HashMap<String,String> one2threeletter = new HashMap<String,String>();
62     one2threeletter.put("C", "CYS");
63     one2threeletter.put("D", "ASP");
64     one2threeletter.put("S", "SER");
65     one2threeletter.put("Q", "GLN");
66     one2threeletter.put("K", "LYS");
67     one2threeletter.put("I", "ILE");
68     one2threeletter.put("P", "PRO");
69     one2threeletter.put("T", "THR");
70     one2threeletter.put("F", "PHE");
71     one2threeletter.put("A", "ALA");
72     one2threeletter.put("G", "GLY");
73     one2threeletter.put("H", "HIS");
74     one2threeletter.put("E", "GLU");
75     one2threeletter.put("L", "LEU");
76     one2threeletter.put("R", "ARG");
77     one2threeletter.put("W", "TRP");
78     one2threeletter.put("V", "VAL");
79     one2threeletter.put("N", "ASN");
80     one2threeletter.put("Y", "TYR");
81     one2threeletter.put("M", "MET");
82     return one2threeletter;
83     }
84    
85     public static String oneletter2threeletter(String one) {
86     HashMap<String,String> one2threeletter = getOneletter2Threeletter();
87     return one2threeletter.get(one);
88     }
89    
90 duarte 123 public static ArrayList<String> aas() {
91     HashMap<String,String> three2oneletter = getThreeletter2oneletter();
92     ArrayList<String> aas = new ArrayList<String>();
93     for (String aa:three2oneletter.keySet()) {
94     aas.add(aa);
95     }
96     return aas;
97     }
98    
99     public static HashMap<String,ArrayList<String>> getaas2atoms() {
100     HashMap<String,ArrayList<String>> aas2atoms = new HashMap<String,ArrayList<String>>();
101     MySQLConnection conn = new MySQLConnection(MYSQLSERVER,MYSQLUSER,MYSQLPWD,DB);
102     String sql="SELECT code_3_letter, group_concat(chem_atom_name) FROM atom_names GROUP BY code_3_letter ORDER BY code_3_letter";
103     try {
104     Statement stmt = conn.createStatement();
105     ResultSet rsst = stmt.executeQuery(sql);
106     while (rsst.next()) {
107     String res_type=rsst.getString(1);
108     String atomsStr = rsst.getString(2);
109     String[] atoms = atomsStr.split(",");
110     ArrayList<String> atomsAL = new ArrayList<String>();
111     for (String atom:atoms){
112     if (! atom.equals("OXT")){
113     atomsAL.add(atom);
114     }
115     }
116     aas2atoms.put(res_type, atomsAL);
117     }
118     rsst.close();
119     stmt.close();
120     } catch (SQLException e) {
121     e.printStackTrace();
122     }
123     conn.close();
124     return aas2atoms;
125    
126     }
127    
128     public static HashMap<String,String[]> ct2atoms(String ct) {
129     ArrayList<String> aas = aas();
130     HashMap<String,String[]> ct2atoms = new HashMap<String,String[]>();
131     if (ct.equals("Ca")){
132     String[] atoms = {"CA"};
133     for (String aa:aas) {
134     ct2atoms.put(aa, atoms);
135     }
136     }
137     else if (ct.equals("Cb")){
138     String[] atoms = {"CB"};
139     for (String aa:aas) {
140     ct2atoms.put(aa, atoms);
141     }
142     atoms = new String[1];
143     atoms[0]="CA";
144     ct2atoms.put("GLY", atoms);
145     }
146     else if (ct.equals("C")){
147     String[] atoms = {"C"};
148     for (String aa:aas) {
149     ct2atoms.put(aa, atoms);
150     }
151     }
152     else if (ct.equals("Cg")){
153     String[] atoms = {"SG"};
154     ct2atoms.put("CYS", atoms);
155     atoms = new String[1];
156     atoms[0]= "CG";
157     ct2atoms.put("ASP", atoms);
158     atoms = new String[1];
159     atoms[0]="OG";
160     ct2atoms.put("SER", atoms);
161     atoms = new String[1];
162     atoms[0]="CG";
163     ct2atoms.put("GLN", atoms);
164     atoms = new String[1];
165     atoms[0]="CD";
166     ct2atoms.put("LYS", atoms);
167     atoms = new String[1];
168     atoms[0]="CG1";
169     ct2atoms.put("ILE", atoms);
170     atoms = new String[1];
171     atoms[0]="CG";
172     ct2atoms.put("PRO", atoms);
173     atoms = new String[1];
174     atoms[0]="OG1";
175     ct2atoms.put("THR", atoms);
176     atoms = new String[1];
177     atoms[0]="CG";
178     ct2atoms.put("PHE", atoms);
179     ct2atoms.put("ALA", new String[0]);
180     ct2atoms.put("GLY", new String[0]);
181     atoms = new String[1];
182     atoms[0]="CG";
183     ct2atoms.put("HIS", atoms);
184     atoms = new String[1];
185     atoms[0]="CG";
186     ct2atoms.put("GLU", atoms);
187     atoms = new String[1];
188     atoms[0]="CG";
189     ct2atoms.put("LEU", atoms);
190     atoms = new String[1];
191     atoms[0]="NE";
192     ct2atoms.put("ARG", atoms);
193     atoms = new String[1];
194     atoms[0]="CD2";
195     ct2atoms.put("TRP", atoms);
196     atoms = new String[1];
197     atoms[0]="CG1";
198     ct2atoms.put("VAL", atoms);
199     atoms = new String[1];
200     atoms[0]="CG";
201     ct2atoms.put("ASN", atoms);
202     atoms = new String[1];
203     atoms[0]="CG";
204     ct2atoms.put("TYR", atoms);
205     atoms = new String[1];
206     atoms[0]="CG";
207     ct2atoms.put("MET", atoms);
208     }
209     else if (ct.equals("BB")){
210     String[] atoms = {"CA", "N", "C", "O"};
211     for (String aa:aas) {
212     ct2atoms.put(aa, atoms);
213     }
214     }
215     else if (ct.equals("SC")){
216     HashMap<String,ArrayList<String>> aas2atoms = getaas2atoms();
217     for (String aa:aas) {
218     ArrayList<String> SCatoms =aas2atoms.get(aa);
219     SCatoms.remove("CA");
220     SCatoms.remove("N");
221     SCatoms.remove("C");
222     SCatoms.remove("O");
223     String[] SCatomsar= new String[SCatoms.size()];
224     SCatomsar=SCatoms.toArray(SCatomsar);
225     ct2atoms.put(aa, SCatomsar);
226     }
227     }
228     else if (ct.equals("ALL")){
229     HashMap<String,ArrayList<String>> aas2atoms = getaas2atoms();
230     for (String aa:aas) {
231     ArrayList<String> ALLatoms = aas2atoms.get(aa);
232     String[] ALLatomsar= new String[ALLatoms.size()];
233     ALLatomsar=ALLatoms.toArray(ALLatomsar);
234     ct2atoms.put(aa,ALLatomsar);
235     }
236     }
237     return ct2atoms;
238     }
239     }