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.disorder;
\r
21 import java.io.File;
\r
22 import java.io.FileInputStream;
\r
23 import java.io.FileNotFoundException;
\r
24 import java.io.IOException;
\r
25 import java.io.InputStream;
\r
26 import java.util.Arrays;
\r
27 import java.util.List;
\r
28 import java.util.Map;
\r
30 import org.apache.log4j.Logger;
\r
32 import compbio.data.sequence.Score;
\r
33 import compbio.data.sequence.SequenceUtil;
\r
34 import compbio.data.sequence.UnknownFileFormatException;
\r
35 import compbio.engine.client.CommandBuilder;
\r
36 import compbio.engine.client.Executable;
\r
37 import compbio.engine.client.SkeletalExecutable;
\r
38 import compbio.metadata.Limit;
\r
39 import compbio.metadata.LimitsManager;
\r
40 import compbio.metadata.ResultNotAvailableException;
\r
41 import compbio.runner.Util;
\r
46 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
51 public class Jronn extends SkeletalExecutable<Jronn> {
\r
53 private static Logger log = Logger.getLogger(Jronn.class);
\r
56 * Number of cores to use, defaults to 1 for local execution or the value of
\r
57 * "jronn.cluster.cpunum" property for cluster execution
\r
59 private int ncoreNumber = 0;
\r
61 private final String ncorePrm = "-n=";
\r
63 // Cache for Limits information
\r
64 private static LimitsManager<Jronn> limits;
\r
66 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
67 public static final String STAT_FILE = "stat.txt";
\r
70 addParameters(Arrays.asList("-jar", getLibPath(), "-s=" + STAT_FILE,
\r
74 @SuppressWarnings("unchecked")
\r
76 public Map<String, Score> getResults(String workDirectory)
\r
77 throws ResultNotAvailableException {
\r
78 Map<String, Score> sequences = null;
\r
80 InputStream inStream = new FileInputStream(new File(workDirectory,
\r
82 sequences = SequenceUtil.readJRonn(inStream);
\r
84 } catch (FileNotFoundException e) {
\r
85 log.error(e.getMessage(), e.getCause());
\r
86 throw new ResultNotAvailableException(e);
\r
87 } catch (IOException e) {
\r
88 log.error(e.getMessage(), e.getCause());
\r
89 throw new ResultNotAvailableException(e);
\r
90 } catch (UnknownFileFormatException e) {
\r
91 log.error(e.getMessage(), e.getCause());
\r
92 throw new ResultNotAvailableException(e);
\r
93 } catch (NullPointerException e) {
\r
94 log.error(e.getMessage(), e.getCause());
\r
95 throw new ResultNotAvailableException(e);
\r
100 private static String getLibPath() {
\r
102 String settings = ph.getProperty("jronn.jar.file");
\r
103 if (compbio.util.Util.isEmpty(settings)) {
\r
104 throw new NullPointerException(
\r
105 "Please define jronn.jar.file property in Executable.properties file"
\r
106 + "and initialize it with the location of jronn jar file");
\r
108 if (new File(settings).isAbsolute()) {
\r
109 // Jronn jar can be found so no actions necessary
\r
110 // no further actions is necessary
\r
113 return compbio.engine.client.Util.convertToAbsolute(settings);
\r
117 public List<String> getCreatedFiles() {
\r
118 return Arrays.asList(getOutput(), getError());
\r
122 public Jronn setInput(String inFile) {
\r
123 super.setInput(inFile);
\r
124 cbuilder.setParam("-i=" + inFile);
\r
129 public Jronn setOutput(String outFile) {
\r
130 super.setOutput(outFile);
\r
131 cbuilder.setParam("-o=" + outFile);
\r
136 public Limit<Jronn> getLimit(String presetName) {
\r
137 if (limits == null) {
\r
138 limits = getLimits();
\r
140 Limit<Jronn> limit = null;
\r
141 if (limits != null) {
\r
142 // this returns default limit if preset is undefined!
\r
143 limit = limits.getLimitByName(presetName);
\r
145 // If limit is not defined for a particular preset, then return default
\r
147 if (limit == null) {
\r
148 log.debug("Limit for the preset " + presetName
\r
149 + " is not found. Using default");
\r
150 limit = limits.getDefaultLimit();
\r
156 public LimitsManager<Jronn> getLimits() {
\r
157 // synchronise on static field
\r
158 synchronized (log) {
\r
159 if (limits == null) {
\r
160 limits = Util.getLimits(this.getClass());
\r
167 public Class<? extends Executable<?>> getType() {
\r
168 return this.getClass();
\r
171 public static String getStatFile() {
\r
175 public void setNCore(int ncoreNumber) {
\r
176 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
177 throw new IndexOutOfBoundsException(
\r
178 "Number of cores must be within 1 and 100 ");
\r
180 this.ncoreNumber = ncoreNumber;
\r
181 cbuilder.setParam(ncorePrm + Integer.toString(getNCore()));
\r
185 return ncoreNumber;
\r
189 public CommandBuilder<Jronn> getParameters(ExecProvider provider) {
\r
190 // If number of cores is provided, set it for the cluster execution
\r
192 if (provider == Executable.ExecProvider.Cluster) {
\r
193 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
194 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
197 // Limit number of cores to 1 for ANY execution which does not set
\r
198 // Ncores explicitly using setNCore method or is run on local VM
\r
199 if (ncoreNumber == 0) {
\r
203 return super.getParameters(provider);
\r