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 /data/UNIREFdb -ncpu 4
\r
45 * @author asherstnev
\r
48 public class Jpred extends SkeletalExecutable<Jpred> {
\r
50 private static Logger log = Logger.getLogger(Jpred.class);
\r
53 * Number of cores to use, defaults to 1 for local execution or the value of
\r
54 * "jpred.cluster.cpunum" property for cluster execution
\r
56 private int ncoreNumber = 0;
\r
58 public static final String KEY_VALUE_SEPARATOR = " ";
\r
59 public static final String STAT_FILE = "stat.txt";
\r
62 addParameters(Arrays.asList("-logfile " + STAT_FILE));
\r
63 addParameters(Arrays.asList("-jabaws"));
\r
66 // HashMap<Method, float[]>
\r
67 @SuppressWarnings("unchecked")
\r
69 public JpredAlignment getResults(String workDirectory)
\r
70 throws ResultNotAvailableException {
\r
71 JpredAlignment annotations = null;
\r
73 InputStream inStream = new FileInputStream(new File(workDirectory, getOutput()));
\r
74 annotations = new JpredAlignment(SequenceUtil.readJpredFile(inStream), new AlignmentMetadata(Program.Jpred, '-'));
\r
75 } catch (FileNotFoundException e) {
\r
76 log.error(e.getMessage(), e.getCause());
\r
77 throw new ResultNotAvailableException(e);
\r
78 } catch (IOException e) {
\r
79 log.error(e.getMessage(), e.getCause());
\r
80 throw new ResultNotAvailableException(e);
\r
81 } catch (NullPointerException e) {
\r
82 log.error(e.getMessage(), e.getCause());
\r
83 throw new ResultNotAvailableException(e);
\r
89 public List<String> getCreatedFiles() {
\r
90 return Arrays.asList(getOutput(), getError());
\r
94 public Jpred setInput(String inFile) {
\r
95 super.setInput(inFile);
\r
96 cbuilder.setParam("-in " + inFile);
\r
101 public Jpred setOutput(String outFile) {
\r
102 super.setOutput(outFile);
\r
103 cbuilder.setParam("-outfile " + outFile);
\r
107 @SuppressWarnings("unchecked")
\r
109 public Class<Jpred> getType() {
\r
110 return (Class<Jpred>) this.getClass();
\r
113 public static String getStatFile() {
\r
117 public void setNCore(int ncoreNumber) {
\r
118 if (0 < ncoreNumber && ncoreNumber < 9) {
\r
119 this.ncoreNumber = ncoreNumber;
\r
120 cbuilder.setParam("-ncpu " + Integer.toString(getNCore()));
\r
122 throw new IndexOutOfBoundsException("Number of cores must be between 1 and 8 ");
\r
127 return ncoreNumber;
\r
131 public CommandBuilder<Jpred> getParameters(ExecProvider provider) {
\r
132 // If number of cores is provided, set it for the cluster execution only!
\r
133 if (provider == Executable.ExecProvider.Cluster) {
\r
134 int cpunum = SkeletalExecutable.getClusterCpuNum(getType());
\r
135 cpunum = (cpunum == 0) ? 1 : cpunum;
\r
138 // Limit number of cores to 1 for ANY execution which does not set
\r
139 // Ncores explicitly using setNCore method or is run on local VM
\r
140 if (ncoreNumber == 0) {
\r
144 return super.getParameters(provider);
\r