From 9162b52a4bed5155831e19605228c866e1832586 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Fri, 2 Aug 2013 17:20:05 +0100 Subject: [PATCH] Add Java wrapper class for Jpred --- runner/compbio/runner/predictors/Jpred.java | 143 +++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 runner/compbio/runner/predictors/Jpred.java diff --git a/runner/compbio/runner/predictors/Jpred.java b/runner/compbio/runner/predictors/Jpred.java new file mode 100644 index 0000000..017dcfc --- /dev/null +++ b/runner/compbio/runner/predictors/Jpred.java @@ -0,0 +1,143 @@ +/* Copyright (c) 2013 Alexander Sherstnev + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 3.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ + +package compbio.runner.predictors; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +import org.apache.log4j.Logger; + +import compbio.data.sequence.ScoreManager; +import compbio.data.sequence.SequenceUtil; +import compbio.engine.client.CommandBuilder; +import compbio.engine.client.Executable; +import compbio.engine.client.SkeletalExecutable; +import compbio.metadata.ResultNotAvailableException; + +/** + * Command line + * + * jpred.pl -in d16vpa_.fas -out res_d16vpa_ -dbname ported_db -dbpath /data/UNIREFdb -ncpu 4 + * + * @author asherstnev + * + */ +public class Jpred extends SkeletalExecutable { + + private static Logger log = Logger.getLogger(Jpred.class); + + /** + * Number of cores to use, defaults to 1 for local execution or the value of + * "jpred.cluster.cpunum" property for cluster execution + */ + private int ncoreNumber = 0; + + public static final String KEY_VALUE_SEPARATOR = " "; + public static final String STAT_FILE = "stat.txt"; + + public Jpred() { +// addParameters(Arrays.asList()); + } + // HashMap + @Override + public ScoreManager getResults(String workDirectory) + throws ResultNotAvailableException { + ScoreManager annotations = null; + try { + InputStream inStream = new FileInputStream(new File(workDirectory, getOutput())); + annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil.readAAConResults(inStream)); + inStream.close(); + } catch (FileNotFoundException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (IOException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (NullPointerException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } + return annotations; + } + + @Override + public List getCreatedFiles() { + return Arrays.asList(getOutput(), getError()); + } + + @Override + public Jpred setInput(String inFile) { + super.setInput(inFile); + cbuilder.setParam("-in " + inFile); + return this; + } + + @Override + public Jpred setOutput(String outFile) { + super.setOutput(outFile); + cbuilder.setParam("-out " + outFile); + return this; + } + + @SuppressWarnings("unchecked") + @Override + public Class getType() { + return (Class) this.getClass(); + } + + public static String getStatFile() { + return STAT_FILE; + } + + public void setNCore(int ncoreNumber) { + if (0 < ncoreNumber && ncoreNumber < 9) { + this.ncoreNumber = ncoreNumber; + cbuilder.setParam("-ncpu " + Integer.toString(getNCore())); + } else { + throw new IndexOutOfBoundsException("Number of cores must be between 1 and 8 "); + } + } + + int getNCore() { + return ncoreNumber; + } + + @Override + public CommandBuilder getParameters(ExecProvider provider) { + // If number of cores is provided, set it for the cluster execution only! + if (provider == Executable.ExecProvider.Cluster) { + int cpunum = SkeletalExecutable.getClusterCpuNum(getType()); + cpunum = (cpunum == 0) ? 1 : cpunum; + setNCore(cpunum); + } else { + // Limit number of cores to 1 for ANY execution which does not set + // Ncores explicitly using setNCore method or is run on local VM + if (ncoreNumber == 0) { + setNCore(1); + } + } + return super.getParameters(provider); + } + +} -- 1.7.10.2