X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=runner%2Fcompbio%2Frunner%2Fmsa%2FTcoffee.java;h=645b994913eb58cca53825f1b1f1c8d0d43add63;hb=ba2d4e920e433bd080f448248e7dacade69a27a0;hp=2fd2283ce489fc3931b83ffabe88a52cccf6eaa6;hpb=535359a3d592ee41bda72e7356f0181f6cee9d07;p=jabaws.git diff --git a/runner/compbio/runner/msa/Tcoffee.java b/runner/compbio/runner/msa/Tcoffee.java index 2fd2283..645b994 100644 --- a/runner/compbio/runner/msa/Tcoffee.java +++ b/runner/compbio/runner/msa/Tcoffee.java @@ -1,6 +1,6 @@ -/* Copyright (c) 2009 Peter Troshin +/* Copyright (c) 2011 Peter Troshin * - * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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 @@ -20,7 +20,6 @@ package compbio.runner.msa; import java.io.FileNotFoundException; import java.io.IOException; -import java.security.InvalidParameterException; import java.util.Arrays; import java.util.List; @@ -28,186 +27,114 @@ import org.apache.log4j.Logger; import compbio.data.sequence.Alignment; import compbio.data.sequence.UnknownFileFormatException; -import compbio.engine.client.ClusterNativeSpecExecutable; import compbio.engine.client.CommandBuilder; import compbio.engine.client.Executable; import compbio.engine.client.PipedExecutable; import compbio.engine.client.SkeletalExecutable; import compbio.engine.conf.PropertyHelperManager; -import compbio.metadata.Limit; -import compbio.metadata.LimitsManager; import compbio.metadata.ResultNotAvailableException; import compbio.runner.Util; import compbio.util.PropertyHelper; -public class Tcoffee extends SkeletalExecutable implements - PipedExecutable, ClusterNativeSpecExecutable { +public class Tcoffee extends SkeletalExecutable + implements + PipedExecutable { - private static Logger log = Logger.getLogger(Tcoffee.class); + private static Logger log = Logger.getLogger(Tcoffee.class); - private static PropertyHelper ph = PropertyHelperManager - .getPropertyHelper(); + private static PropertyHelper ph = PropertyHelperManager + .getPropertyHelper(); - // Cache for Limits information - private static LimitsManager limits; + public static final String KEY_VALUE_SEPARATOR = "="; - public static final String KEY_VALUE_SEPARATOR = "="; - - /** - * Number of cores to use, defaults to 1 for local execution or the value of - * "tcoffee.cluster.cpunum" property for cluster execution - */ - private int ncoreNumber = 0; - - /* - * Number of cores parameter name - */ - private final static String ncorePrm = "-n_core"; + /** + * Number of cores to use, defaults to 1 for local execution or the value of + * "tcoffee.cluster.cpunum" property for cluster execution + */ + private int ncoreNumber = 0; - /** - * - * @param workDirectory - */ - public Tcoffee() { - super(KEY_VALUE_SEPARATOR); /* - * Use "-quiet" to disable sdtout and progress to stderr inorder=input - - * prevent t-coffee from sorting sequences + * Number of cores parameter name */ - addParameters(Arrays.asList("-output=clustalw")); - setInput(super.inputFile); - } - - @Override - public Tcoffee setInput(String inFile) { - super.setInput(inFile); - cbuilder.setParam("-seq", inFile); - return this; - } - - @SuppressWarnings("unchecked") - @Override - public Alignment getResults(String workDirectory) - throws ResultNotAvailableException { - try { - return Util.readClustalFile(workDirectory, getOutput()); - } 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 (UnknownFileFormatException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } catch (NullPointerException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } - } + private final static String ncorePrm = "-n_core"; - @Override - public List getCreatedFiles() { - return Arrays.asList(getOutput()); - } - - public void setNCore(int ncoreNumber) { - if (ncoreNumber < 1 || ncoreNumber > 100) { - throw new IndexOutOfBoundsException( - "Number of cores must be within 1 and 100 "); - } - this.ncoreNumber = ncoreNumber; - cbuilder.setParam(ncorePrm, Integer.toString(getNCore())); - } - - int getNCore() { - return ncoreNumber; - } - - @Override - public CommandBuilder getParameters(ExecProvider provider) { - // Limit number of cores to 1 for ANY execution which does not set - // Ncores explicitly using setNCore method - if (ncoreNumber == 0) { - setNCore(1); - } - if (provider == Executable.ExecProvider.Cluster) { - int cpunum = getClusterCpuNum(); - if (cpunum != 0) { - setNCore(cpunum); - } + /** + */ + public Tcoffee() { + super(KEY_VALUE_SEPARATOR); + /* + * Use "-quiet" to disable sdtout and progress to stderr inorder=input - + * prevent t-coffee from sorting sequences + */ + addParameters(Arrays.asList("-output=clustalw")); + setInput(super.inputFile); } - return super.getParameters(provider); - } - @Override - public Limit getLimit(String presetName) { - if (limits == null) { - limits = getLimits(); + @Override + public Tcoffee setInput(String inFile) { + super.setInput(inFile); + cbuilder.setParam("-seq", inFile); + return this; } - Limit limit = null; - if (limits != null) { - // this returns default limit if preset is undefined! - limit = limits.getLimitByName(presetName); - } - // If limit is not defined for a particular preset, then return default - // limit - if (limit == null) { - log.debug("Limit for the preset " + presetName - + " is not found. Using default"); - limit = limits.getDefaultLimit(); + @SuppressWarnings("unchecked") + @Override + public Alignment getResults(String workDirectory) + throws ResultNotAvailableException { + try { + return Util.readClustalFile(workDirectory, getOutput()); + } 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 (UnknownFileFormatException 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 limit; - } - - @Override - public LimitsManager getLimits() { - // synchronise on static field - synchronized (log) { - if (limits == null) { - limits = Util.getLimits(this.getClass()); - } + + @Override + public List getCreatedFiles() { + return Arrays.asList(getOutput()); } - return limits; - } - - @Override - public String getNativeSpecs() { - return getClusterSettings(); - } - - /** - * - * @return number of cpus to use on the cluster or 0 if the value is - * undefined - */ - public static int getClusterCpuNum() { - int cpus = 0; - String cpuNum = ph.getProperty("tcoffee.cluster.cpunum"); - if (compbio.util.Util.isEmpty(cpuNum)) { - return 0; + + public void setNCore(int ncoreNumber) { + if (ncoreNumber < 1 || ncoreNumber > 100) { + throw new IndexOutOfBoundsException( + "Number of cores must be within 1 and 100 "); + } + this.ncoreNumber = ncoreNumber; + cbuilder.setParam(ncorePrm, Integer.toString(getNCore())); } - try { - cpus = Integer.parseInt(cpuNum); - } catch (NumberFormatException e) { - // safe to ignore - log - .debug("Number of cpus to use for cluster execution is defined but could not be parsed as integer! Given value is: " - + cpuNum); - return 0; + + int getNCore() { + return ncoreNumber; } - if (cpus < 1 || cpus > 100) { - throw new InvalidParameterException( - "Number of cpu for cluster execution must be within 1 and 100! " - + "Look at the value of 'tcoffee.cluster.cpunum' property. Given value is " - + cpus); + + @Override + public CommandBuilder getParameters(ExecProvider provider) { + // Limit number of cores to 1 for ANY execution which does not set + // Ncores explicitly using setNCore method + if (ncoreNumber == 0) { + setNCore(1); + } + if (provider == Executable.ExecProvider.Cluster) { + int cpunum = SkeletalExecutable.getClusterCpuNum(getType()); + if (cpunum != 0) { + setNCore(cpunum); + } + } + return super.getParameters(provider); } - return cpus; - } - @Override - public Class> getType() { - return this.getClass(); - } + @SuppressWarnings("unchecked") + @Override + public Class getType() { + return (Class) this.getClass(); + } }