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.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.Executable;
\r
31 import compbio.engine.client.PipedExecutable;
\r
32 import compbio.engine.client.SkeletalExecutable;
\r
33 import compbio.metadata.Limit;
\r
34 import compbio.metadata.LimitsManager;
\r
35 import compbio.metadata.ResultNotAvailableException;
\r
36 import compbio.runner.Util;
\r
38 public class Mafft extends SkeletalExecutable<Mafft> implements
\r
39 PipedExecutable<Mafft> {
\r
41 private static Logger log = Logger.getLogger(Mafft.class);
\r
43 // Cache for Limits information
\r
44 private static LimitsManager<Mafft> limits;
\r
46 private static String autoOption = "--auto";
\r
48 private final String MATRIX_PAR_NAME = "--aamatrix";
\r
50 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
53 // remove default input to prevent it to appear in the parameters list
\r
54 // that could happen if the parameters are set first
\r
55 // super.setInput("");
\r
56 addParameters(Arrays.asList("--clustalout", autoOption));
\r
59 @SuppressWarnings("unchecked")
\r
60 public Alignment getResults(String workDirectory)
\r
61 throws ResultNotAvailableException {
\r
63 return Util.readClustalFile(workDirectory, getOutput());
\r
64 } catch (FileNotFoundException e) {
\r
65 log.error(e.getMessage(), e.getCause());
\r
66 throw new ResultNotAvailableException(e);
\r
67 } catch (IOException e) {
\r
68 log.error(e.getMessage(), e.getCause());
\r
69 throw new ResultNotAvailableException(e);
\r
70 } catch (UnknownFileFormatException e) {
\r
71 log.error(e.getMessage(), e.getCause());
\r
72 throw new ResultNotAvailableException(e);
\r
73 } catch (NullPointerException e) {
\r
74 log.error(e.getMessage(), e.getCause());
\r
75 throw new ResultNotAvailableException(e);
\r
80 public Mafft setInput(String inFile) {
\r
81 super.setInput(inFile);
\r
82 cbuilder.setLast(inFile);
\r
87 * Mafft input must always be the last parameter!
\r
90 public Mafft addParameters(List<String> parameters) {
\r
91 cbuilder.addParams(parameters);
\r
92 cbuilder.removeParam(autoOption);
\r
97 public Limit<Mafft> getLimit(String presetName) {
\r
98 if (limits == null) {
\r
99 limits = getLimits();
\r
102 Limit<Mafft> limit = null;
\r
103 if (limits != null) {
\r
104 // this returns default limit if preset is undefined!
\r
105 limit = limits.getLimitByName(presetName);
\r
107 // If limit is not defined for a particular preset, then return default
\r
109 if (limit == null) {
\r
110 log.debug("Limit for the preset " + presetName
\r
111 + " is not found. Using default");
\r
112 limit = limits.getDefaultLimit();
\r
118 public LimitsManager<Mafft> getLimits() {
\r
119 // synchronise on static field
\r
120 synchronized (log) {
\r
121 if (limits == null) {
\r
122 limits = Util.getLimits(this.getClass());
\r
129 public Class<? extends Executable<?>> getType() {
\r
130 return this.getClass();
\r
134 * @Override public List<String> getParameters(
\r
135 * compbio.runner.Executable.ExecProvider provider) { for (int i = 0; i <
\r
136 * param.size(); i++) { String par = param.get(i); if
\r
137 * (isMatrixParameter(par)) { String matrixName = getValue(i); if (new
\r
138 * File(matrixName).isAbsolute()) { // Matrix can be found so no actions
\r
139 * necessary // This method has been called already and the matrix name //
\r
140 * is modified to contain full path // no further actions is necessary
\r
141 * break; } String matrixPath = Util.getExecProperty("matrix.path", this);
\r
142 * String absMatrixPath = Util.convertToAbsolute(matrixPath); param.remove(i
\r
143 * + 1); param.remove(i); super.addParameter(MATRIX_PAR_NAME);
\r
144 * super.addParameter(absMatrixPath + File.separator + matrixName); break; }
\r
145 * } return super.getParameters(provider); }
\r
147 * boolean isMatrixParameter(String parameter) { assert
\r
148 * !compbio.util.Util.isEmpty(parameter); if
\r
149 * (parameter.toUpperCase().startsWith(MATRIX_PAR_NAME)) { return true; }
\r
152 * String getValue(int i) { return param.get(i + 1); }
\r