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
29 import org.apache.log4j.Logger;
\r
31 import compbio.data.sequence.AnnotatedSequence;
\r
32 import compbio.data.sequence.SequenceUtil;
\r
33 import compbio.data.sequence.UnknownFileFormatException;
\r
34 import compbio.engine.client.Executable;
\r
35 import compbio.engine.client.SkeletalExecutable;
\r
36 import compbio.metadata.Limit;
\r
37 import compbio.metadata.LimitsManager;
\r
38 import compbio.metadata.ResultNotAvailableException;
\r
39 import compbio.runner.Util;
\r
44 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
49 public class Jronn extends SkeletalExecutable<Jronn> {
\r
51 private static Logger log = Logger.getLogger(Jronn.class);
\r
53 // Cache for Limits information
\r
54 private static LimitsManager<Jronn> limits;
\r
56 public static final String KEY_VALUE_SEPARATOR = Util.SPACE;
\r
57 public static final String STAT_FILE = "stat.txt";
\r
60 addParameters(Arrays.asList("-jar", getLibPath(), "-n=1", "-s="
\r
61 + STAT_FILE, "-f=H"));
\r
64 @SuppressWarnings("unchecked")
\r
66 public List<AnnotatedSequence> getResults(String workDirectory)
\r
67 throws ResultNotAvailableException {
\r
68 List<AnnotatedSequence> sequences = null;
\r
70 InputStream inStream = new FileInputStream(new File(workDirectory,
\r
72 sequences = SequenceUtil.readJRonn(inStream);
\r
74 } catch (FileNotFoundException e) {
\r
75 log.error(e.getMessage(), e.getCause());
\r
76 throw new ResultNotAvailableException(e);
\r
77 } catch (IOException e) {
\r
78 log.error(e.getMessage(), e.getCause());
\r
79 throw new ResultNotAvailableException(e);
\r
80 } catch (UnknownFileFormatException 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("jronn.jar.file");
\r
93 if (compbio.util.Util.isEmpty(settings)) {
\r
94 throw new NullPointerException(
\r
95 "Please define jronn.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 // Jronn 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 Jronn setInput(String inFile) {
\r
113 super.setInput(inFile);
\r
114 cbuilder.setParam("-i=" + inFile);
\r
119 public Jronn setOutput(String outFile) {
\r
120 super.setOutput(outFile);
\r
121 cbuilder.setParam("-o=" + outFile);
\r
126 public Limit<Jronn> getLimit(String presetName) {
\r
127 if (limits == null) {
\r
128 limits = getLimits();
\r
130 Limit<Jronn> limit = null;
\r
131 if (limits != null) {
\r
132 // this returns default limit if preset is undefined!
\r
133 limit = limits.getLimitByName(presetName);
\r
135 // If limit is not defined for a particular preset, then return default
\r
137 if (limit == null) {
\r
138 log.debug("Limit for the preset " + presetName
\r
139 + " is not found. Using default");
\r
140 limit = limits.getDefaultLimit();
\r
146 public LimitsManager<Jronn> getLimits() {
\r
147 // synchronise on static field
\r
148 synchronized (log) {
\r
149 if (limits == null) {
\r
150 limits = Util.getLimits(this.getClass());
\r
157 public Class<? extends Executable<?>> getType() {
\r
158 return this.getClass();
\r
161 public static String getStatFile() {
\r