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.security.InvalidParameterException;
\r
27 import java.util.Arrays;
\r
28 import java.util.List;
\r
30 import org.apache.log4j.Logger;
\r
32 import compbio.data.sequence.AnnotatedSequence;
\r
33 import compbio.data.sequence.SequenceUtil;
\r
34 import compbio.data.sequence.UnknownFileFormatException;
\r
35 import compbio.engine.client.Executable;
\r
36 import compbio.engine.client.SkeletalExecutable;
\r
37 import compbio.metadata.Limit;
\r
38 import compbio.metadata.LimitsManager;
\r
39 import compbio.metadata.ResultNotAvailableException;
\r
40 import compbio.runner.Util;
\r
45 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
50 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 String ncorePrm = "-n";
\r
64 // Cache for Limits information
\r
65 private static LimitsManager<Jronn> limits;
\r
67 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
68 public static final String STAT_FILE = "stat.txt";
\r
71 addParameters(Arrays.asList("-jar", getLibPath(), "-s="
\r
72 + STAT_FILE, "-f=H"));
\r
75 @SuppressWarnings("unchecked")
\r
77 public List<AnnotatedSequence> getResults(String workDirectory)
\r
78 throws ResultNotAvailableException {
\r
79 List<AnnotatedSequence> sequences = null;
\r
81 InputStream inStream = new FileInputStream(new File(workDirectory,
\r
83 sequences = SequenceUtil.readJRonn(inStream);
\r
85 } catch (FileNotFoundException e) {
\r
86 log.error(e.getMessage(), e.getCause());
\r
87 throw new ResultNotAvailableException(e);
\r
88 } catch (IOException e) {
\r
89 log.error(e.getMessage(), e.getCause());
\r
90 throw new ResultNotAvailableException(e);
\r
91 } catch (UnknownFileFormatException e) {
\r
92 log.error(e.getMessage(), e.getCause());
\r
93 throw new ResultNotAvailableException(e);
\r
94 } catch (NullPointerException e) {
\r
95 log.error(e.getMessage(), e.getCause());
\r
96 throw new ResultNotAvailableException(e);
\r
101 private static String getLibPath() {
\r
103 String settings = ph.getProperty("jronn.jar.file");
\r
104 if (compbio.util.Util.isEmpty(settings)) {
\r
105 throw new NullPointerException(
\r
106 "Please define jronn.jar.file property in Executable.properties file"
\r
107 + "and initialize it with the location of jronn jar file");
\r
109 if (new File(settings).isAbsolute()) {
\r
110 // Jronn jar can be found so no actions necessary
\r
111 // no further actions is necessary
\r
114 return compbio.engine.client.Util.convertToAbsolute(settings);
\r
118 public List<String> getCreatedFiles() {
\r
119 return Arrays.asList(getOutput(), getError());
\r
123 public Jronn setInput(String inFile) {
\r
124 super.setInput(inFile);
\r
125 cbuilder.setParam("-i=" + inFile);
\r
130 public Jronn setOutput(String outFile) {
\r
131 super.setOutput(outFile);
\r
132 cbuilder.setParam("-o=" + outFile);
\r
137 public Limit<Jronn> getLimit(String presetName) {
\r
138 if (limits == null) {
\r
139 limits = getLimits();
\r
141 Limit<Jronn> limit = null;
\r
142 if (limits != null) {
\r
143 // this returns default limit if preset is undefined!
\r
144 limit = limits.getLimitByName(presetName);
\r
146 // If limit is not defined for a particular preset, then return default
\r
148 if (limit == null) {
\r
149 log.debug("Limit for the preset " + presetName
\r
150 + " is not found. Using default");
\r
151 limit = limits.getDefaultLimit();
\r
157 public LimitsManager<Jronn> getLimits() {
\r
158 // synchronise on static field
\r
159 synchronized (log) {
\r
160 if (limits == null) {
\r
161 limits = Util.getLimits(this.getClass());
\r
168 public Class<? extends Executable<?>> getType() {
\r
169 return this.getClass();
\r
172 public static String getStatFile() {
\r
176 public void setNCore(int ncoreNumber) {
\r
177 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
178 throw new IndexOutOfBoundsException(
\r
179 "Number of cores must be within 1 and 100 ");
\r
181 this.ncoreNumber = ncoreNumber;
\r
182 cbuilder.setParam(ncorePrm, Integer.toString(getNCore()));
\r
186 return ncoreNumber;
\r