From 28e0d442de369b005639945543fb97b1f5ead2bd Mon Sep 17 00:00:00 2001 From: josemduarte Date: Fri, 19 Jul 2024 15:02:01 -0700 Subject: [PATCH 1/2] Some cleanups --- .../ce/AbstractUserArgumentProcessor.java | 138 +++++++----------- .../align/ce/CeUserArgumentProcessor.java | 4 +- .../structure/align/ce/StartupParameters.java | 49 ++----- 3 files changed, 66 insertions(+), 125 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java index 20bc11827e..60242f8fde 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java @@ -74,11 +74,10 @@ * * @author Andreas * @author Spencer - * */ public abstract class AbstractUserArgumentProcessor implements UserArgumentProcessor { - public static String newline = System.getProperty("line.separator"); + public static String newline = System.lineSeparator(); protected StartupParameters params ; @@ -109,11 +108,6 @@ public void process(String[] argv){ printAboutMe(); -// if(argv.length == 0 ) { -// System.out.println(printHelp()); -// return; -// } - for (int i = 0 ; i < argv.length; i++){ String arg = argv[i]; @@ -144,8 +138,6 @@ public void process(String[] argv){ String[] tmp = {arg,value}; - //System.out.println(arg + " " + value); - try { CliTools.configureBean(params, tmp); @@ -177,7 +169,6 @@ public void process(String[] argv){ String pdb1 = params.getPdb1(); String file1 = params.getFile1(); - try { if (pdb1 != null || file1 != null){ runPairwise(); @@ -195,90 +186,76 @@ public void process(String[] argv){ System.exit(1); return; } - - - - public static void printAboutMe() { - try { - ResourceManager about = ResourceManager.getResourceManager("about"); - - String version = about.getString("project_version"); - String build = about.getString("build"); - - System.out.println("Protein Comparison Tool " + version + " " + build); - } catch (Exception e){ - e.printStackTrace(); - } + ResourceManager about = ResourceManager.getResourceManager("about"); + String version = about.getString("project_version"); + String build = about.getString("build"); + System.out.println("Protein Comparison Tool " + version + " " + build); } - private void runAlignPairs(AtomCache cache, String alignPairs, - String outputFile) { - try { - File f = new File(alignPairs); + private void runAlignPairs(AtomCache cache, String alignPairs, String outputFile) throws IOException, StructureException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { - BufferedReader is = new BufferedReader (new InputStreamReader(new FileInputStream(f))); + File f = new File(alignPairs); - BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true)); + BufferedReader is = new BufferedReader (new InputStreamReader(new FileInputStream(f))); - StructureAlignment algorithm = getAlgorithm(); + BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true)); - String header = "# algorithm:" + algorithm.getAlgorithmName(); - out.write(header); - out.write(newline); + StructureAlignment algorithm = getAlgorithm(); - out.write("#Legend: " + newline ); - String legend = getDbSearchLegend(); - out.write(legend + newline ); - System.out.println(legend); - String line = null; - while ( (line = is.readLine()) != null){ - if ( line.startsWith("#")) - continue; + String header = "# algorithm:" + algorithm.getAlgorithmName(); + out.write(header); + out.write(newline); - String[] spl = line.split(" "); + out.write("#Legend: " + newline ); + String legend = getDbSearchLegend(); + out.write(legend + newline ); + System.out.println(legend); + String line = null; + while ( (line = is.readLine()) != null){ + if ( line.startsWith("#")) + continue; - if ( spl.length != 2) { - System.err.println("wrongly formattted line. Expected format: 4hhb.A 4hhb.B but found " + line); - continue; - } + String[] spl = line.split(" "); - String pdb1 = spl[0]; - String pdb2 = spl[1]; + if ( spl.length != 2) { + System.err.println("wrongly formattted line. Expected format: 4hhb.A 4hhb.B but found " + line); + continue; + } + String pdb1 = spl[0]; + String pdb2 = spl[1]; - Structure structure1 = cache.getStructure(pdb1); - Structure structure2 = cache.getStructure(pdb2); - Atom[] ca1; - Atom[] ca2; + Structure structure1 = cache.getStructure(pdb1); + Structure structure2 = cache.getStructure(pdb2); + Atom[] ca1; + Atom[] ca2; - ca1 = StructureTools.getRepresentativeAtomArray(structure1); - ca2 = StructureTools.getRepresentativeAtomArray(structure2); - Object jparams = getParameters(); + ca1 = StructureTools.getRepresentativeAtomArray(structure1); + ca2 = StructureTools.getRepresentativeAtomArray(structure2); - AFPChain afpChain; + Object jparams = getParameters(); - afpChain = algorithm.align(ca1, ca2, jparams); - afpChain.setName1(pdb1); - afpChain.setName2(pdb2); + AFPChain afpChain; - String result = getDbSearchResult(afpChain); - out.write(result); - System.out.print(result); + afpChain = algorithm.align(ca1, ca2, jparams); + afpChain.setName1(pdb1); + afpChain.setName2(pdb2); - checkWriteFile(afpChain,ca1,ca2,true); - } + String result = getDbSearchResult(afpChain); + out.write(result); + System.out.print(result); - out.close(); - is.close(); - } catch(Exception e){ - e.printStackTrace(); + checkWriteFile(afpChain,ca1,ca2,true); } + + out.close(); + is.close(); } @@ -411,9 +388,6 @@ private void runPairwise() throws ConfigurationException{ checkWriteFile(afpChain,ca1, ca2, false); - - - if ( params.isPrintXML()){ String fatcatXML = AFPChainXMLConverter.toXML(afpChain,ca1,ca2); System.out.println(fatcatXML); @@ -426,26 +400,12 @@ private void runPairwise() throws ConfigurationException{ System.out.println(afpChain.toCE(ca1, ca2)); } - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); return; - } catch (ClassNotFoundException e) { - e.printStackTrace(); - System.exit(1); return; - } catch (NoSuchMethodException e) { - e.printStackTrace(); - System.exit(1); return; - } catch (InvocationTargetException e) { - e.printStackTrace(); - System.exit(1); return; - } catch (IllegalAccessException e) { - e.printStackTrace(); - System.exit(1); return; - } catch (StructureException e) { + } catch (IOException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException | StructureException e) { e.printStackTrace(); System.exit(1); return; } - } + } /** * check if the result should be written to the local file system diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeUserArgumentProcessor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeUserArgumentProcessor.java index 6f04aa7342..9274ed41eb 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeUserArgumentProcessor.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeUserArgumentProcessor.java @@ -28,7 +28,8 @@ import org.biojava.nbio.structure.align.StructureAlignment; import org.biojava.nbio.structure.align.ce.CeParameters.ScoringStrategy; -/** process the arguments from command line +/** + * Process the arguments from command line * * @author Andreas Prlic * @@ -154,7 +155,6 @@ public String toString() { .append(showMenu).append(", printPDB=").append(printPDB) .append(", isDomainSplit=").append(isDomainSplit) .append(", alignPairs=").append(alignPairs) - .append(", searchFile=").append(searchFile) .append(", saveOutputDir=").append(saveOutputDir) .append(", nrCPU=").append(nrCPU).append("]"); return builder.toString(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/StartupParameters.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/StartupParameters.java index b6ee5e8ec5..bc6201d238 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/StartupParameters.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/StartupParameters.java @@ -25,7 +25,6 @@ * A simple bean that contains the parameters that can get set at startup * * @author Andreas Prlic - * */ public class StartupParameters { @@ -49,7 +48,6 @@ public class StartupParameters { // for DB searches String alignPairs; - String searchFile; String saveOutputDir; int nrCPU; @@ -69,19 +67,8 @@ public StartupParameters(){ nrCPU = 1; } - /** An input file to be used for the DB search - * - * @return - */ - public String getSearchFile() { - return searchFile; - } - public void setSearchFile(String searchFile) { - this.searchFile = searchFile; - } - - - /** The file that contains a list of PDB pairs to be aligned + /** + * The file that contains a list of PDB pairs to be aligned * * @return */ @@ -109,7 +96,8 @@ public void setShowMenu(boolean showMenu) { this.showMenu = showMenu; } - /** Display the output string in CE style + /** + * Display the output string in CE style * * @return flag */ @@ -117,7 +105,8 @@ public boolean isPrintCE() { return printCE; } - /** Display the output string in CE style + /** + * Display the output string in CE style * * @param printCE a flag */ @@ -129,7 +118,8 @@ public void setPrintCE(boolean printCE) { public String getPdb1() { return pdb1; } - /** mandatory argument to set the first PDB (and optionally chain ID) to be aligned. + /** + * mandatory argument to set the first PDB (and optionally chain ID) to be aligned. * * @param pdb1 */ @@ -140,7 +130,8 @@ public String getPdb2() { return pdb2; } - /** mandatory argument to set the second PDB (and optionally chain ID) to be aligned. + /** + * mandatory argument to set the second PDB (and optionally chain ID) to be aligned. * @param pdb2 */ public void setPdb2(String pdb2) { @@ -164,7 +155,8 @@ public String getPdbFilePath() { return pdbFilePath; } - /** mandatory argument to set the location of PDB files. + /** + * mandatory argument to set the location of PDB files. * * @param pdbFilePath */ @@ -232,9 +224,8 @@ public void setFile2(String file2) this.file2 = file2; } - - - /** When writing the results to a file, don;t write as XML but write aligned PDB file + /** + * When writing the results to a file, don;t write as XML but write aligned PDB file * * @return flag */ @@ -249,10 +240,6 @@ public void setOutputPDB(boolean printPDB) { this.printPDB = printPDB; } - - - - public boolean isDomainSplit() { return isDomainSplit; } @@ -273,14 +260,8 @@ public String toString() { + ", " + newline + " printPDB=" + printPDB + ", " + newline + " isDomainSplit=" + isDomainSplit + ", " + newline + " alignPairs=" + alignPairs - + ", " + newline + " searchFile=" + searchFile + ", " + newline + " saveOutputDir=" + + ", " + newline + " saveOutputDir=" + saveOutputDir + ", " + newline + " nrCPU=" + nrCPU + "]"; } - - - - - - } From 2e8138c5175ba113a26bb0b1f1cf516283c27ec5 Mon Sep 17 00:00:00 2001 From: josemduarte Date: Fri, 19 Jul 2024 15:25:11 -0700 Subject: [PATCH 2/2] Bringing back alignPairs option, should fix #1096 --- .../ce/AbstractUserArgumentProcessor.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java index 60242f8fde..dc61972ecb 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java @@ -175,8 +175,11 @@ public void process(String[] argv){ return; } - - } catch (ConfigurationException e) { + if ( params.getAlignPairs() != null){ + runAlignPairs(); + return; + } + } catch (Exception e) { System.err.println(e.getLocalizedMessage()); System.exit(1); return; } @@ -195,6 +198,33 @@ public static void printAboutMe() { System.out.println("Protein Comparison Tool " + version + " " + build); } + private void runAlignPairs() throws ConfigurationException, StructureException, IOException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { + + String pdbFilePath = params.getPdbFilePath(); + + if ( pdbFilePath == null || pdbFilePath.equals("")){ + UserConfiguration c = new UserConfiguration(); + pdbFilePath = c.getPdbFilePath(); + System.err.println("You did not specify the -pdbFilePath parameter. Defaulting to "+pdbFilePath+"."); + } + + AtomCache cache = new AtomCache(pdbFilePath, pdbFilePath); + + String alignPairs = params.getAlignPairs(); + + if ( alignPairs == null || alignPairs.equals("")) { + throw new ConfigurationException("Please specify -alignPairs!"); + } + + String outputFile = params.getOutFile(); + + if ( outputFile == null || outputFile.equals("")){ + throw new ConfigurationException("Please specify the mandatory argument -outFile!"); + } + + runAlignPairs(cache, alignPairs, outputFile); + } + private void runAlignPairs(AtomCache cache, String alignPairs, String outputFile) throws IOException, StructureException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { File f = new File(alignPairs);