X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=runner%2Fcompbio%2Frunner%2FUtil.java;h=6f0ec09bc576e9475b53ef88e849460be04e68ff;hb=4b647613e686c4edffd44702d86662c6facb2d5a;hp=2f040aa80f363b41e439f32fa060b0798e256924;hpb=8033a51860de2200a54e64add0809d6780f5b092;p=jabaws.git diff --git a/runner/compbio/runner/Util.java b/runner/compbio/runner/Util.java index 2f040aa..6f0ec09 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 @@ -19,76 +19,56 @@ package compbio.runner; import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Arrays; import java.util.List; +import java.util.ArrayList; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.TreeMap; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.Scanner; + + + import org.apache.log4j.Logger; import compbio.data.sequence.Alignment; import compbio.data.sequence.ClustalAlignmentUtil; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.RNAStructScoreManager; import compbio.data.sequence.Score; +import compbio.data.sequence.ScoreManager; +import compbio.data.sequence.Range; +import compbio.data.sequence.RNAStructReader; 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); + public 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) { - 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 { @@ -152,19 +132,92 @@ public final class Util { } public static void writeInput(List sequences, - ConfiguredExecutable exec) { + ConfiguredExecutable exec) throws JobSubmissionException { - File filein = new File(exec.getInput()); 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 (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { - e.printStackTrace(); + 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); } } + + public static void writeClustalInput(List sequences, + ConfiguredExecutable exec, char gapChar) throws JobSubmissionException { + + try { + File filein = new File(exec.getInput()); + FileOutputStream fout = new FileOutputStream(filein); + log.debug("File path: " + filein.getAbsolutePath()); + SequenceUtil.writeClustal(fout, sequences, gapChar); + fout.close(); + } catch (IOException e) { + log.error("IOException while writing input file into the disk: " + + e.getLocalizedMessage(), e); + throw new JobSubmissionException( + "We are sorry but JABAWS server seems to have a problem! " + + e.getLocalizedMessage(), e); + } + } + + + public static RNAStructScoreManager readRNAStruct(String workDirectory, + String structFile) throws IOException, FileNotFoundException { + + assert !compbio.util.Util.isEmpty(workDirectory); + assert !compbio.util.Util.isEmpty(structFile); + // The stdout from RNAalifold + File sFile = new File(compbio.engine.client.Util.getFullPath( + workDirectory, structFile)); + // Base pair probability matrix (-p option) + File aliFile = new File(compbio.engine.client.Util.getFullPath( + workDirectory, "alifold.out")); + // Check that stdout file exists + if(!(sFile.exists() && sFile.length() > 0)) { + throw new FileNotFoundException("Result for the jobId " + + workDirectory + "with file name " + structFile + + " is not found!"); + } + // Check that base pair probability file exists + if(!aliFile.exists()) { + log.warn("The file alifold.out is not found for the jobId " + + workDirectory + "Is the -p or --MEA option not specified?"); + return RNAStructReader.readRNAStructStream(new FileInputStream(sFile)); + + } else { + return RNAStructReader.readRNAStructStream(new FileInputStream(sFile), + new FileInputStream(aliFile)); + } + } + + + public static String readFile(File inputFile) throws + FileNotFoundException, IOException { + + BufferedReader input = new BufferedReader(new FileReader(inputFile)); + + String file = new String(); + String line = new String(); + + while (true) { + line = input.readLine(); + + if (line != null) { + file = file + line + "\r\n"; + } else break; + } + // Close file + input.close(); + return file; + } } + +