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.PipedExecutable;
\r
31 import compbio.engine.client.SkeletalExecutable;
\r
32 import compbio.metadata.ResultNotAvailableException;
\r
33 import compbio.runner.Util;
\r
35 public class Mafft extends SkeletalExecutable<Mafft>
\r
37 PipedExecutable<Mafft> {
\r
39 private static Logger log = Logger.getLogger(Mafft.class);
\r
41 private static String autoOption = "--auto";
\r
43 private final String MATRIX_PAR_NAME = "--aamatrix";
\r
45 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
48 // remove default input to prevent it to appear in the parameters list
\r
49 // that could happen if the parameters are set first
\r
50 // super.setInput("");
\r
51 addParameters(Arrays.asList("--clustalout", autoOption));
\r
54 @SuppressWarnings("unchecked")
\r
55 public Alignment getResults(String workDirectory)
\r
56 throws ResultNotAvailableException {
\r
58 return Util.readClustalFile(workDirectory, getOutput());
\r
59 } catch (FileNotFoundException e) {
\r
60 log.error(e.getMessage(), e.getCause());
\r
61 throw new ResultNotAvailableException(e);
\r
62 } catch (IOException e) {
\r
63 log.error(e.getMessage(), e.getCause());
\r
64 throw new ResultNotAvailableException(e);
\r
65 } catch (UnknownFileFormatException e) {
\r
66 log.error(e.getMessage(), e.getCause());
\r
67 throw new ResultNotAvailableException(e);
\r
68 } catch (NullPointerException e) {
\r
69 log.error(e.getMessage(), e.getCause());
\r
70 throw new ResultNotAvailableException(e);
\r
75 public Mafft setInput(String inFile) {
\r
76 super.setInput(inFile);
\r
77 cbuilder.setLast(inFile);
\r
82 * Mafft input must always be the last parameter!
\r
85 public Mafft addParameters(List<String> parameters) {
\r
86 cbuilder.addParams(parameters);
\r
87 cbuilder.removeParam(autoOption);
\r
91 @SuppressWarnings("unchecked")
\r
93 public Class<Mafft> getType() {
\r
94 return (Class<Mafft>) this.getClass();
\r
98 * @Override public List<String> getParameters(
\r
99 * compbio.runner.Executable.ExecProvider provider) { for (int i = 0; i <
\r
100 * param.size(); i++) { String par = param.get(i); if
\r
101 * (isMatrixParameter(par)) { String matrixName = getValue(i); if (new
\r
102 * File(matrixName).isAbsolute()) { // Matrix can be found so no actions
\r
103 * necessary // This method has been called already and the matrix name //
\r
104 * is modified to contain full path // no further actions is necessary
\r
105 * break; } String matrixPath = Util.getExecProperty("matrix.path", this);
\r
106 * String absMatrixPath = Util.convertToAbsolute(matrixPath); param.remove(i
\r
107 * + 1); param.remove(i); super.addParameter(MATRIX_PAR_NAME);
\r
108 * super.addParameter(absMatrixPath + File.separator + matrixName); break; }
\r
109 * } return super.getParameters(provider); }
\r
111 * boolean isMatrixParameter(String parameter) { assert
\r
112 * !compbio.util.Util.isEmpty(parameter); if
\r
113 * (parameter.toUpperCase().startsWith(MATRIX_PAR_NAME)) { return true; }
\r
116 * String getValue(int i) { return param.get(i + 1); }
\r