Skip to content

Commit 28e0d44

Browse files
committed
Some cleanups
1 parent 62b0426 commit 28e0d44

File tree

3 files changed

+66
-125
lines changed

3 files changed

+66
-125
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java

Lines changed: 49 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@
7474
*
7575
* @author Andreas
7676
* @author Spencer
77-
*
7877
*/
7978
public abstract class AbstractUserArgumentProcessor implements UserArgumentProcessor {
8079

81-
public static String newline = System.getProperty("line.separator");
80+
public static String newline = System.lineSeparator();
8281

8382
protected StartupParameters params ;
8483

@@ -109,11 +108,6 @@ public void process(String[] argv){
109108

110109
printAboutMe();
111110

112-
// if(argv.length == 0 ) {
113-
// System.out.println(printHelp());
114-
// return;
115-
// }
116-
117111
for (int i = 0 ; i < argv.length; i++){
118112
String arg = argv[i];
119113

@@ -144,8 +138,6 @@ public void process(String[] argv){
144138

145139
String[] tmp = {arg,value};
146140

147-
//System.out.println(arg + " " + value);
148-
149141
try {
150142

151143
CliTools.configureBean(params, tmp);
@@ -177,7 +169,6 @@ public void process(String[] argv){
177169
String pdb1 = params.getPdb1();
178170
String file1 = params.getFile1();
179171

180-
181172
try {
182173
if (pdb1 != null || file1 != null){
183174
runPairwise();
@@ -195,90 +186,76 @@ public void process(String[] argv){
195186
System.exit(1); return;
196187
}
197188

198-
199-
200-
201-
202189
public static void printAboutMe() {
203-
try {
204-
ResourceManager about = ResourceManager.getResourceManager("about");
205-
206-
String version = about.getString("project_version");
207-
String build = about.getString("build");
208-
209-
System.out.println("Protein Comparison Tool " + version + " " + build);
210-
} catch (Exception e){
211-
e.printStackTrace();
212-
}
190+
ResourceManager about = ResourceManager.getResourceManager("about");
213191

192+
String version = about.getString("project_version");
193+
String build = about.getString("build");
214194

195+
System.out.println("Protein Comparison Tool " + version + " " + build);
215196
}
216197

217-
private void runAlignPairs(AtomCache cache, String alignPairs,
218-
String outputFile) {
219-
try {
220-
File f = new File(alignPairs);
198+
private void runAlignPairs(AtomCache cache, String alignPairs, String outputFile) throws IOException, StructureException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
221199

222-
BufferedReader is = new BufferedReader (new InputStreamReader(new FileInputStream(f)));
200+
File f = new File(alignPairs);
223201

224-
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true));
202+
BufferedReader is = new BufferedReader (new InputStreamReader(new FileInputStream(f)));
225203

226-
StructureAlignment algorithm = getAlgorithm();
204+
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true));
227205

228-
String header = "# algorithm:" + algorithm.getAlgorithmName();
229-
out.write(header);
230-
out.write(newline);
206+
StructureAlignment algorithm = getAlgorithm();
231207

232-
out.write("#Legend: " + newline );
233-
String legend = getDbSearchLegend();
234-
out.write(legend + newline );
235-
System.out.println(legend);
236-
String line = null;
237-
while ( (line = is.readLine()) != null){
238-
if ( line.startsWith("#"))
239-
continue;
208+
String header = "# algorithm:" + algorithm.getAlgorithmName();
209+
out.write(header);
210+
out.write(newline);
240211

241-
String[] spl = line.split(" ");
212+
out.write("#Legend: " + newline );
213+
String legend = getDbSearchLegend();
214+
out.write(legend + newline );
215+
System.out.println(legend);
216+
String line = null;
217+
while ( (line = is.readLine()) != null){
218+
if ( line.startsWith("#"))
219+
continue;
242220

243-
if ( spl.length != 2) {
244-
System.err.println("wrongly formattted line. Expected format: 4hhb.A 4hhb.B but found " + line);
245-
continue;
246-
}
221+
String[] spl = line.split(" ");
247222

248-
String pdb1 = spl[0];
249-
String pdb2 = spl[1];
223+
if ( spl.length != 2) {
224+
System.err.println("wrongly formattted line. Expected format: 4hhb.A 4hhb.B but found " + line);
225+
continue;
226+
}
250227

228+
String pdb1 = spl[0];
229+
String pdb2 = spl[1];
251230

252-
Structure structure1 = cache.getStructure(pdb1);
253-
Structure structure2 = cache.getStructure(pdb2);
254231

255-
Atom[] ca1;
256-
Atom[] ca2;
232+
Structure structure1 = cache.getStructure(pdb1);
233+
Structure structure2 = cache.getStructure(pdb2);
257234

235+
Atom[] ca1;
236+
Atom[] ca2;
258237

259-
ca1 = StructureTools.getRepresentativeAtomArray(structure1);
260-
ca2 = StructureTools.getRepresentativeAtomArray(structure2);
261238

262-
Object jparams = getParameters();
239+
ca1 = StructureTools.getRepresentativeAtomArray(structure1);
240+
ca2 = StructureTools.getRepresentativeAtomArray(structure2);
263241

264-
AFPChain afpChain;
242+
Object jparams = getParameters();
265243

266-
afpChain = algorithm.align(ca1, ca2, jparams);
267-
afpChain.setName1(pdb1);
268-
afpChain.setName2(pdb2);
244+
AFPChain afpChain;
269245

270-
String result = getDbSearchResult(afpChain);
271-
out.write(result);
272-
System.out.print(result);
246+
afpChain = algorithm.align(ca1, ca2, jparams);
247+
afpChain.setName1(pdb1);
248+
afpChain.setName2(pdb2);
273249

274-
checkWriteFile(afpChain,ca1,ca2,true);
275-
}
250+
String result = getDbSearchResult(afpChain);
251+
out.write(result);
252+
System.out.print(result);
276253

277-
out.close();
278-
is.close();
279-
} catch(Exception e){
280-
e.printStackTrace();
254+
checkWriteFile(afpChain,ca1,ca2,true);
281255
}
256+
257+
out.close();
258+
is.close();
282259
}
283260

284261

@@ -411,9 +388,6 @@ private void runPairwise() throws ConfigurationException{
411388

412389
checkWriteFile(afpChain,ca1, ca2, false);
413390

414-
415-
416-
417391
if ( params.isPrintXML()){
418392
String fatcatXML = AFPChainXMLConverter.toXML(afpChain,ca1,ca2);
419393
System.out.println(fatcatXML);
@@ -426,26 +400,12 @@ private void runPairwise() throws ConfigurationException{
426400
System.out.println(afpChain.toCE(ca1, ca2));
427401
}
428402

429-
} catch (IOException e) {
430-
e.printStackTrace();
431-
System.exit(1); return;
432-
} catch (ClassNotFoundException e) {
433-
e.printStackTrace();
434-
System.exit(1); return;
435-
} catch (NoSuchMethodException e) {
436-
e.printStackTrace();
437-
System.exit(1); return;
438-
} catch (InvocationTargetException e) {
439-
e.printStackTrace();
440-
System.exit(1); return;
441-
} catch (IllegalAccessException e) {
442-
e.printStackTrace();
443-
System.exit(1); return;
444-
} catch (StructureException e) {
403+
} catch (IOException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
404+
IllegalAccessException | StructureException e) {
445405
e.printStackTrace();
446406
System.exit(1); return;
447407
}
448-
}
408+
}
449409

450410
/**
451411
* check if the result should be written to the local file system

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeUserArgumentProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import org.biojava.nbio.structure.align.StructureAlignment;
2929
import org.biojava.nbio.structure.align.ce.CeParameters.ScoringStrategy;
3030

31-
/** process the arguments from command line
31+
/**
32+
* Process the arguments from command line
3233
*
3334
* @author Andreas Prlic
3435
*
@@ -154,7 +155,6 @@ public String toString() {
154155
.append(showMenu).append(", printPDB=").append(printPDB)
155156
.append(", isDomainSplit=").append(isDomainSplit)
156157
.append(", alignPairs=").append(alignPairs)
157-
.append(", searchFile=").append(searchFile)
158158
.append(", saveOutputDir=").append(saveOutputDir)
159159
.append(", nrCPU=").append(nrCPU).append("]");
160160
return builder.toString();

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/StartupParameters.java

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* A simple bean that contains the parameters that can get set at startup
2626
*
2727
* @author Andreas Prlic
28-
*
2928
*/
3029
public class StartupParameters {
3130

@@ -49,7 +48,6 @@ public class StartupParameters {
4948

5049
// for DB searches
5150
String alignPairs;
52-
String searchFile;
5351
String saveOutputDir;
5452
int nrCPU;
5553

@@ -69,19 +67,8 @@ public StartupParameters(){
6967
nrCPU = 1;
7068
}
7169

72-
/** An input file to be used for the DB search
73-
*
74-
* @return
75-
*/
76-
public String getSearchFile() {
77-
return searchFile;
78-
}
79-
public void setSearchFile(String searchFile) {
80-
this.searchFile = searchFile;
81-
}
82-
83-
84-
/** The file that contains a list of PDB pairs to be aligned
70+
/**
71+
* The file that contains a list of PDB pairs to be aligned
8572
*
8673
* @return
8774
*/
@@ -109,15 +96,17 @@ public void setShowMenu(boolean showMenu) {
10996
this.showMenu = showMenu;
11097
}
11198

112-
/** Display the output string in CE style
99+
/**
100+
* Display the output string in CE style
113101
*
114102
* @return flag
115103
*/
116104
public boolean isPrintCE() {
117105
return printCE;
118106
}
119107

120-
/** Display the output string in CE style
108+
/**
109+
* Display the output string in CE style
121110
*
122111
* @param printCE a flag
123112
*/
@@ -129,7 +118,8 @@ public void setPrintCE(boolean printCE) {
129118
public String getPdb1() {
130119
return pdb1;
131120
}
132-
/** mandatory argument to set the first PDB (and optionally chain ID) to be aligned.
121+
/**
122+
* mandatory argument to set the first PDB (and optionally chain ID) to be aligned.
133123
*
134124
* @param pdb1
135125
*/
@@ -140,7 +130,8 @@ public String getPdb2() {
140130
return pdb2;
141131
}
142132

143-
/** mandatory argument to set the second PDB (and optionally chain ID) to be aligned.
133+
/**
134+
* mandatory argument to set the second PDB (and optionally chain ID) to be aligned.
144135
* @param pdb2
145136
*/
146137
public void setPdb2(String pdb2) {
@@ -164,7 +155,8 @@ public String getPdbFilePath() {
164155
return pdbFilePath;
165156
}
166157

167-
/** mandatory argument to set the location of PDB files.
158+
/**
159+
* mandatory argument to set the location of PDB files.
168160
*
169161
* @param pdbFilePath
170162
*/
@@ -232,9 +224,8 @@ public void setFile2(String file2)
232224
this.file2 = file2;
233225
}
234226

235-
236-
237-
/** When writing the results to a file, don;t write as XML but write aligned PDB file
227+
/**
228+
* When writing the results to a file, don;t write as XML but write aligned PDB file
238229
*
239230
* @return flag
240231
*/
@@ -249,10 +240,6 @@ public void setOutputPDB(boolean printPDB) {
249240
this.printPDB = printPDB;
250241
}
251242

252-
253-
254-
255-
256243
public boolean isDomainSplit() {
257244
return isDomainSplit;
258245
}
@@ -273,14 +260,8 @@ public String toString() {
273260
+ ", " + newline + " printPDB=" + printPDB
274261
+ ", " + newline + " isDomainSplit="
275262
+ isDomainSplit + ", " + newline + " alignPairs=" + alignPairs
276-
+ ", " + newline + " searchFile=" + searchFile + ", " + newline + " saveOutputDir="
263+
+ ", " + newline + " saveOutputDir="
277264
+ saveOutputDir + ", " + newline + " nrCPU=" + nrCPU + "]";
278265
}
279266

280-
281-
282-
283-
284-
285-
286267
}

0 commit comments

Comments
 (0)