1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\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
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
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
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.runner.msa;
\r
21 import java.io.FileNotFoundException;
\r
22 import java.io.IOException;
\r
23 import java.security.InvalidParameterException;
\r
24 import java.util.Arrays;
\r
25 import java.util.List;
\r
27 import org.apache.log4j.Logger;
\r
29 import compbio.data.sequence.Alignment;
\r
30 import compbio.data.sequence.UnknownFileFormatException;
\r
31 import compbio.engine.client.ClusterNativeSpecExecutable;
\r
32 import compbio.engine.client.CommandBuilder;
\r
33 import compbio.engine.client.Executable;
\r
34 import compbio.engine.client.PipedExecutable;
\r
35 import compbio.engine.client.SkeletalExecutable;
\r
36 import compbio.engine.conf.PropertyHelperManager;
\r
37 import compbio.metadata.Limit;
\r
38 import compbio.metadata.LimitsManager;
\r
39 import compbio.metadata.ResultNotAvailableException;
\r
40 import compbio.runner.Util;
\r
41 import compbio.util.PropertyHelper;
\r
43 public class Tcoffee extends SkeletalExecutable<Tcoffee> implements
\r
44 PipedExecutable<Tcoffee>, ClusterNativeSpecExecutable<Tcoffee> {
\r
46 private static Logger log = Logger.getLogger(Tcoffee.class);
\r
48 private static PropertyHelper ph = PropertyHelperManager
\r
49 .getPropertyHelper();
\r
51 // Cache for Limits information
\r
52 private static LimitsManager<Tcoffee> limits;
\r
54 public static final String KEY_VALUE_SEPARATOR = "=";
\r
57 * Number of cores to use, defaults to 1 for local execution or the value of
\r
58 * "tcoffee.cluster.cpunum" property for cluster execution
\r
60 private int ncoreNumber = 0;
\r
63 * Number of cores parameter name
\r
65 private final static String ncorePrm = "-n_core";
\r
69 * @param workDirectory
\r
72 super(KEY_VALUE_SEPARATOR);
\r
74 * Use "-quiet" to disable sdtout and progress to stderr inorder=input -
\r
75 * prevent t-coffee from sorting sequences
\r
77 addParameters(Arrays.asList("-output=clustalw"));
\r
78 setInput(super.inputFile);
\r
82 public Tcoffee setInput(String inFile) {
\r
83 super.setInput(inFile);
\r
84 cbuilder.setParam("-seq", inFile);
\r
88 @SuppressWarnings("unchecked")
\r
90 public Alignment getResults(String workDirectory)
\r
91 throws ResultNotAvailableException {
\r
93 return Util.readClustalFile(workDirectory, getOutput());
\r
94 } catch (FileNotFoundException e) {
\r
95 log.error(e.getMessage(), e.getCause());
\r
96 throw new ResultNotAvailableException(e);
\r
97 } catch (IOException e) {
\r
98 log.error(e.getMessage(), e.getCause());
\r
99 throw new ResultNotAvailableException(e);
\r
100 } catch (UnknownFileFormatException e) {
\r
101 log.error(e.getMessage(), e.getCause());
\r
102 throw new ResultNotAvailableException(e);
\r
103 } catch (NullPointerException e) {
\r
104 log.error(e.getMessage(), e.getCause());
\r
105 throw new ResultNotAvailableException(e);
\r
110 public List<String> getCreatedFiles() {
\r
111 return Arrays.asList(getOutput());
\r
114 public void setNCore(int ncoreNumber) {
\r
115 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
116 throw new IndexOutOfBoundsException(
\r
117 "Number of cores must be within 1 and 100 ");
\r
119 this.ncoreNumber = ncoreNumber;
\r
120 cbuilder.setParam(ncorePrm, Integer.toString(getNCore()));
\r
124 return ncoreNumber;
\r
128 public CommandBuilder<Tcoffee> getParameters(ExecProvider provider) {
\r
129 // Limit number of cores to 1 for ANY execution which does not set
\r
130 // Ncores explicitly using setNCore method
\r
131 if (ncoreNumber == 0) {
\r
134 if (provider == Executable.ExecProvider.Cluster) {
\r
135 int cpunum = getClusterCpuNum();
\r
140 return super.getParameters(provider);
\r
144 public Limit<Tcoffee> getLimit(String presetName) {
\r
145 if (limits == null) {
\r
146 limits = getLimits();
\r
149 Limit<Tcoffee> limit = null;
\r
150 if (limits != null) {
\r
151 // this returns default limit if preset is undefined!
\r
152 limit = limits.getLimitByName(presetName);
\r
154 // If limit is not defined for a particular preset, then return default
\r
156 if (limit == null) {
\r
157 log.debug("Limit for the preset " + presetName
\r
158 + " is not found. Using default");
\r
159 limit = limits.getDefaultLimit();
\r
165 public LimitsManager<Tcoffee> getLimits() {
\r
166 // synchronise on static field
\r
167 synchronized (log) {
\r
168 if (limits == null) {
\r
169 limits = Util.getLimits(this.getClass());
\r
176 public String getNativeSpecs() {
\r
177 return getClusterSettings();
\r
182 * @return number of cpus to use on the cluster or 0 if the value is
\r
185 public static int getClusterCpuNum() {
\r
187 String cpuNum = ph.getProperty("tcoffee.cluster.cpunum");
\r
188 if (compbio.util.Util.isEmpty(cpuNum)) {
\r
192 cpus = Integer.parseInt(cpuNum);
\r
193 } catch (NumberFormatException e) {
\r
196 .debug("Number of cpus to use for cluster execution is defined but could not be parsed as integer! Given value is: "
\r
200 if (cpus < 1 || cpus > 100) {
\r
201 throw new InvalidParameterException(
\r
202 "Number of cpu for cluster execution must be within 1 and 100! "
\r
203 + "Look at the value of 'tcoffee.cluster.cpunum' property. Given value is "
\r
210 public Class<? extends Executable<?>> getType() {
\r
211 return this.getClass();
\r