1 /* Copyright (c) 2013 Alexander Sherstnev
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 3.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.predictors;
\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.metadata.ResultNotAvailableException;
\r
41 * jpred.pl -in d16vpa_.fas -out res_d16vpa_ -dbname ported_db -dbpath /data/UNIREFdb -ncpu 4
\r
43 * @author asherstnev
\r
46 public class Jpred extends SkeletalExecutable<Jpred> {
\r
48 private static Logger log = Logger.getLogger(Jpred.class);
\r
51 * Number of cores to use, defaults to 1 for local execution or the value of
\r
52 * "jpred.cluster.cpunum" property for cluster execution
\r
54 private int ncoreNumber = 0;
\r
56 public static final String KEY_VALUE_SEPARATOR = " ";
\r
57 public static final String STAT_FILE = "stat.txt";
\r
60 // addParameters(Arrays.asList());
\r
62 // HashMap<Method, float[]>
\r
64 public ScoreManager getResults(String workDirectory)
\r
65 throws ResultNotAvailableException {
\r
66 ScoreManager annotations = null;
\r
68 InputStream inStream = new FileInputStream(new File(workDirectory, getOutput()));
\r
69 annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil.readAAConResults(inStream));
\r
71 } catch (FileNotFoundException e) {
\r
72 log.error(e.getMessage(), e.getCause());
\r
73 throw new ResultNotAvailableException(e);
\r
74 } catch (IOException e) {
\r
75 log.error(e.getMessage(), e.getCause());
\r
76 throw new ResultNotAvailableException(e);
\r
77 } catch (NullPointerException e) {
\r
78 log.error(e.getMessage(), e.getCause());
\r
79 throw new ResultNotAvailableException(e);
\r
85 public List<String> getCreatedFiles() {
\r
86 return Arrays.asList(getOutput(), getError());
\r
90 public Jpred setInput(String inFile) {
\r
91 super.setInput(inFile);
\r
92 cbuilder.setParam("-in " + inFile);
\r
97 public Jpred setOutput(String outFile) {
\r
98 super.setOutput(outFile);
\r
99 cbuilder.setParam("-out " + outFile);
\r
103 @SuppressWarnings("unchecked")
\r
105 public Class<Jpred> getType() {
\r
106 return (Class<Jpred>) this.getClass();
\r
109 public static String getStatFile() {
\r
113 public void setNCore(int ncoreNumber) {
\r
114 if (0 < ncoreNumber && ncoreNumber < 9) {
\r
115 this.ncoreNumber = ncoreNumber;
\r
116 cbuilder.setParam("-ncpu " + Integer.toString(getNCore()));
\r
118 throw new IndexOutOfBoundsException("Number of cores must be between 1 and 8 ");
\r
123 return ncoreNumber;
\r
127 public CommandBuilder<Jpred> getParameters(ExecProvider provider) {
\r
128 // If number of cores is provided, set it for the cluster execution only!
\r
129 if (provider == Executable.ExecProvider.Cluster) {
\r
130 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
131 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
134 // Limit number of cores to 1 for ANY execution which does not set
\r
135 // Ncores explicitly using setNCore method or is run on local VM
\r
136 if (ncoreNumber == 0) {
\r
140 return super.getParameters(provider);
\r