3d0f86aa0a124cfa7581d101f7097d7ab21e447e
[jabaws.git] / runner / compbio / runner / msa / Probcons.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.runner.msa;\r
20 \r
21 import java.io.FileNotFoundException;\r
22 import java.io.IOException;\r
23 import java.util.Arrays;\r
24 import java.util.List;\r
25 \r
26 import org.apache.log4j.Logger;\r
27 \r
28 import compbio.data.sequence.Alignment;\r
29 import compbio.data.sequence.UnknownFileFormatException;\r
30 import compbio.engine.client.PipedExecutable;\r
31 import compbio.engine.client.SkeletalExecutable;\r
32 import compbio.metadata.ResultNotAvailableException;\r
33 import compbio.runner.Util;\r
34 \r
35 public class Probcons extends SkeletalExecutable<Probcons>\r
36                 implements\r
37                         PipedExecutable<Probcons> {\r
38 \r
39         private static Logger log = Logger.getLogger(Probcons.class);\r
40 \r
41         private final static String ANNOTATION = "annotation.txt";\r
42 \r
43         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
44 \r
45         /**\r
46          * \r
47          * @param workDirectory\r
48          */\r
49         public Probcons() {\r
50                 addParameters(Arrays.asList("-v", "-clustalw", "-annot", ANNOTATION));\r
51                 /*\r
52                  * Could either have probabilities or the alignment, but not both "-t",\r
53                  * "probabilities"\r
54                  */\r
55         }\r
56 \r
57         @SuppressWarnings("unchecked")\r
58         @Override\r
59         public Alignment getResults(String workDirectory)\r
60                         throws ResultNotAvailableException {\r
61                 try {\r
62                         return Util.readClustalFile(workDirectory, getOutput());\r
63                 } catch (FileNotFoundException e) {\r
64                         log.error(e.getMessage(), e.getCause());\r
65                         throw new ResultNotAvailableException(e);\r
66                 } catch (IOException e) {\r
67                         log.error(e.getMessage(), e.getCause());\r
68                         throw new ResultNotAvailableException(e);\r
69                 } catch (UnknownFileFormatException e) {\r
70                         log.error(e.getMessage(), e.getCause());\r
71                         throw new ResultNotAvailableException(e);\r
72                 } catch (NullPointerException e) {\r
73                         log.error(e.getMessage(), e.getCause());\r
74                         throw new ResultNotAvailableException(e);\r
75                 }\r
76         }\r
77 \r
78         @Override\r
79         public List<String> getCreatedFiles() {\r
80                 return Arrays.asList(getOutput(), ANNOTATION, getError());\r
81         }\r
82 \r
83         @Override\r
84         public Probcons setInput(String inFile) {\r
85                 String input = getInput();\r
86                 super.setInput(inFile);\r
87                 // TODO replace with setLast\r
88                 cbuilder.setParam(inFile);\r
89                 return this;\r
90         }\r
91 \r
92         @SuppressWarnings("unchecked")\r
93         @Override\r
94         public Class<Probcons> getType() {\r
95                 return (Class<Probcons>) this.getClass();\r
96         }\r
97 }\r