Wrapper for Clustal Omega.
[jabaws.git] / runner / compbio / runner / msa / ClustalO.java
diff --git a/runner/compbio/runner/msa/ClustalO.java b/runner/compbio/runner/msa/ClustalO.java
new file mode 100644 (file)
index 0000000..e94dead
--- /dev/null
@@ -0,0 +1,103 @@
+/* Copyright (c) 2009 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0\r
+ * \r
+ *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ *  Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ *  License for more details.\r
+ * \r
+ *  A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.runner.msa;\r
+\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.UnknownFileFormatException;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.runner.Util;\r
+\r
+public class ClustalO extends SkeletalExecutable<ClustalO> {\r
+\r
+       private static Logger log = Logger.getLogger(ClustalO.class);\r
+       private static final String EXEC_STAT_FILE = "stat.log";\r
+       private static final String TREE_FILE_EXT = ".dnd";\r
+\r
+       public static final String KEY_VALUE_SEPARATOR = "=";\r
+\r
+       /**\r
+        * \r
+        * --auto Set options automatically (might overwrite some of your options)\r
+        * \r
+        * --threads=<n> Number of processors to use\r
+        * \r
+        * -l, --log=<file> Log all non-essential output to this file\r
+        */\r
+       public ClustalO() {\r
+               super(KEY_VALUE_SEPARATOR);\r
+               addParameters(Arrays.asList("--outfmt=clustal", "-v", "--log="\r
+                               + EXEC_STAT_FILE));\r
+               // set default in, outs and err files\r
+               this.setInput(super.inputFile);\r
+               this.setOutput(super.outputFile);\r
+               this.setError(super.errorFile);\r
+       }\r
+\r
+       @Override\r
+       public ClustalO setOutput(String outFile) {\r
+               super.setOutput(outFile);\r
+               cbuilder.setParam("--outfile=" + outFile);\r
+               return this;\r
+       }\r
+\r
+       @Override\r
+       public ClustalO setInput(String inFile) {\r
+               super.setInput(inFile);\r
+               cbuilder.setParam("--infile=" + inFile);\r
+               return this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public Alignment getResults(String workDirectory)\r
+                       throws ResultNotAvailableException {\r
+               try {\r
+                       return Util.readClustalFile(workDirectory, getOutput());\r
+               } catch (FileNotFoundException e) {\r
+                       log.error(e.getMessage(), e.getCause());\r
+                       throw new ResultNotAvailableException(e);\r
+               } catch (IOException e) {\r
+                       log.error(e.getMessage(), e.getCause());\r
+                       throw new ResultNotAvailableException(e);\r
+               } catch (UnknownFileFormatException e) {\r
+                       log.error(e.getMessage(), e.getCause());\r
+                       throw new ResultNotAvailableException(e);\r
+               } catch (NullPointerException e) {\r
+                       log.error(e.getMessage(), e.getCause());\r
+                       throw new ResultNotAvailableException(e);\r
+               }\r
+       }\r
+\r
+       public static String getStatFile() {\r
+               return EXEC_STAT_FILE;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Class<ClustalO> getType() {\r
+               return (Class<ClustalO>) this.getClass();\r
+       }\r
+\r
+}\r