2 * Copyright (c) 2009 Peter Troshin JAva Bioinformatics Analysis Web Services
\r
3 * (JABAWS) @version: 1.0 This library is free software; you can redistribute it
\r
4 * and/or modify it under the terms of the Apache License version 2 as published
\r
5 * by the Apache Software Foundation This library is distributed in the hope
\r
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
7 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
8 * Apache License for more details. A copy of the license is in
\r
9 * apache_license.txt. It is also available here:
\r
10 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or
\r
11 * derived work distributed in source code form must include this copyright and
\r
15 package compbio.runner.conservation;
\r
17 import java.io.File;
\r
18 import java.io.FileInputStream;
\r
19 import java.io.FileNotFoundException;
\r
20 import java.io.IOException;
\r
21 import java.io.InputStream;
\r
22 import java.util.Arrays;
\r
23 import java.util.List;
\r
25 import org.apache.log4j.Logger;
\r
27 import compbio.data.sequence.SMERFSConstraints;
\r
28 import compbio.data.sequence.ScoreManager;
\r
29 import compbio.data.sequence.SequenceUtil;
\r
30 import compbio.engine.client.CommandBuilder;
\r
31 import compbio.engine.client.Executable;
\r
32 import compbio.engine.client.SkeletalExecutable;
\r
33 import compbio.metadata.ResultNotAvailableException;
\r
38 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
43 public class AACon extends SkeletalExecutable<AACon> {
\r
45 private static Logger log = Logger.getLogger(AACon.class);
\r
48 * Number of cores to use, defaults to 1 for local execution or the value of
\r
49 * "jronn.cluster.cpunum" property for cluster execution
\r
51 private int ncoreNumber = 0;
\r
53 private final String ncorePrm = "-t=";
\r
55 public static final String KEY_VALUE_SEPARATOR = "=";
\r
56 public static final String STAT_FILE = "stat.txt";
\r
58 private final int windowWidth = SMERFSConstraints.DEFAULT_WINDOW_SIZE;
\r
59 private final SMERFSConstraints colScoreMethod = SMERFSConstraints.MID_SCORE;
\r
60 private final double gapTreshold = SMERFSConstraints.DEFAULT_GAP_THRESHOLD;
\r
63 addParameters(Arrays.asList("-jar", getLibPath(), "-d=" + STAT_FILE,
\r
64 "-f=RESULT_NO_ALIGNMENT"));
\r
66 // HashMap<Method, float[]>
\r
68 public ScoreManager getResults(String workDirectory)
\r
69 throws ResultNotAvailableException {
\r
70 ScoreManager annotations = null;
\r
72 InputStream inStream = new FileInputStream(new File(workDirectory,
\r
74 annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil
\r
75 .readAAConResults(inStream));
\r
77 } catch (FileNotFoundException e) {
\r
78 log.error(e.getMessage(), e.getCause());
\r
79 throw new ResultNotAvailableException(e);
\r
80 } catch (IOException e) {
\r
81 log.error(e.getMessage(), e.getCause());
\r
82 throw new ResultNotAvailableException(e);
\r
83 } catch (NullPointerException e) {
\r
84 log.error(e.getMessage(), e.getCause());
\r
85 throw new ResultNotAvailableException(e);
\r
90 private static String getLibPath() {
\r
92 String settings = ph.getProperty("aacon.jar.file");
\r
93 if (compbio.util.Util.isEmpty(settings)) {
\r
94 throw new NullPointerException(
\r
95 "Please define aacon.jar.file property in Executable.properties file"
\r
96 + "and initialize it with the location of jronn jar file");
\r
98 if (new File(settings).isAbsolute()) {
\r
99 // the jar can be found so no actions necessary
\r
100 // no further actions is necessary
\r
103 return compbio.engine.client.Util.convertToAbsolute(settings);
\r
107 public List<String> getCreatedFiles() {
\r
108 return Arrays.asList(getOutput(), getError());
\r
112 public AACon setInput(String inFile) {
\r
113 super.setInput(inFile);
\r
114 cbuilder.setParam("-i=" + inFile);
\r
119 public AACon setOutput(String outFile) {
\r
120 super.setOutput(outFile);
\r
121 cbuilder.setParam("-o=" + outFile);
\r
125 @SuppressWarnings("unchecked")
\r
127 public Class<AACon> getType() {
\r
128 return (Class<AACon>) this.getClass();
\r
131 public static String getStatFile() {
\r
135 public void setNCore(int ncoreNumber) {
\r
136 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
137 throw new IndexOutOfBoundsException(
\r
138 "Number of cores must be within 1 and 100 ");
\r
140 this.ncoreNumber = ncoreNumber;
\r
141 cbuilder.setParam(ncorePrm + Integer.toString(getNCore()));
\r
145 return ncoreNumber;
\r
149 public CommandBuilder<AACon> getParameters(ExecProvider provider) {
\r
150 // If number of cores is provided, set it for the cluster execution
\r
152 if (provider == Executable.ExecProvider.Cluster) {
\r
153 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
154 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
157 // Limit number of cores to 1 for ANY execution which does not set
\r
158 // Ncores explicitly using setNCore method or is run on local VM
\r
159 if (ncoreNumber == 0) {
\r
163 return super.getParameters(provider);
\r