X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=runner%2Fcompbio%2Frunner%2FUtil.java;h=8d778644f8f3e5f9431a4649c5c398e5c76f6763;hb=c97b1954611988b2b1d2e9aeec6e4b0696a0ab66;hp=a3c86c6a87d3b8bebfa887540f1dbff9478c0a04;hpb=535359a3d592ee41bda72e7356f0181f6cee9d07;p=jabaws.git diff --git a/runner/compbio/runner/Util.java b/runner/compbio/runner/Util.java index a3c86c6..8d77864 100644 --- a/runner/compbio/runner/Util.java +++ b/runner/compbio/runner/Util.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 @@ -23,127 +23,112 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; import compbio.data.sequence.Alignment; import compbio.data.sequence.ClustalAlignmentUtil; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.Score; import compbio.data.sequence.SequenceUtil; import compbio.data.sequence.UnknownFileFormatException; import compbio.engine.client.ConfExecutable; import compbio.engine.client.ConfiguredExecutable; import compbio.engine.client.Executable; import compbio.engine.conf.PropertyHelperManager; -import compbio.metadata.LimitsManager; +import compbio.metadata.JobSubmissionException; import compbio.metadata.PresetManager; import compbio.metadata.RunnerConfig; import compbio.util.PropertyHelper; public final class Util { - private static Logger log = Logger.getLogger(Util.class); - - private static final PropertyHelper ph = PropertyHelperManager - .getPropertyHelper(); - - public static final String SPACE = " "; - - /** - * For now just assume that all parameters which came in needs setting it - * will be a client responsibility to prepare RunnerConfig object then - * - * @param rconfig - * @return - * - * public static List toOptionString(RunnerConfig - * rconfig) { String option = ""; List options = new - * ArrayList(); for (Parameter par : - * rconfig.getParameters()) { if (par.getPossibleValues().isEmpty()) - * { option = par.getOptionName(); } else { option = - * par.getOptionName() + "=" + par.getPossibleValues().get(0); } // - * separate options options.add(option); } return options; } - */ - - public static LimitsManager getLimits( - Class> clazz) { - LimitsManager limits = null; - try { - limits = ConfExecutable.getRunnerLimits(clazz); - if (limits == null) { + public static Logger log = Logger.getLogger(Util.class); + + private static final PropertyHelper ph = PropertyHelperManager + .getPropertyHelper(); + + public static final String SPACE = " "; + + public static synchronized RunnerConfig getSupportedOptions( + Class> clazz) { + try { + return ConfExecutable.getRunnerOptions(clazz); + } catch (FileNotFoundException e) { + log.error( + "Could not load " + clazz + " Parameters !" + + e.getMessage(), e.getCause()); + } catch (IOException e) { + log.error("IO exception while reading " + clazz + " Parameters !" + + e.getMessage(), e.getCause()); + } return null; - } - } catch (FileNotFoundException e) { - log.warn("No limits are found for " + clazz + " executable! " - + e.getLocalizedMessage(), e.getCause()); - return null; - } catch (IOException e) { - log.warn("IO exception while attempting to read limits for " - + clazz + " executable! " + e.getLocalizedMessage(), e - .getCause()); - return null; } - return limits; - } - public static synchronized RunnerConfig getSupportedOptions( - Class> clazz) { - try { - return ConfExecutable.getRunnerOptions(clazz); - } catch (FileNotFoundException e) { - log.error("Could not load " + clazz + " Parameters !" - + e.getMessage(), e.getCause()); - } catch (IOException e) { - log.error("IO exception while reading " + clazz + " Parameters !" - + e.getMessage(), e.getCause()); + public static PresetManager getPresets( + Class> clazz) { + try { + return ConfExecutable.getRunnerPresets(clazz); + } catch (FileNotFoundException e) { + log.warn( + "No presets are found for " + clazz + " executable! " + + e.getLocalizedMessage(), e.getCause()); + } catch (IOException e) { + log.warn("IO exception while reading presents! for " + clazz + + " executable! " + e.getLocalizedMessage(), e.getCause()); + } + return null; } - return null; - } - public static PresetManager getPresets( - Class> clazz) { - try { - return ConfExecutable.getRunnerPresets(clazz); - } catch (FileNotFoundException e) { - log.warn("No presets are found for " + clazz + " executable! " - + e.getLocalizedMessage(), e.getCause()); - } catch (IOException e) { - log.warn("IO exception while reading presents! for " + clazz - + " executable! " + e.getLocalizedMessage(), e.getCause()); + public static final Alignment readClustalFile(String workDirectory, + String clustFile) throws UnknownFileFormatException, IOException, + FileNotFoundException, NullPointerException { + assert !compbio.util.Util.isEmpty(workDirectory); + assert !compbio.util.Util.isEmpty(clustFile); + File cfile = new File(compbio.engine.client.Util.getFullPath( + workDirectory, clustFile)); + log.trace("CLUSTAL OUTPUT FILE PATH: " + cfile.getAbsolutePath()); + if (!(cfile.exists() && cfile.length() > 0)) { + throw new FileNotFoundException("Result for the jobId " + + workDirectory + " with file name " + clustFile + + " is not found!"); + } + return ClustalAlignmentUtil.readClustalFile(cfile); } - return null; - } - public static final Alignment readClustalFile(String workDirectory, - String clustFile) throws UnknownFileFormatException, IOException, - FileNotFoundException, NullPointerException { - assert !compbio.util.Util.isEmpty(workDirectory); - assert !compbio.util.Util.isEmpty(clustFile); - File cfile = new File(compbio.engine.client.Util.getFullPath( - workDirectory, clustFile)); - log.trace("CLUSTAL OUTPUT FILE PATH: " + cfile.getAbsolutePath()); - if (!(cfile.exists() && cfile.length() > 0)) { - throw new FileNotFoundException("Result for the jobId " - + workDirectory + " with file name " + clustFile - + " is not found!"); + public static final Map readJronnFile(String workDirectory, + String clustFile) throws UnknownFileFormatException, IOException, + FileNotFoundException, NullPointerException { + assert !compbio.util.Util.isEmpty(workDirectory); + assert !compbio.util.Util.isEmpty(clustFile); + File cfile = new File(compbio.engine.client.Util.getFullPath( + workDirectory, clustFile)); + log.trace("Jronn OUTPUT FILE PATH: " + cfile.getAbsolutePath()); + if (!(cfile.exists() && cfile.length() > 0)) { + throw new FileNotFoundException("Result for the jobId " + + workDirectory + " with file name " + clustFile + + " is not found!"); + } + return SequenceUtil.readJRonn(cfile); } - return ClustalAlignmentUtil.readClustalFile(cfile); - } - - public static void writeInput(List sequences, - ConfiguredExecutable exec) { - File filein = new File(exec.getInput()); - try { - FileOutputStream fout = new FileOutputStream(filein); - log.debug("File path: " + filein.getAbsolutePath()); - SequenceUtil.writeFasta(fout, sequences); - fout.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + public static void writeInput(List sequences, + ConfiguredExecutable exec) throws JobSubmissionException { + + try { + File filein = new File(exec.getInput()); + FileOutputStream fout = new FileOutputStream(filein); + log.debug("File path: " + filein.getAbsolutePath()); + SequenceUtil.writeFasta(fout, sequences); + fout.close(); + } catch (IOException e) { + log.error("IOException while writing input file into the disk: " + + e.getLocalizedMessage(), e); + throw new JobSubmissionException( + "We are sorry by JABAWS server seems to have a problem! " + + e.getLocalizedMessage(), e); + } } - } }