1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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.conservation;
\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.ScoreManager;
\r
32 import compbio.data.sequence.SequenceUtil;
\r
33 import compbio.engine.client.CommandBuilder;
\r
34 import compbio.engine.client.Executable;
\r
35 import compbio.engine.client.SkeletalExecutable;
\r
36 import compbio.engine.client.EngineUtil;
\r
37 import compbio.metadata.ResultNotAvailableException;
\r
42 * java -Xmx512 -jar jronn_v3.jar -i=test_seq.txt -n=1 -o=out.txt -s=stat.out
\r
47 public class AACon extends SkeletalExecutable<AACon> {
\r
49 private static Logger log = Logger.getLogger(AACon.class);
\r
52 * Number of cores to use, defaults to 1 for local execution or the value of
\r
53 * "jronn.cluster.cpunum" property for cluster execution
\r
55 private int ncoreNumber = 0;
\r
57 private final String ncorePrm = "-t=";
\r
59 public static final String KEY_VALUE_SEPARATOR = "=";
\r
60 public static final String STAT_FILE = "stat.txt";
\r
63 addParameters(Arrays.asList("-jar", getLibPath(), "-d=" + STAT_FILE, "-f=RESULT_NO_ALIGNMENT"));
\r
66 // HashMap<Method, float[]>
\r
68 public ScoreManager getResults(String workDirectory) throws ResultNotAvailableException {
\r
69 ScoreManager annotations = null;
\r
71 InputStream inStream = new FileInputStream(new File(workDirectory, getOutput()));
\r
72 annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil.readAAConResults(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 (NullPointerException e) {
\r
81 log.error(e.getMessage(), e.getCause());
\r
82 throw new ResultNotAvailableException(e);
\r
87 private static String getLibPath() {
\r
89 String settings = ph.getProperty("aacon.jar.file");
\r
90 if (compbio.util.Util.isEmpty(settings)) {
\r
91 throw new NullPointerException("Please define aacon.jar.file property in Executable.properties file "
\r
92 + "and initialize it with the location of aaconservation jar file");
\r
94 if (new File(settings).isAbsolute()) {
\r
95 // the jar can be found so no actions necessary
\r
96 // no further actions is necessary
\r
99 return EngineUtil.convertToAbsolute(settings);
\r
103 public List<String> getCreatedFiles() {
\r
104 return Arrays.asList(getOutput(), getError());
\r
108 public AACon setInput(String inFile) {
\r
109 super.setInput(inFile);
\r
110 cbuilder.setParam("-i=" + inFile);
\r
115 public AACon setOutput(String outFile) {
\r
116 super.setOutput(outFile);
\r
117 cbuilder.setParam("-o=" + outFile);
\r
121 @SuppressWarnings("unchecked")
\r
123 public Class<AACon> getType() {
\r
124 return (Class<AACon>) this.getClass();
\r
127 public static String getStatFile() {
\r
131 public void setNCore(int ncoreNumber) {
\r
132 if (ncoreNumber < 1 || ncoreNumber > 100) {
\r
133 throw new IndexOutOfBoundsException("Number of cores must be within 1 and 100 ");
\r
135 this.ncoreNumber = ncoreNumber;
\r
136 cbuilder.setParam(ncorePrm + Integer.toString(getNCore()));
\r
140 return ncoreNumber;
\r
144 public CommandBuilder<AACon> getParameters(ExecProvider provider) {
\r
145 // If number of cores is provided, set it for the cluster execution
\r
147 if (provider == Executable.ExecProvider.Cluster) {
\r
148 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
149 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
152 // Limit number of cores to 1 for ANY execution which does not set
\r
153 // Ncores explicitly using setNCore method or is run on local VM
\r
154 if (ncoreNumber == 0) {
\r
158 return super.getParameters(provider);
\r