e62746279c280ca3005f9eb7d486a1a2f7c5f233
[jabaws.git] / runner / compbio / runner / msa / Muscle.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 javax.xml.bind.annotation.XmlTransient;\r
27 \r
28 import org.apache.log4j.Logger;\r
29 \r
30 import compbio.data.sequence.Alignment;\r
31 import compbio.data.sequence.UnknownFileFormatException;\r
32 import compbio.engine.client.SkeletalExecutable;\r
33 import compbio.metadata.ResultNotAvailableException;\r
34 import compbio.runner.Util;\r
35 \r
36 public class Muscle extends SkeletalExecutable<Muscle> {\r
37 \r
38         /*\r
39          * Tell JAXB to ignore this while marshalling\r
40          */\r
41         @XmlTransient\r
42         private static Logger log = Logger.getLogger(Muscle.class);\r
43 \r
44         private static final String EXEC_STAT_FILE = "stat.log";\r
45 \r
46         public static final String KEY_VALUE_SEPARATOR = Util.SPACE;\r
47 \r
48         /**\r
49          * Default options are\r
50          * \r
51          * -clwstrict - write output in clustal format\r
52          * \r
53          * @param workDirectory\r
54          */\r
55         public Muscle() {\r
56                 /*\r
57                  * The –quiet command-line option disables writing progress messages to\r
58                  * standard error. If the –verbose command-line option is specified, a\r
59                  * progress message will be written to the log file when each iteration\r
60                  * completes. So –quiet and –verbose are not contradictory."-quiet",\r
61                  * "-verbose"\r
62                  */\r
63                 addParameters(Arrays.asList("-clwstrict", "-quiet", "-verbose",\r
64                                 "-nocore"));\r
65                 cbuilder.setParam("-log", EXEC_STAT_FILE);\r
66         }\r
67 \r
68         @Override\r
69         public Muscle setOutput(String outFile) {\r
70                 super.setOutput(outFile);\r
71                 cbuilder.setParam("-out", outFile);\r
72                 return this;\r
73         }\r
74 \r
75         @Override\r
76         public Muscle setInput(String inFile) {\r
77                 super.setInput(inFile);\r
78                 cbuilder.setParam("-in", inFile);\r
79                 return this;\r
80         }\r
81 \r
82         @SuppressWarnings("unchecked")\r
83         @Override\r
84         public Alignment getResults(String workDirectory)\r
85                         throws ResultNotAvailableException {\r
86                 try {\r
87                         return Util.readClustalFile(workDirectory, getOutput());\r
88                 } catch (FileNotFoundException e) {\r
89                         log.error(e.getMessage(), e.getCause());\r
90                         throw new ResultNotAvailableException(e);\r
91                 } catch (IOException e) {\r
92                         log.error(e.getMessage(), e.getCause());\r
93                         throw new ResultNotAvailableException(e);\r
94                 } catch (UnknownFileFormatException e) {\r
95                         log.error(e.getMessage(), e.getCause());\r
96                         throw new ResultNotAvailableException(e);\r
97                 } catch (NullPointerException e) {\r
98                         log.error(e.getMessage(), e.getCause());\r
99                         throw new ResultNotAvailableException(e);\r
100                 }\r
101         }\r
102 \r
103         @Override\r
104         public List<String> getCreatedFiles() {\r
105                 return Arrays.asList(getOutput(), EXEC_STAT_FILE);\r
106         }\r
107 \r
108         public static String getStatFile() {\r
109                 return EXEC_STAT_FILE;\r
110         }\r
111 \r
112         @SuppressWarnings("unchecked")\r
113         @Override\r
114         public Class<Muscle> getType() {\r
115                 return (Class<Muscle>) this.getClass();\r
116         }\r
117 \r
118 }\r