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
25 import org.apache.log4j.Logger;
\r
27 import compbio.data.sequence.Alignment;
\r
28 import compbio.data.sequence.UnknownFileFormatException;
\r
29 import compbio.engine.client.CommandBuilder;
\r
30 import compbio.engine.client.Executable;
\r
31 import compbio.engine.client.SkeletalExecutable;
\r
32 import compbio.engine.client.Executable.ExecProvider;
\r
33 import compbio.metadata.ResultNotAvailableException;
\r
34 import compbio.runner.RunnerUtil;
\r
36 public class ClustalO extends SkeletalExecutable<ClustalO> {
\r
38 private static Logger log = Logger.getLogger(ClustalO.class);
\r
40 private static final String EXEC_STAT_FILE = "stat.log";
\r
42 public static final String KEY_VALUE_SEPARATOR = "=";
\r
45 * Number of cores parameter name
\r
47 private final static String ncorePrm = "--threads";
\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 * --threads=<n> Number of processors to use
\r
58 * -l, --log=<file> Log all non-essential output to this file
\r
61 super(KEY_VALUE_SEPARATOR);
\r
62 addParameters(Arrays.asList("--outfmt=clustal", "-v", "--log=" + EXEC_STAT_FILE));
\r
63 // set default in, outs and err files
\r
64 this.setInput(super.inputFile);
\r
65 this.setOutput(super.outputFile);
\r
66 this.setError(super.errorFile);
\r
70 public ClustalO setOutput(String outFile) {
\r
71 super.setOutput(outFile);
\r
72 cbuilder.setParam("--outfile=" + outFile);
\r
77 public ClustalO setInput(String inFile) {
\r
78 super.setInput(inFile);
\r
79 cbuilder.setParam("--infile=" + inFile);
\r
83 @SuppressWarnings("unchecked")
\r
84 public Alignment getResults(String workDirectory)
\r
85 throws ResultNotAvailableException {
\r
87 return RunnerUtil.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
103 public static String getStatFile() {
\r
104 return EXEC_STAT_FILE;
\r
107 @SuppressWarnings("unchecked")
\r
109 public Class<ClustalO> getType() {
\r
110 return (Class<ClustalO>) this.getClass();
\r
114 public CommandBuilder<ClustalO> getParameters(ExecProvider provider) {
\r
115 // Limit number of cores to 1 for ANY execution which does not set
\r
116 // Ncores explicitly using setNCore method
\r
117 if (ncoreNumber == 0) {
\r
120 if (provider == Executable.ExecProvider.Cluster) {
\r
121 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
126 return super.getParameters(provider);
\r
129 public void setNCore(int ncoreNumber) {
\r
130 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
131 throw new IndexOutOfBoundsException("Number of cores must be within 1 and 100 ");
\r
133 this.ncoreNumber = ncoreNumber;
\r
134 cbuilder.setParam(ncorePrm, Integer.toString(getNCore()));
\r
138 return ncoreNumber;
\r