Javadoc fixes
[jabaws.git] / runner / compbio / runner / msa / Tcoffee.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.CommandBuilder;\r
31 import compbio.engine.client.Executable;\r
32 import compbio.engine.client.PipedExecutable;\r
33 import compbio.engine.client.SkeletalExecutable;\r
34 import compbio.engine.conf.PropertyHelperManager;\r
35 import compbio.metadata.ResultNotAvailableException;\r
36 import compbio.runner.Util;\r
37 import compbio.util.PropertyHelper;\r
38 \r
39 public class Tcoffee extends SkeletalExecutable<Tcoffee>\r
40                 implements\r
41                         PipedExecutable<Tcoffee> {\r
42 \r
43         private static Logger log = Logger.getLogger(Tcoffee.class);\r
44 \r
45         private static PropertyHelper ph = PropertyHelperManager\r
46                         .getPropertyHelper();\r
47 \r
48         public static final String KEY_VALUE_SEPARATOR = "=";\r
49 \r
50         /**\r
51          * Number of cores to use, defaults to 1 for local execution or the value of\r
52          * "tcoffee.cluster.cpunum" property for cluster execution\r
53          */\r
54         private int ncoreNumber = 0;\r
55 \r
56         /*\r
57          * Number of cores parameter name\r
58          */\r
59         private final static String ncorePrm = "-n_core";\r
60 \r
61         /**\r
62          */\r
63         public Tcoffee() {\r
64                 super(KEY_VALUE_SEPARATOR);\r
65                 /*\r
66                  * Use "-quiet" to disable sdtout and progress to stderr inorder=input -\r
67                  * prevent t-coffee from sorting sequences\r
68                  */\r
69                 addParameters(Arrays.asList("-output=clustalw"));\r
70                 setInput(super.inputFile);\r
71         }\r
72 \r
73         @Override\r
74         public Tcoffee setInput(String inFile) {\r
75                 super.setInput(inFile);\r
76                 cbuilder.setParam("-seq", inFile);\r
77                 return this;\r
78         }\r
79 \r
80         @SuppressWarnings("unchecked")\r
81         @Override\r
82         public Alignment getResults(String workDirectory)\r
83                         throws ResultNotAvailableException {\r
84                 try {\r
85                         return Util.readClustalFile(workDirectory, getOutput());\r
86                 } catch (FileNotFoundException e) {\r
87                         log.error(e.getMessage(), e.getCause());\r
88                         throw new ResultNotAvailableException(e);\r
89                 } catch (IOException e) {\r
90                         log.error(e.getMessage(), e.getCause());\r
91                         throw new ResultNotAvailableException(e);\r
92                 } catch (UnknownFileFormatException e) {\r
93                         log.error(e.getMessage(), e.getCause());\r
94                         throw new ResultNotAvailableException(e);\r
95                 } catch (NullPointerException e) {\r
96                         log.error(e.getMessage(), e.getCause());\r
97                         throw new ResultNotAvailableException(e);\r
98                 }\r
99         }\r
100 \r
101         @Override\r
102         public List<String> getCreatedFiles() {\r
103                 return Arrays.asList(getOutput());\r
104         }\r
105 \r
106         public void setNCore(int ncoreNumber) {\r
107                 if (ncoreNumber < 1 || ncoreNumber > 100) {\r
108                         throw new IndexOutOfBoundsException(\r
109                                         "Number of cores must be within 1 and 100 ");\r
110                 }\r
111                 this.ncoreNumber = ncoreNumber;\r
112                 cbuilder.setParam(ncorePrm, Integer.toString(getNCore()));\r
113         }\r
114 \r
115         int getNCore() {\r
116                 return ncoreNumber;\r
117         }\r
118 \r
119         @Override\r
120         public CommandBuilder<Tcoffee> getParameters(ExecProvider provider) {\r
121                 // Limit number of cores to 1 for ANY execution which does not set\r
122                 // Ncores explicitly using setNCore method\r
123                 if (ncoreNumber == 0) {\r
124                         setNCore(1);\r
125                 }\r
126                 if (provider == Executable.ExecProvider.Cluster) {\r
127                         int cpunum = SkeletalExecutable.getClusterCpuNum(getType());\r
128                         if (cpunum != 0) {\r
129                                 setNCore(cpunum);\r
130                         }\r
131                 }\r
132                 return super.getParameters(provider);\r
133         }\r
134 \r
135         @SuppressWarnings("unchecked")\r
136         @Override\r
137         public Class<Tcoffee> getType() {\r
138                 return (Class<Tcoffee>) this.getClass();\r
139         }\r
140 }\r