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.conservation.Method;
\r
28 import compbio.conservation.ResultReader;
\r
29 import compbio.data.sequence.MultiAnnotatedSequence;
\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.Limit;
\r
34 import compbio.metadata.LimitsManager;
\r
35 import compbio.metadata.ResultNotAvailableException;
\r
36 import compbio.runner.Util;
\r
41 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
46 public class AACon extends SkeletalExecutable<AACon> {
\r
48 private static Logger log = Logger.getLogger(AACon.class);
\r
51 * Number of cores to use, defaults to 1 for local execution or the value of
\r
52 * "jronn.cluster.cpunum" property for cluster execution
\r
54 private int ncoreNumber = 0;
\r
56 private final String ncorePrm = "-n=";
\r
58 // Cache for Limits information
\r
59 private static LimitsManager<AACon> limits;
\r
61 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
62 public static final String STAT_FILE = "stat.txt";
\r
65 addParameters(Arrays.asList("-jar", getLibPath(), "-d=" + STAT_FILE,
\r
66 "-f=RESULT_NO_ALIGNMENT"));
\r
69 @SuppressWarnings("unchecked")
\r
71 public MultiAnnotatedSequence<Method> getResults(String workDirectory)
\r
72 throws ResultNotAvailableException {
\r
73 MultiAnnotatedSequence<Method> annotations = null;
\r
75 InputStream inStream = new FileInputStream(new File(workDirectory,
\r
77 annotations = ResultReader.readResults(inStream);
\r
79 } catch (FileNotFoundException e) {
\r
80 log.error(e.getMessage(), e.getCause());
\r
81 throw new ResultNotAvailableException(e);
\r
82 } catch (IOException e) {
\r
83 log.error(e.getMessage(), e.getCause());
\r
84 throw new ResultNotAvailableException(e);
\r
85 } catch (NullPointerException e) {
\r
86 log.error(e.getMessage(), e.getCause());
\r
87 throw new ResultNotAvailableException(e);
\r
92 private static String getLibPath() {
\r
94 String settings = ph.getProperty("aacon.jar.file");
\r
95 if (compbio.util.Util.isEmpty(settings)) {
\r
96 throw new NullPointerException(
\r
97 "Please define aacon.jar.file property in Executable.properties file"
\r
98 + "and initialize it with the location of jronn jar file");
\r
100 if (new File(settings).isAbsolute()) {
\r
101 // Jronn jar can be found so no actions necessary
\r
102 // no further actions is necessary
\r
105 return compbio.engine.client.Util.convertToAbsolute(settings);
\r
109 public List<String> getCreatedFiles() {
\r
110 return Arrays.asList(getOutput(), getError());
\r
114 public AACon setInput(String inFile) {
\r
115 super.setInput(inFile);
\r
116 cbuilder.setParam("-i=" + inFile);
\r
121 public AACon setOutput(String outFile) {
\r
122 super.setOutput(outFile);
\r
123 cbuilder.setParam("-o=" + outFile);
\r
128 public Limit<AACon> getLimit(String presetName) {
\r
129 if (limits == null) {
\r
130 limits = getLimits();
\r
132 Limit<AACon> limit = null;
\r
133 if (limits != null) {
\r
134 // this returns default limit if preset is undefined!
\r
135 limit = limits.getLimitByName(presetName);
\r
137 // If limit is not defined for a particular preset, then return default
\r
139 if (limit == null) {
\r
140 log.debug("Limit for the preset " + presetName
\r
141 + " is not found. Using default");
\r
142 limit = limits.getDefaultLimit();
\r
148 public LimitsManager<AACon> getLimits() {
\r
149 // synchronise on static field
\r
150 synchronized (log) {
\r
151 if (limits == null) {
\r
152 limits = Util.getLimits(this.getClass());
\r
159 public Class<? extends Executable<?>> getType() {
\r
160 return this.getClass();
\r
163 public static String getStatFile() {
\r
167 public void setNCore(int ncoreNumber) {
\r
168 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
169 throw new IndexOutOfBoundsException(
\r
170 "Number of cores must be within 1 and 100 ");
\r
172 this.ncoreNumber = ncoreNumber;
\r
173 cbuilder.setParam(ncorePrm + Integer.toString(getNCore()));
\r
177 return ncoreNumber;
\r
181 public CommandBuilder<AACon> getParameters(ExecProvider provider) {
\r
182 // If number of cores is provided, set it for the cluster execution
\r
184 if (provider == Executable.ExecProvider.Cluster) {
\r
185 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
186 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
189 // Limit number of cores to 1 for ANY execution which does not set
\r
190 // Ncores explicitly using setNCore method or is run on local VM
\r
191 if (ncoreNumber == 0) {
\r
195 return super.getParameters(provider);
\r