Wrapper for Clustal Omega.
[jabaws.git] / runner / compbio / runner / msa / ClustalO.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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 \r
25 import org.apache.log4j.Logger;\r
26 \r
27 import compbio.data.sequence.Alignment;\r
28 import compbio.data.sequence.UnknownFileFormatException;\r
29 import compbio.engine.client.SkeletalExecutable;\r
30 import compbio.metadata.ResultNotAvailableException;\r
31 import compbio.runner.Util;\r
32 \r
33 public class ClustalO extends SkeletalExecutable<ClustalO> {\r
34 \r
35         private static Logger log = Logger.getLogger(ClustalO.class);\r
36         private static final String EXEC_STAT_FILE = "stat.log";\r
37         private static final String TREE_FILE_EXT = ".dnd";\r
38 \r
39         public static final String KEY_VALUE_SEPARATOR = "=";\r
40 \r
41         /**\r
42          * \r
43          * --auto Set options automatically (might overwrite some of your options)\r
44          * \r
45          * --threads=<n> Number of processors to use\r
46          * \r
47          * -l, --log=<file> Log all non-essential output to this file\r
48          */\r
49         public ClustalO() {\r
50                 super(KEY_VALUE_SEPARATOR);\r
51                 addParameters(Arrays.asList("--outfmt=clustal", "-v", "--log="\r
52                                 + EXEC_STAT_FILE));\r
53                 // set default in, outs and err files\r
54                 this.setInput(super.inputFile);\r
55                 this.setOutput(super.outputFile);\r
56                 this.setError(super.errorFile);\r
57         }\r
58 \r
59         @Override\r
60         public ClustalO setOutput(String outFile) {\r
61                 super.setOutput(outFile);\r
62                 cbuilder.setParam("--outfile=" + outFile);\r
63                 return this;\r
64         }\r
65 \r
66         @Override\r
67         public ClustalO setInput(String inFile) {\r
68                 super.setInput(inFile);\r
69                 cbuilder.setParam("--infile=" + inFile);\r
70                 return this;\r
71         }\r
72 \r
73         @SuppressWarnings("unchecked")\r
74         public Alignment getResults(String workDirectory)\r
75                         throws ResultNotAvailableException {\r
76                 try {\r
77                         return Util.readClustalFile(workDirectory, getOutput());\r
78                 } catch (FileNotFoundException e) {\r
79                         log.error(e.getMessage(), e.getCause());\r
80                         throw new ResultNotAvailableException(e);\r
81                 } catch (IOException e) {\r
82                         log.error(e.getMessage(), e.getCause());\r
83                         throw new ResultNotAvailableException(e);\r
84                 } catch (UnknownFileFormatException e) {\r
85                         log.error(e.getMessage(), e.getCause());\r
86                         throw new ResultNotAvailableException(e);\r
87                 } catch (NullPointerException e) {\r
88                         log.error(e.getMessage(), e.getCause());\r
89                         throw new ResultNotAvailableException(e);\r
90                 }\r
91         }\r
92 \r
93         public static String getStatFile() {\r
94                 return EXEC_STAT_FILE;\r
95         }\r
96 \r
97         @SuppressWarnings("unchecked")\r
98         @Override\r
99         public Class<ClustalO> getType() {\r
100                 return (Class<ClustalO>) this.getClass();\r
101         }\r
102 \r
103 }\r