1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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.util.Arrays;
\r
24 import java.util.List;
\r
26 import org.apache.log4j.Logger;
\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.RunnerUtil;
\r
37 import compbio.util.PropertyHelper;
\r
39 public class Tcoffee extends SkeletalExecutable<Tcoffee>
\r
41 PipedExecutable<Tcoffee> {
\r
43 private static Logger log = Logger.getLogger(Tcoffee.class);
\r
45 private static PropertyHelper ph = PropertyHelperManager.getPropertyHelper();
\r
47 public static final String KEY_VALUE_SEPARATOR = "=";
\r
50 * Number of cores to use, defaults to 1 for local execution or the value of
\r
51 * "tcoffee.cluster.cpunum" property for cluster execution
\r
53 private int ncoreNumber = 0;
\r
56 * Number of cores parameter name
\r
58 private final static String ncorePrm = "-n_core";
\r
63 super(KEY_VALUE_SEPARATOR);
\r
65 * Use "-quiet" to disable sdtout and progress to stderr inorder=input -
\r
66 * prevent t-coffee from sorting sequences
\r
68 addParameters(Arrays.asList("-output=clustalw"));
\r
69 setInput(super.inputFile);
\r
73 public Tcoffee setInput(String inFile) {
\r
74 super.setInput(inFile);
\r
75 cbuilder.setParam("-seq", inFile);
\r
79 @SuppressWarnings("unchecked")
\r
81 public Alignment getResults(String workDirectory)
\r
82 throws ResultNotAvailableException {
\r
84 return RunnerUtil.readClustalFile(workDirectory, getOutput());
\r
85 } catch (FileNotFoundException e) {
\r
86 log.error(e.getMessage(), e.getCause());
\r
87 throw new ResultNotAvailableException(e);
\r
88 } catch (IOException e) {
\r
89 log.error(e.getMessage(), e.getCause());
\r
90 throw new ResultNotAvailableException(e);
\r
91 } catch (UnknownFileFormatException e) {
\r
92 log.error(e.getMessage(), e.getCause());
\r
93 throw new ResultNotAvailableException(e);
\r
94 } catch (NullPointerException e) {
\r
95 log.error(e.getMessage(), e.getCause());
\r
96 throw new ResultNotAvailableException(e);
\r
101 public List<String> getCreatedFiles() {
\r
102 return Arrays.asList(getOutput());
\r
105 public void setNCore(int ncoreNumber) {
\r
106 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
107 throw new IndexOutOfBoundsException(
\r
108 "Number of cores must be within 1 and 100 ");
\r
110 this.ncoreNumber = ncoreNumber;
\r
111 cbuilder.setParam(ncorePrm, Integer.toString(getNCore()));
\r
115 return ncoreNumber;
\r
119 public CommandBuilder<Tcoffee> getParameters(ExecProvider provider) {
\r
120 // Limit number of cores to 1 for ANY execution which does not set
\r
121 // Ncores explicitly using setNCore method
\r
122 if (ncoreNumber == 0) {
\r
125 if (provider == Executable.ExecProvider.Cluster) {
\r
126 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
131 return super.getParameters(provider);
\r
134 @SuppressWarnings("unchecked")
\r
136 public Class<Tcoffee> getType() {
\r
137 return (Class<Tcoffee>) this.getClass();
\r