1 |
duarte |
277 |
import gnu.getopt.Getopt; |
2 |
|
|
|
3 |
|
|
import java.io.File; |
4 |
|
|
import java.io.IOException; |
5 |
|
|
import java.sql.SQLException; |
6 |
|
|
|
7 |
|
|
import proteinstructure.Pdb; |
8 |
|
|
import proteinstructure.PdbCodeNotFoundError; |
9 |
duarte |
441 |
import proteinstructure.PdbLoadError; |
10 |
duarte |
277 |
import proteinstructure.PdbasePdb; |
11 |
|
|
import proteinstructure.PdbfilePdb; |
12 |
duarte |
420 |
import proteinstructure.RIGraph; |
13 |
duarte |
609 |
import proteinstructure.TemplateList; |
14 |
duarte |
277 |
import tools.MySQLConnection; |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
public class genGraph { |
18 |
|
|
/*------------------------------ constants ------------------------------*/ |
19 |
|
|
|
20 |
|
|
public static final String PDB_DB = "pdbase"; |
21 |
|
|
public static final String DB_HOST = "white"; |
22 |
|
|
public static final String DB_USER = getUserName(); |
23 |
|
|
public static final String DB_PWD = "nieve"; |
24 |
|
|
|
25 |
|
|
/*---------------------------- private methods --------------------------*/ |
26 |
|
|
/** |
27 |
|
|
* Get user name from operating system (for use as database username). |
28 |
|
|
* */ |
29 |
|
|
private static String getUserName() { |
30 |
|
|
String user = null; |
31 |
|
|
user = System.getProperty("user.name"); |
32 |
|
|
if(user == null) { |
33 |
|
|
System.err.println("Could not get user name from operating system."); |
34 |
|
|
} |
35 |
|
|
return user; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
public static void main(String[] args) throws IOException { |
39 |
|
|
|
40 |
duarte |
599 |
String progName = "genGraph"; |
41 |
duarte |
277 |
|
42 |
|
|
String help = "Usage, 3 options:\n" + |
43 |
duarte |
609 |
"1) "+progName+" -i <listfile> -d <distance_cutoff> -t <contact_type> [-o <output_dir>] [-D <pdbase_db>] [-P] \n" + |
44 |
|
|
"2) "+progName+" -p <pdb_code> -d <distance_cutoff> -t <contact_type> [-o <output_dir>] [-D <pdbase_db>] [-P] \n" + |
45 |
|
|
"3) "+progName+" -f <pdbfile> [-c <chain_pdb_code>] -d <distance_cutoff> -t <contact_type> [-o <output_dir>] [-P] \n\n" + |
46 |
|
|
"In case 2) also a list of comma separated pdb codes+chain codes can be specified, e.g. -p 1bxyA,1josA \n" + |
47 |
|
|
"In case 3) if -c not specified then the first chain code in the pdb file will be taken\n" + |
48 |
duarte |
599 |
"If pdbase_db not specified, the default pdbase will be used\n" + |
49 |
duarte |
609 |
"If output dir not specified default is current\n" + |
50 |
duarte |
600 |
"In all cases option -P can be specified to get the graph in paul format instead of aglappe format\n"; |
51 |
duarte |
277 |
|
52 |
|
|
String listfile = ""; |
53 |
duarte |
609 |
String[] pdbIds = null; |
54 |
|
|
String pdbChainCode4file = null; |
55 |
duarte |
277 |
String pdbfile = ""; |
56 |
|
|
String pdbaseDb = PDB_DB; |
57 |
|
|
String edgeType = ""; |
58 |
|
|
double cutoff = 0.0; |
59 |
duarte |
609 |
String outputDir = "."; // we set default to current directory |
60 |
duarte |
599 |
boolean paul = false; |
61 |
duarte |
277 |
|
62 |
duarte |
599 |
Getopt g = new Getopt(progName, args, "i:p:c:f:d:t:o:D:Ph?"); |
63 |
duarte |
277 |
int c; |
64 |
|
|
while ((c = g.getopt()) != -1) { |
65 |
|
|
switch(c){ |
66 |
|
|
case 'i': |
67 |
|
|
listfile = g.getOptarg(); |
68 |
|
|
break; |
69 |
|
|
case 'p': |
70 |
duarte |
609 |
pdbIds = g.getOptarg().split(","); |
71 |
duarte |
277 |
break; |
72 |
|
|
case 'c': |
73 |
duarte |
609 |
pdbChainCode4file = g.getOptarg(); |
74 |
duarte |
277 |
break; |
75 |
|
|
case 'f': |
76 |
|
|
pdbfile = g.getOptarg(); |
77 |
|
|
break; |
78 |
|
|
case 'd': |
79 |
|
|
cutoff = Double.valueOf(g.getOptarg()); |
80 |
|
|
break; |
81 |
|
|
case 't': |
82 |
|
|
edgeType = g.getOptarg(); |
83 |
|
|
break; |
84 |
|
|
case 'o': |
85 |
|
|
outputDir = g.getOptarg(); |
86 |
|
|
break; |
87 |
|
|
case 'D': |
88 |
|
|
pdbaseDb = g.getOptarg(); |
89 |
|
|
break; |
90 |
duarte |
599 |
case 'P': |
91 |
|
|
paul = true; |
92 |
|
|
break; |
93 |
duarte |
277 |
case 'h': |
94 |
|
|
case '?': |
95 |
|
|
System.out.println(help); |
96 |
|
|
System.exit(0); |
97 |
|
|
break; // getopt() already printed an error |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
|
101 |
duarte |
609 |
if (edgeType.equals("") || cutoff==0.0) { |
102 |
duarte |
277 |
System.err.println("Some missing option"); |
103 |
|
|
System.err.println(help); |
104 |
|
|
System.exit(1); |
105 |
|
|
} |
106 |
duarte |
609 |
if (listfile.equals("") && pdbIds==null && pdbfile.equals("")){ |
107 |
duarte |
277 |
System.err.println("Either a listfile, some pdb codes/chain codes or a pdbfile must be given"); |
108 |
|
|
System.err.println(help); |
109 |
|
|
System.exit(1); |
110 |
|
|
} |
111 |
duarte |
609 |
if ((!listfile.equals("") && pdbIds!=null) || (!listfile.equals("") && !pdbfile.equals("")) || (pdbIds!=null && !pdbfile.equals(""))) { |
112 |
|
|
System.err.println("Options -p, -i and -f/-c are exclusive. Use only one of them"); |
113 |
duarte |
277 |
System.err.println(help); |
114 |
|
|
System.exit(1); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
MySQLConnection conn = null; |
119 |
|
|
|
120 |
|
|
try{ |
121 |
|
|
conn = new MySQLConnection(DB_HOST, DB_USER, DB_PWD); |
122 |
|
|
} catch (Exception e) { |
123 |
|
|
System.err.println("Error opening database connection. Exiting"); |
124 |
|
|
System.exit(1); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
if (pdbfile.equals("")){ |
129 |
|
|
|
130 |
duarte |
609 |
if (!listfile.equals("")) { |
131 |
|
|
pdbIds = TemplateList.readIdsListFile(new File(listfile)); |
132 |
duarte |
277 |
} |
133 |
|
|
|
134 |
|
|
int numPdbs = 0; |
135 |
|
|
|
136 |
duarte |
609 |
for (int i=0;i<pdbIds.length;i++) { |
137 |
|
|
String pdbCode = pdbIds[i].substring(0,4); |
138 |
|
|
String pdbChainCode = pdbIds[i].substring(4); |
139 |
duarte |
277 |
|
140 |
|
|
try { |
141 |
duarte |
285 |
|
142 |
duarte |
600 |
//long start = System.currentTimeMillis(); |
143 |
duarte |
285 |
|
144 |
duarte |
441 |
Pdb pdb = new PdbasePdb(pdbCode, pdbaseDb, conn); |
145 |
|
|
pdb.load(pdbChainCode); |
146 |
duarte |
277 |
|
147 |
|
|
// get graph |
148 |
duarte |
420 |
RIGraph graph = pdb.get_graph(edgeType, cutoff); |
149 |
duarte |
431 |
|
150 |
|
|
String edgeTypeStr = edgeType.replaceAll("/", ":"); |
151 |
|
|
|
152 |
duarte |
609 |
File outputFile = new File(outputDir,pdbCode+pdbChainCode+"_"+edgeTypeStr+"_"+cutoff+".cm"); |
153 |
duarte |
599 |
if (!paul) { |
154 |
|
|
graph.write_graph_to_file(outputFile.getAbsolutePath()); |
155 |
|
|
} else { |
156 |
|
|
graph.writeToPaulFile(outputFile.getAbsolutePath()); |
157 |
|
|
} |
158 |
duarte |
277 |
|
159 |
duarte |
600 |
//long end = System.currentTimeMillis(); |
160 |
|
|
//double time = (double) (end -start)/1000; |
161 |
duarte |
285 |
|
162 |
duarte |
277 |
System.out.println("Wrote "+outputFile.getAbsolutePath()); |
163 |
duarte |
600 |
//System.out.printf("%5.3f s\n",time); |
164 |
duarte |
285 |
|
165 |
duarte |
277 |
numPdbs++; |
166 |
|
|
|
167 |
duarte |
441 |
} catch (PdbLoadError e) { |
168 |
|
|
System.err.println("Error loading pdb data for " + pdbCode + pdbChainCode+", specific error: "+e.getMessage()); |
169 |
duarte |
277 |
} catch (PdbCodeNotFoundError e) { |
170 |
|
|
System.err.println("Couldn't find pdb code "+pdbCode); |
171 |
|
|
} catch (SQLException e) { |
172 |
duarte |
609 |
System.err.println("SQL error for structure "+pdbCode+pdbChainCode+", error: "+e.getMessage()); |
173 |
duarte |
277 |
} |
174 |
|
|
|
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
// output results |
178 |
|
|
System.out.println("Number of structures done successfully: " + numPdbs); |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
} else { |
182 |
duarte |
609 |
File pdbFile = new File(pdbfile); |
183 |
duarte |
277 |
try { |
184 |
duarte |
441 |
Pdb pdb = new PdbfilePdb(pdbfile); |
185 |
duarte |
609 |
if (pdbChainCode4file==null) { |
186 |
|
|
pdbChainCode4file = pdb.getChains()[0]; |
187 |
duarte |
277 |
} |
188 |
duarte |
609 |
|
189 |
|
|
pdb.load(pdbChainCode4file); |
190 |
duarte |
420 |
RIGraph graph = pdb.get_graph(edgeType, cutoff); |
191 |
duarte |
277 |
|
192 |
duarte |
431 |
String edgeTypeStr = edgeType.replaceAll("/", ":"); |
193 |
|
|
|
194 |
duarte |
609 |
String filename = pdbFile.getName().substring(0, pdbFile.getName().lastIndexOf(".")); |
195 |
|
|
File outputFile = new File(outputDir,filename+"_"+edgeTypeStr+"_"+cutoff+".cm"); |
196 |
duarte |
599 |
if (!paul) { |
197 |
|
|
graph.write_graph_to_file(outputFile.getAbsolutePath()); |
198 |
|
|
} else { |
199 |
|
|
graph.writeToPaulFile(outputFile.getAbsolutePath()); |
200 |
|
|
} |
201 |
duarte |
609 |
System.out.println("Wrote graph file "+outputFile.getAbsolutePath()+" from pdb file "+pdbFile); |
202 |
duarte |
277 |
|
203 |
duarte |
441 |
} catch (PdbLoadError e) { |
204 |
duarte |
609 |
System.err.println("Error loading from pdb file "+pdbFile+", specific error: "+e.getMessage()); |
205 |
duarte |
277 |
} |
206 |
|
|
} |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
} |