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.JpredAlignment;
\r
32 import compbio.data.sequence.AlignmentMetadata;
\r
33 import compbio.data.sequence.Program;
\r
34 import compbio.data.sequence.SequenceUtil;
\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.ResultNotAvailableException;
\r
43 * jpred.pl -in d16vpa_.fas -outfile res_d16vpa_ -dbname ported_db -dbpath
\r
44 * /data/UNIREFdb -ncpu 4
\r
46 * @author asherstnev
\r
49 public class Jpred extends SkeletalExecutable<Jpred> {
\r
51 private static Logger log = Logger.getLogger(Jpred.class);
\r
54 * Number of cores to use, defaults to 1 for local execution or the value of
\r
55 * "jpred.cluster.cpunum" property for cluster execution
\r
57 private int ncoreNumber = 0;
\r
59 public static final String KEY_VALUE_SEPARATOR = " ";
\r
60 public static final String STAT_FILE = "stat.txt";
\r
63 String dbpath = ph.getProperty("jpred.data.uniref.path");
\r
64 String dbname = ph.getProperty("jpred.data.uniref.name");
\r
65 addParameters(Arrays.asList("-logfile " + STAT_FILE));
\r
66 addParameters(Arrays.asList("-dbpath " + dbpath));
\r
67 addParameters(Arrays.asList("-dbname " + dbname));
\r
68 addParameters(Arrays.asList("-jabaws"));
\r
71 // HashMap<Method, float[]>
\r
72 @SuppressWarnings("unchecked")
\r
74 public JpredAlignment getResults(String workDirectory) throws ResultNotAvailableException {
\r
75 JpredAlignment annotations = null;
\r
77 InputStream inStream = new FileInputStream(new File(workDirectory, getOutput()));
\r
78 annotations = new JpredAlignment(SequenceUtil.readJpredFile(inStream), new AlignmentMetadata(Program.Jpred, '-'));
\r
79 } catch (FileNotFoundException e) {
\r
80 log.error(e.getMessage(), e.getCause());
\r
81 throw new ResultNotAvailableException(e);
\r
82 } catch (IOException e) {
\r
83 log.error(e.getMessage(), e.getCause());
\r
84 throw new ResultNotAvailableException(e);
\r
85 } catch (NullPointerException e) {
\r
86 log.error(e.getMessage(), e.getCause());
\r
87 throw new ResultNotAvailableException(e);
\r
93 public List<String> getCreatedFiles() {
\r
94 return Arrays.asList(getOutput(), getError());
\r
98 public Jpred setInput(String inFile) {
\r
99 super.setInput(inFile);
\r
100 cbuilder.setParam("-in " + inFile);
\r
105 public Jpred setOutput(String outFile) {
\r
106 super.setOutput(outFile);
\r
107 cbuilder.setParam("-outfile " + outFile);
\r
111 @SuppressWarnings("unchecked")
\r
113 public Class<Jpred> getType() {
\r
114 return (Class<Jpred>) this.getClass();
\r
117 public static String getStatFile() {
\r
121 public void setNCore(int ncoreNumber) {
\r
122 if (0 < ncoreNumber && ncoreNumber < 9) {
\r
123 this.ncoreNumber = ncoreNumber;
\r
124 cbuilder.setParam("-ncpu " + Integer.toString(getNCore()));
\r
126 throw new IndexOutOfBoundsException("Number of cores must be between 1 and 8 ");
\r
131 return ncoreNumber;
\r
135 public CommandBuilder<Jpred> getParameters(ExecProvider provider) {
\r
136 // If number of cores is provided, set it for the cluster execution
\r
138 if (provider == Executable.ExecProvider.Cluster) {
\r
139 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
140 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
143 // Limit number of cores to 1 for ANY execution which does not set
\r
144 // Ncores explicitly using setNCore method or is run on local VM
\r
145 if (ncoreNumber == 0) {
\r
149 return super.getParameters(provider);
\r