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.SkeletalExecutable;
\r
31 import compbio.metadata.ResultNotAvailableException;
\r
32 import compbio.runner.RunnerUtil;
\r
34 public class ClustalW extends SkeletalExecutable<ClustalW> {
\r
36 private static Logger log = Logger.getLogger(ClustalW.class);
\r
37 private static final String EXEC_STAT_FILE = "stat.log";
\r
38 private static final String TREE_FILE_EXT = ".dnd";
\r
40 public static final String KEY_VALUE_SEPARATOR = "=";
\r
43 super(KEY_VALUE_SEPARATOR);
\r
44 addParameters(Arrays.asList("-OUTORDER=ALIGNED", "-QUIET", "-STATS="
\r
46 // set default in, outs and err files
\r
47 this.setInput(super.inputFile);
\r
48 this.setOutput(super.outputFile);
\r
49 this.setError(super.errorFile);
\r
53 public ClustalW setOutput(String outFile) {
\r
54 super.setOutput(outFile);
\r
55 cbuilder.setParam("-OUTFILE=" + outFile);
\r
60 public ClustalW setInput(String inFile) {
\r
61 super.setInput(inFile);
\r
62 cbuilder.setParam("-INFILE=" + inFile);
\r
66 @SuppressWarnings("unchecked")
\r
67 public Alignment getResults(String workDirectory)
\r
68 throws ResultNotAvailableException {
\r
70 return RunnerUtil.readClustalFile(workDirectory, getOutput());
\r
71 } catch (FileNotFoundException e) {
\r
72 log.error(e.getMessage(), e.getCause());
\r
73 throw new ResultNotAvailableException(e);
\r
74 } catch (IOException e) {
\r
75 log.error(e.getMessage(), e.getCause());
\r
76 throw new ResultNotAvailableException(e);
\r
77 } catch (UnknownFileFormatException e) {
\r
78 log.error(e.getMessage(), e.getCause());
\r
79 throw new ResultNotAvailableException(e);
\r
80 } catch (NullPointerException e) {
\r
81 log.error(e.getMessage(), e.getCause());
\r
82 throw new ResultNotAvailableException(e);
\r
87 public List<String> getCreatedFiles() {
\r
88 return Arrays.asList(getOutput(), EXEC_STAT_FILE,
\r
89 convertInputNameToTreeName());
\r
93 * Clustal output tree with same name as input file but .dnd extension e.g.
\r
94 * this methods do similar conversion TO122.fasta -> TO122.dnd or
\r
95 * TO122.fasta.in -> TO122.fasta.dnd It does not seems that there is any
\r
96 * limits on the name length
\r
100 private String convertInputNameToTreeName() {
\r
101 assert super.getInput() != null;
\r
102 int dotIdx = getInput().lastIndexOf(".");
\r
103 String treeFileName = "";
\r
105 treeFileName = getInput().substring(0, dotIdx);
\r
107 return treeFileName + TREE_FILE_EXT;
\r
110 public static String getStatFile() {
\r
111 return EXEC_STAT_FILE;
\r
114 @SuppressWarnings("unchecked")
\r
116 public Class<ClustalW> getType() {
\r
117 return (Class<ClustalW>) this.getClass();
\r