Add all needed infrastructure for MSAprobs and GLprobs
[jabaws.git] / runner / compbio / runner / msa / MSAprobs.java
diff --git a/runner/compbio/runner/msa/MSAprobs.java b/runner/compbio/runner/msa/MSAprobs.java
new file mode 100644 (file)
index 0000000..9264384
--- /dev/null
@@ -0,0 +1,95 @@
+/* Copyright (c) 2011 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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
+import java.util.List;\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.PipedExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.runner.RunnerUtil;\r
+\r
+public class MSAprobs extends SkeletalExecutable<MSAprobs>\r
+               implements\r
+                       PipedExecutable<MSAprobs> {\r
+\r
+       private static Logger log = Logger.getLogger(MSAprobs.class);\r
+\r
+       private final static String ANNOTATION = "annotation.txt";\r
+\r
+       public static final String KEY_VALUE_SEPARATOR = " ";\r
+\r
+       /**\r
+        */\r
+       public MSAprobs() {\r
+               addParameters(Arrays.asList("-v", "-clustalw", "-annot", ANNOTATION));\r
+               /*\r
+                * Could either have probabilities or the alignment, but not both "-t",\r
+                * "probabilities"\r
+                */\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Alignment getResults(String workDirectory)\r
+                       throws ResultNotAvailableException {\r
+               try {\r
+                       return RunnerUtil.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
+       @Override\r
+       public List<String> getCreatedFiles() {\r
+               return Arrays.asList(getOutput(), ANNOTATION, getError());\r
+       }\r
+\r
+       @Override\r
+       public MSAprobs setInput(String inFile) {\r
+               String input = getInput();\r
+               super.setInput(inFile);\r
+               // TODO replace with setLast\r
+               cbuilder.setParam(inFile);\r
+               return this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Class<MSAprobs> getType() {\r
+               return (Class<MSAprobs>) this.getClass();\r
+       }\r
+}\r