From 8033a51860de2200a54e64add0809d6780f5b092 Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Wed, 2 Feb 2011 16:30:22 +0000 Subject: [PATCH] Remove Annotated and MuptiAnnotated Sequence use Score instead git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3660 e3abac25-378b-4346-85de-24260fe3988d --- TODO.txt | 2 +- .../compbio/data/sequence/AnnotatedSequence.java | 61 --- .../compbio/data/sequence/DisorderMethod.java | 6 + .../data/sequence/MultiAnnotatedSequence.java | 82 ---- datamodel/compbio/data/sequence/Score.java | 18 +- datamodel/compbio/data/sequence/SequenceUtil.java | 53 +- runner/compbio/runner/Util.java | 233 ++++----- runner/compbio/runner/disorder/Disembl.java | 30 +- runner/compbio/runner/disorder/Jronn.java | 286 +++++------ .../compbio/data/sequence/SequenceUtilTester.java | 13 +- .../compbio/runner/conservation/AAConTester.java | 16 +- testsrc/compbio/runner/disorder/DisemblTester.java | 510 ++++++++++---------- testsrc/compbio/runner/disorder/JronnTester.java | 86 ++-- webservices/compbio/ws/client/IOHelper.java | 27 ++ webservices/compbio/ws/client/Jws2Client.java | 97 +++- webservices/compbio/ws/server/JronnWS.java | 177 +++++++ 16 files changed, 925 insertions(+), 772 deletions(-) delete mode 100644 datamodel/compbio/data/sequence/AnnotatedSequence.java create mode 100644 datamodel/compbio/data/sequence/DisorderMethod.java delete mode 100644 datamodel/compbio/data/sequence/MultiAnnotatedSequence.java create mode 100644 webservices/compbio/ws/server/JronnWS.java diff --git a/TODO.txt b/TODO.txt index 66b5984..f25cd0d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -28,7 +28,7 @@ new parsers for the above programmes output (Stockholm MSA format?) Think hard on what to do with large output files? e.g. serve the hits table in full, but retrieve alignments on demand. -What actually neeeds to be sent? +What actually needs to be sent? Add facility to distribute other results of the calculations like the trees and annotation file for probcons. diff --git a/datamodel/compbio/data/sequence/AnnotatedSequence.java b/datamodel/compbio/data/sequence/AnnotatedSequence.java deleted file mode 100644 index 65dbce9..0000000 --- a/datamodel/compbio/data/sequence/AnnotatedSequence.java +++ /dev/null @@ -1,61 +0,0 @@ -package compbio.data.sequence; - -import java.util.Arrays; - -public class AnnotatedSequence extends FastaSequence { - - private float[] annotation; - - private AnnotatedSequence() { - super(); - // JAXB default constructor - } - - public AnnotatedSequence(String id, String sequence, float[] annotation) { - super(id, sequence); - this.annotation = annotation; - if (annotation == null || annotation.length != sequence.length()) { - throw new IllegalArgumentException("The length of the annotation (" - + ((annotation != null) ? annotation.length : "0") - + ") does not match the length of the sequence (" - + sequence.length() + ")!"); - } - } - - public AnnotatedSequence(FastaSequence fsequence, float[] annotation) { - this(fsequence.getId(), fsequence.getSequence(), annotation); - } - - public float[] getAnnotation() { - return annotation; - } - - @Override - public int hashCode() { - final int prime = 7; - int result = super.hashCode(); - result = prime * result + Arrays.hashCode(annotation); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - AnnotatedSequence other = (AnnotatedSequence) obj; - if (!Arrays.equals(annotation, other.annotation)) - return false; - return true; - } - - @Override - public String toString() { - return super.toString() + "Annotation:\n " - + Arrays.toString(annotation) + "\n"; - } - -} diff --git a/datamodel/compbio/data/sequence/DisorderMethod.java b/datamodel/compbio/data/sequence/DisorderMethod.java new file mode 100644 index 0000000..521d9a3 --- /dev/null +++ b/datamodel/compbio/data/sequence/DisorderMethod.java @@ -0,0 +1,6 @@ +package compbio.data.sequence; + +public enum DisorderMethod { + + JRonn, Disembl +} diff --git a/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java b/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java deleted file mode 100644 index 1212a7d..0000000 --- a/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java +++ /dev/null @@ -1,82 +0,0 @@ -package compbio.data.sequence; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -import compbio.util.annotation.NotThreadSafe; - -/** - * TODO complete - * - * @author pvtroshin - * - * @param - * enum type - */ -@NotThreadSafe -// @XmlAccessorType(XmlAccessType.FIELD) -public class MultiAnnotatedSequence> { - - private EnumMap> annotations; - - MultiAnnotatedSequence() { - // default constructor for JAXB - } - - public MultiAnnotatedSequence(Class enumeration) { - this.annotations = new EnumMap>(enumeration); - } - - public void addAnnotation(T type, ArrayList annotation) { - assert type != null : "Type is expected"; - assert annotation != null : "Not empty value is expected!"; - if (!annotations.isEmpty()) { - assert annotations.values().iterator().next().size() == annotation - .size() : "Annotations must contain the same number of elements!"; - } - this.annotations.put(type, annotation); - } - - public Map> getAnnotations() { - return new EnumMap>(this.annotations); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((annotations == null) ? 0 : annotations.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - MultiAnnotatedSequence other = (MultiAnnotatedSequence) obj; - if (annotations == null) { - if (other.annotations != null) - return false; - } else if (!annotations.equals(other.annotations)) - return false; - return true; - } - - @Override - public String toString() { - String value = ""; - for (Map.Entry> annt : annotations.entrySet()) { - value += annt.getKey() + " "; - value += annt.getValue() + "\n"; - } - return value; - } - -} diff --git a/datamodel/compbio/data/sequence/Score.java b/datamodel/compbio/data/sequence/Score.java index 98ba06a..8a110ee 100644 --- a/datamodel/compbio/data/sequence/Score.java +++ b/datamodel/compbio/data/sequence/Score.java @@ -34,7 +34,7 @@ public class Score { NUMBER_FORMAT.setMaximumFractionDigits(3); } - private ConservationMethod method; + private Enum method; private List scores; @@ -52,17 +52,29 @@ public class Score { * the actual conservation values for each column of the * alignment */ - public Score(ConservationMethod method, List scores) { + public Score(Enum method, List scores) { this.method = method; this.scores = new ArrayList(scores); } + public Score(Enum method, float[] scores) { + this.method = method; + this.scores = toList(scores); + } + + private List toList(float[] values) { + List vlist = new ArrayList(); + for (float v : values) { + vlist.add(new Float(v)); + } + return vlist; + } /** * Returns the ConservationMethod * * @return the ConservationMethod */ - public ConservationMethod getMethod() { + public Enum getMethod() { return method; } diff --git a/datamodel/compbio/data/sequence/SequenceUtil.java b/datamodel/compbio/data/sequence/SequenceUtil.java index f061ac7..85ae95f 100644 --- a/datamodel/compbio/data/sequence/SequenceUtil.java +++ b/datamodel/compbio/data/sequence/SequenceUtil.java @@ -25,9 +25,12 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Scanner; +import java.util.Set; import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -294,10 +297,10 @@ public final class SequenceUtil { outWriter.close(); } - public static List readJRonn(final File result) + public static Map readJRonn(final File result) throws IOException, UnknownFileFormatException { InputStream input = new FileInputStream(result); - List sequences = readJRonn(input); + Map sequences = readJRonn(input); input.close(); return sequences; } @@ -321,9 +324,9 @@ public final class SequenceUtil { * is thrown if the inStream represents an unknown source of * data, i.e. not a JRonn output */ - public static List readJRonn(final InputStream inStream) + public static Map readJRonn(final InputStream inStream) throws IOException, UnknownFileFormatException { - final List seqs = new ArrayList(); + final Map seqs = new HashMap(); final BufferedReader infasta = new BufferedReader( new InputStreamReader(inStream, "UTF8"), 16000); @@ -351,14 +354,13 @@ public final class SequenceUtil { "File does not look like Jronn horizontally formatted output file!\n" + JRONN_WRONG_FORMAT_MESSAGE); } - seqs.add(new AnnotatedSequence(sname, sequence, annotation)); + seqs.put(sname, new Score(DisorderMethod.JRonn, annotation)); } } while (line != null); infasta.close(); return seqs; } - private static float[] convertToNumber(String[] annotValues) throws UnknownFileFormatException { float[] annotation = new float[annotValues.length]; @@ -404,18 +406,24 @@ public final class SequenceUtil { * * TODO complete! * - * # RESIDUE COILS REM465 HOTLOOPS M 0.86010 0.88512 0.37094 T 0.79983 - * 0.85864 0.44331 .... # RESIDUE COILS REM465 HOTLOOPS M 0.86010 0.88512 - * 0.37094 + * RESIDUE COILS REM465 HOTLOOPS + * + * M 0.86010 0.88512 0.37094 + * + * T 0.79983 0.85864 0.44331 .... + * + * RESIDUE COILS REM465 HOTLOOPS + * + * M 0.86010 0.88512 0.37094 + * * * @param input * @return * @throws IOException * @throws UnknownFileFormatException */ - static List> readDisembl( - final InputStream input) throws IOException, - UnknownFileFormatException { + static Map> readDisembl(final InputStream input) + throws IOException, UnknownFileFormatException { Scanner scan = new Scanner(input); scan.useDelimiter("# RESIDUE COILS REM465 HOTLOOPS\n"); if (!scan.hasNext()) { @@ -425,7 +433,7 @@ public final class SequenceUtil { + " No such line was found!"); } - List> results = new ArrayList>(); + Map> results = new HashMap>(); int seqCounter = 0; while (scan.hasNext()) { seqCounter++; @@ -435,10 +443,8 @@ public final class SequenceUtil { ArrayList coils = new ArrayList(); ArrayList rem = new ArrayList(); ArrayList hotloops = new ArrayList(); - - MultiAnnotatedSequence disemblRes = new MultiAnnotatedSequence( - DisemblResultAnnot.class); - + FastaSequence fs = new FastaSequence(Integer.toString(seqCounter), + singleSeq); while (scansingle.hasNextLine()) { String valueLine = scansingle.nextLine(); Scanner values = new Scanner(valueLine); @@ -448,19 +454,18 @@ public final class SequenceUtil { hotloops.add(values.nextFloat()); values.close(); } - disemblRes.addAnnotation(DisemblResultAnnot.COILS, coils); - disemblRes.addAnnotation(DisemblResultAnnot.REM465, rem); - disemblRes.addAnnotation(DisemblResultAnnot.HOTLOOPS, hotloops); - // TODO - // disemblRes.sequence = seqbuffer.toString(); + Set scores = new HashSet(); + scores.add(new Score(DisemblResultAnnot.COILS, coils)); + scores.add(new Score(DisemblResultAnnot.HOTLOOPS, hotloops)); + scores.add(new Score(DisemblResultAnnot.REM465, rem)); + results.put(fs, scores); + scansingle.close(); - results.add(disemblRes); } input.close(); return results; } - /** * Read AACon result with no alignment files. This method leaves incoming * the InputStream results open! diff --git a/runner/compbio/runner/Util.java b/runner/compbio/runner/Util.java index 9475a0b..2f040aa 100644 --- a/runner/compbio/runner/Util.java +++ b/runner/compbio/runner/Util.java @@ -23,13 +23,14 @@ 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.AnnotatedSequence; 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; @@ -43,125 +44,127 @@ 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) { - 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; + 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) { + 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; } - 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 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; } - 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 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 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 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 ClustalAlignmentUtil.readClustalFile(cfile); - } - - public static final List 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!"); + + 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 SequenceUtil.readJRonn(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) { + + 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(); + } } - } } diff --git a/runner/compbio/runner/disorder/Disembl.java b/runner/compbio/runner/disorder/Disembl.java index c6b278f..716859f 100644 --- a/runner/compbio/runner/disorder/Disembl.java +++ b/runner/compbio/runner/disorder/Disembl.java @@ -14,14 +14,12 @@ package compbio.runner.disorder; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.Arrays; +import java.util.Map; import org.apache.log4j.Logger; -import compbio.data.sequence.Alignment; -import compbio.data.sequence.UnknownFileFormatException; +import compbio.data.sequence.Score; import compbio.engine.client.Executable; import compbio.engine.client.PipedExecutable; import compbio.engine.client.SkeletalExecutable; @@ -46,8 +44,9 @@ import compbio.runner.Util; * print 'Mode: "default"(nothing) or "scores" which will give scores per * residue in TAB separated format' */ -public class Disembl extends SkeletalExecutable implements - PipedExecutable { +public class Disembl extends SkeletalExecutable + implements + PipedExecutable { private static Logger log = Logger.getLogger(Disembl.class); @@ -65,23 +64,10 @@ public class Disembl extends SkeletalExecutable implements } @SuppressWarnings("unchecked") - public Alignment getResults(String workDirectory) + public Map 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 null; } @Override diff --git a/runner/compbio/runner/disorder/Jronn.java b/runner/compbio/runner/disorder/Jronn.java index 57cf9f6..a436456 100644 --- a/runner/compbio/runner/disorder/Jronn.java +++ b/runner/compbio/runner/disorder/Jronn.java @@ -25,10 +25,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; -import compbio.data.sequence.AnnotatedSequence; +import compbio.data.sequence.Score; import compbio.data.sequence.SequenceUtil; import compbio.data.sequence.UnknownFileFormatException; import compbio.engine.client.CommandBuilder; @@ -49,156 +50,157 @@ import compbio.runner.Util; */ public class Jronn extends SkeletalExecutable { - private static Logger log = Logger.getLogger(Jronn.class); - - /** - * Number of cores to use, defaults to 1 for local execution or the value of - * "jronn.cluster.cpunum" property for cluster execution - */ - private int ncoreNumber = 0; - - private final String ncorePrm = "-n="; - - // Cache for Limits information - private static LimitsManager limits; - - public static final String KEY_VALUE_SEPARATOR = Util.SPACE; - public static final String STAT_FILE = "stat.txt"; - - public Jronn() { - addParameters(Arrays.asList("-jar", getLibPath(), "-s=" + STAT_FILE, - "-f=H")); - } - - @SuppressWarnings("unchecked") - @Override - public List getResults(String workDirectory) - throws ResultNotAvailableException { - List sequences = null; - try { - InputStream inStream = new FileInputStream(new File(workDirectory, - getOutput())); - sequences = SequenceUtil.readJRonn(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 (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 static Logger log = Logger.getLogger(Jronn.class); + + /** + * Number of cores to use, defaults to 1 for local execution or the value of + * "jronn.cluster.cpunum" property for cluster execution + */ + private int ncoreNumber = 0; + + private final String ncorePrm = "-n="; + + // Cache for Limits information + private static LimitsManager limits; + + public static final String KEY_VALUE_SEPARATOR = Util.SPACE; + public static final String STAT_FILE = "stat.txt"; + + public Jronn() { + addParameters(Arrays.asList("-jar", getLibPath(), "-s=" + STAT_FILE, + "-f=H")); + } + + @SuppressWarnings("unchecked") + @Override + public Map getResults(String workDirectory) + throws ResultNotAvailableException { + Map sequences = null; + try { + InputStream inStream = new FileInputStream(new File(workDirectory, + getOutput())); + sequences = SequenceUtil.readJRonn(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 (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 sequences; + } + + private static String getLibPath() { + + String settings = ph.getProperty("jronn.jar.file"); + if (compbio.util.Util.isEmpty(settings)) { + throw new NullPointerException( + "Please define jronn.jar.file property in Executable.properties file" + + "and initialize it with the location of jronn jar file"); + } + if (new File(settings).isAbsolute()) { + // Jronn jar can be found so no actions necessary + // no further actions is necessary + return settings; + } + return compbio.engine.client.Util.convertToAbsolute(settings); + } + + @Override + public List getCreatedFiles() { + return Arrays.asList(getOutput(), getError()); } - return sequences; - } - private static String getLibPath() { + @Override + public Jronn setInput(String inFile) { + super.setInput(inFile); + cbuilder.setParam("-i=" + inFile); + return this; + } - String settings = ph.getProperty("jronn.jar.file"); - if (compbio.util.Util.isEmpty(settings)) { - throw new NullPointerException( - "Please define jronn.jar.file property in Executable.properties file" - + "and initialize it with the location of jronn jar file"); + @Override + public Jronn setOutput(String outFile) { + super.setOutput(outFile); + cbuilder.setParam("-o=" + outFile); + return this; } - if (new File(settings).isAbsolute()) { - // Jronn jar can be found so no actions necessary - // no further actions is necessary - return settings; + + @Override + public Limit getLimit(String presetName) { + if (limits == null) { + limits = getLimits(); + } + 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(); + } + return limit; + } + + @Override + public LimitsManager getLimits() { + // synchronise on static field + synchronized (log) { + if (limits == null) { + limits = Util.getLimits(this.getClass()); + } + } + return limits; } - return compbio.engine.client.Util.convertToAbsolute(settings); - } - - @Override - public List getCreatedFiles() { - return Arrays.asList(getOutput(), getError()); - } - - @Override - public Jronn setInput(String inFile) { - super.setInput(inFile); - cbuilder.setParam("-i=" + inFile); - return this; - } - - @Override - public Jronn setOutput(String outFile) { - super.setOutput(outFile); - cbuilder.setParam("-o=" + outFile); - return this; - } - - @Override - public Limit getLimit(String presetName) { - if (limits == null) { - limits = getLimits(); + + @Override + public Class> getType() { + return this.getClass(); } - Limit limit = null; - if (limits != null) { - // this returns default limit if preset is undefined! - limit = limits.getLimitByName(presetName); + + public static String getStatFile() { + return STAT_FILE; } - // 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(); + + 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())); } - return limit; - } - - @Override - public LimitsManager getLimits() { - // synchronise on static field - synchronized (log) { - if (limits == null) { - limits = Util.getLimits(this.getClass()); - } + + int getNCore() { + return ncoreNumber; } - return limits; - } - - @Override - public Class> getType() { - return this.getClass(); - } - - public static String getStatFile() { - return STAT_FILE; - } - - public void setNCore(int ncoreNumber) { - if (ncoreNumber < 1 || ncoreNumber > 100) { - throw new IndexOutOfBoundsException( - "Number of cores must be within 1 and 100 "); + + @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); } - this.ncoreNumber = ncoreNumber; - cbuilder.setParam(ncorePrm + Integer.toString(getNCore())); - } - - 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); - } } diff --git a/testsrc/compbio/data/sequence/SequenceUtilTester.java b/testsrc/compbio/data/sequence/SequenceUtilTester.java index f526578..1460b52 100644 --- a/testsrc/compbio/data/sequence/SequenceUtilTester.java +++ b/testsrc/compbio/data/sequence/SequenceUtilTester.java @@ -26,6 +26,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import org.testng.annotations.Test; @@ -118,15 +120,14 @@ public class SequenceUtilTester { FileInputStream fio; try { fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "jronn.out"); - List aseqs = SequenceUtil.readJRonn(fio); + Map aseqs = SequenceUtil.readJRonn(fio); assertNotNull(aseqs); assertEquals(aseqs.size(), 3); - AnnotatedSequence aseq = aseqs.get(0); + Score aseq = aseqs.get(0); assertNotNull(aseq); - assertNotNull(aseq.getAnnotation()); + assertNotNull(aseq.getScores()); // System.out.println(aseq); - assertEquals(aseq.getAnnotation().length, aseq.getSequence() - .length()); + assertEquals(aseq.getScores().size(), aseq.getScores().size()); fio.close(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -156,7 +157,7 @@ public class SequenceUtilTester { try { fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "disembl.out"); - List> aseqs = SequenceUtil + Map> aseqs = SequenceUtil .readDisembl(fio); assertNotNull(aseqs); diff --git a/testsrc/compbio/runner/conservation/AAConTester.java b/testsrc/compbio/runner/conservation/AAConTester.java index fd3749b..859c4ae 100644 --- a/testsrc/compbio/runner/conservation/AAConTester.java +++ b/testsrc/compbio/runner/conservation/AAConTester.java @@ -29,6 +29,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; import java.util.Arrays; +import java.util.HashSet; import javax.xml.bind.ValidationException; @@ -37,8 +38,7 @@ import org.ggf.drmaa.JobInfo; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import compbio.data.sequence.ConservationMethod; -import compbio.data.sequence.MultiAnnotatedSequence; +import compbio.data.sequence.Score; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.FilePuller; @@ -188,9 +188,9 @@ public class AAConTester { lr.executeJob(); ConfiguredExecutable al1 = lr.waitForResult(); assertNotNull(al1.getResults()); - MultiAnnotatedSequence annotations = confAAcon.getResults(); + HashSet annotations = confAAcon.getResults(); assertNotNull(annotations); - assertEquals(annotations.getAnnotations().size(), 1); + assertEquals(annotations.size(), 1); assertEquals(al1.getResults(), annotations); } catch (JobSubmissionException e) { e.printStackTrace(); @@ -219,9 +219,9 @@ public class AAConTester { lr.executeJob(); ConfiguredExecutable al1 = lr.waitForResult(); assertNotNull(al1.getResults()); - MultiAnnotatedSequence annotations = confAAcon.getResults(); + HashSet annotations = confAAcon.getResults(); assertNotNull(annotations); - assertEquals(annotations.getAnnotations().size(), 13); + assertEquals(annotations.size(), 13); assertEquals(al1.getResults(), annotations); } catch (JobSubmissionException e) { e.printStackTrace(); @@ -252,9 +252,9 @@ public class AAConTester { lr.executeJob(); ConfiguredExecutable al1 = lr.waitForResult(); assertNotNull(al1.getResults()); - MultiAnnotatedSequence annotations = confAAcon.getResults(); + HashSet annotations = confAAcon.getResults(); assertNotNull(annotations); - assertEquals(annotations.getAnnotations().size(), 3); + assertEquals(annotations.size(), 3); assertEquals(al1.getResults(), annotations); } catch (JobSubmissionException e) { diff --git a/testsrc/compbio/runner/disorder/DisemblTester.java b/testsrc/compbio/runner/disorder/DisemblTester.java index 85d5e91..d77648e 100644 --- a/testsrc/compbio/runner/disorder/DisemblTester.java +++ b/testsrc/compbio/runner/disorder/DisemblTester.java @@ -30,7 +30,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; -import java.util.List; +import java.util.HashSet; import javax.xml.bind.ValidationException; @@ -39,7 +39,7 @@ import org.ggf.drmaa.JobInfo; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import compbio.data.sequence.AnnotatedSequence; +import compbio.data.sequence.Score; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.FilePuller; @@ -66,287 +66,289 @@ import compbio.util.SysPrefs; public class DisemblTester { - public static String test_outfile = "TO1381.disembl.out"; + public static String test_outfile = "TO1381.disembl.out"; - private Disembl disembl; + private Disembl disembl; - @BeforeMethod(alwaysRun = true) - void init() { - disembl = new Disembl(); - disembl.setInput(AllTestSuit.test_input).setOutput(test_outfile); - } + @BeforeMethod(alwaysRun = true) + void init() { + disembl = new Disembl(); + disembl.setInput(AllTestSuit.test_input).setOutput(test_outfile); + } - @Test(groups = { AllTestSuit.test_group_cluster, - AllTestSuit.test_group_runner }) - public void testRunOnCluster() { - assertFalse(SysPrefs.isWindows, - "Cluster execution can only be in unix environment"); - try { - ConfiguredExecutable confDisembl = Configurator - .configureExecutable(disembl, - Executable.ExecProvider.Cluster); - JobRunner runner = JobRunner.getInstance(confDisembl); + @Test(groups = {AllTestSuit.test_group_cluster, + AllTestSuit.test_group_runner}) + public void testRunOnCluster() { + assertFalse(SysPrefs.isWindows, + "Cluster execution can only be in unix environment"); + try { + ConfiguredExecutable confDisembl = Configurator + .configureExecutable(disembl, + Executable.ExecProvider.Cluster); + JobRunner runner = JobRunner.getInstance(confDisembl); - assertNotNull(runner, "Runner is NULL"); - runner.executeJob(); - // assertNotNull("JobId is null", jobId1); - JobStatus status = runner.getJobStatus(); - assertTrue(status == JobStatus.PENDING - || status == JobStatus.RUNNING, - "Status of the process is wrong!"); - JobInfo info = runner.getJobInfo(); - assertNotNull(info, "JobInfo is null"); - StatisticManager sm = new StatisticManager(info); - assertNotNull(sm, "Statictic manager is null"); - try { + assertNotNull(runner, "Runner is NULL"); + runner.executeJob(); + // assertNotNull("JobId is null", jobId1); + JobStatus status = runner.getJobStatus(); + assertTrue(status == JobStatus.PENDING + || status == JobStatus.RUNNING, + "Status of the process is wrong!"); + JobInfo info = runner.getJobInfo(); + assertNotNull(info, "JobInfo is null"); + StatisticManager sm = new StatisticManager(info); + assertNotNull(sm, "Statictic manager is null"); + try { - String exits = sm.getExitStatus(); - assertNotNull("Exit status is null", exits); - // cut 4 trailing zeros from the number - int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits) - .intValue(); - assertEquals(0, exitsInt); - System.out.println(sm.getAllStats()); + String exits = sm.getExitStatus(); + assertNotNull("Exit status is null", exits); + // cut 4 trailing zeros from the number + int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits) + .intValue(); + assertEquals(0, exitsInt); + System.out.println(sm.getAllStats()); - } catch (ParseException e) { - e.printStackTrace(); - fail("Parse Exception: " + e.getMessage()); - } - //assertFalse(runner.cleanup()); - assertTrue(sm.hasExited()); - assertFalse(sm.wasAborted()); - assertFalse(sm.hasDump()); - assertFalse(sm.hasSignaled()); + } catch (ParseException e) { + e.printStackTrace(); + fail("Parse Exception: " + e.getMessage()); + } + // assertFalse(runner.cleanup()); + assertTrue(sm.hasExited()); + assertFalse(sm.wasAborted()); + assertFalse(sm.hasDump()); + assertFalse(sm.hasSignaled()); - } catch (JobSubmissionException e) { - e.printStackTrace(); - fail("DrmaaException caught:" + e.getMessage()); - } catch (JobExecutionException e) { - e.printStackTrace(); - fail("DrmaaException caught:" + e.getMessage()); - } catch (DrmaaException e) { - e.printStackTrace(); - fail("DrmaaException caught:" + e.getMessage()); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail("DrmaaException caught:" + e.getMessage()); + } catch (JobExecutionException e) { + e.printStackTrace(); + fail("DrmaaException caught:" + e.getMessage()); + } catch (DrmaaException e) { + e.printStackTrace(); + fail("DrmaaException caught:" + e.getMessage()); + } } - } - /** - * This tests fails from time to time depending on the cluster load or some - * other factors. Any client code has to adjust for this issue - */ - @Test(groups = { AllTestSuit.test_group_cluster, - AllTestSuit.test_group_runner }) - public void testRunOnClusterAsync() { - assertFalse(SysPrefs.isWindows, - "Cluster execution can only be in unix environment"); - try { - ConfiguredExecutable confDisembl = Configurator - .configureExecutable(disembl, - Executable.ExecProvider.Cluster); - AsyncExecutor aengine = Configurator.getAsyncEngine(confDisembl); - String jobId = aengine.submitJob(confDisembl); - assertNotNull(jobId, "Runner is NULL"); - // let drmaa to start - Thread.sleep(500); - JobStatus status = aengine.getJobStatus(jobId); - while (status != JobStatus.FINISHED) { - System.out.println("Job Status: " + status); - Thread.sleep(1000); - status = aengine.getJobStatus(jobId); - ConfiguredExecutable result = (ConfiguredExecutable) aengine - .getResults(jobId); - assertNotNull(result); - System.out.println("RES:" + result); - // Some times the job could be removed from the cluster accounting - // before it has been reported to finish. Make sure - // to stop waiting in such case - if (status == JobStatus.UNDEFINED) { - break; + /** + * This tests fails from time to time depending on the cluster load or some + * other factors. Any client code has to adjust for this issue + */ + @Test(groups = {AllTestSuit.test_group_cluster, + AllTestSuit.test_group_runner}) + public void testRunOnClusterAsync() { + assertFalse(SysPrefs.isWindows, + "Cluster execution can only be in unix environment"); + try { + ConfiguredExecutable confDisembl = Configurator + .configureExecutable(disembl, + Executable.ExecProvider.Cluster); + AsyncExecutor aengine = Configurator.getAsyncEngine(confDisembl); + String jobId = aengine.submitJob(confDisembl); + assertNotNull(jobId, "Runner is NULL"); + // let drmaa to start + Thread.sleep(500); + JobStatus status = aengine.getJobStatus(jobId); + while (status != JobStatus.FINISHED) { + System.out.println("Job Status: " + status); + Thread.sleep(1000); + status = aengine.getJobStatus(jobId); + ConfiguredExecutable result = (ConfiguredExecutable) aengine + .getResults(jobId); + assertNotNull(result); + System.out.println("RES:" + result); + // Some times the job could be removed from the cluster + // accounting + // before it has been reported to finish. Make sure + // to stop waiting in such case + if (status == JobStatus.UNDEFINED) { + break; + } + } + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail("DrmaaException caught:" + e.getMessage()); + } catch (InterruptedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getMessage()); } - } - } catch (JobSubmissionException e) { - e.printStackTrace(); - fail("DrmaaException caught:" + e.getMessage()); - } catch (InterruptedException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (ResultNotAvailableException e) { - e.printStackTrace(); - fail(e.getMessage()); } - } - @Test(groups = { AllTestSuit.test_group_runner }) - public void testRunLocally() { - try { - ConfiguredExecutable confDisembl = Configurator - .configureExecutable(disembl, Executable.ExecProvider.Local); + @Test(groups = {AllTestSuit.test_group_runner}) + public void testRunLocally() { + try { + ConfiguredExecutable confDisembl = Configurator + .configureExecutable(disembl, Executable.ExecProvider.Local); - // For local execution use relative - LocalRunner lr = new LocalRunner(confDisembl); - lr.executeJob(); - ConfiguredExecutable al1 = lr.waitForResult(); - assertNotNull(al1.getResults()); - List al2 = confDisembl.getResults(); - assertNotNull(al2); - assertEquals(al2.size(), 3); - assertEquals(al1.getResults(), al2); - } catch (JobSubmissionException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (ResultNotAvailableException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (JobExecutionException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + // For local execution use relative + LocalRunner lr = new LocalRunner(confDisembl); + lr.executeJob(); + ConfiguredExecutable al1 = lr.waitForResult(); + assertNotNull(al1.getResults()); + HashSet al2 = confDisembl.getResults(); + assertNotNull(al2); + assertEquals(al2.size(), 3); + assertEquals(al1.getResults(), al2); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JobExecutionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } } - } - @Test(groups = { AllTestSuit.test_group_runner }) - public void readStatistics() { - try { - ConfiguredExecutable confDisembl = Configurator - .configureExecutable(disembl, Executable.ExecProvider.Local); - // For local execution use relavive + @Test(groups = {AllTestSuit.test_group_runner}) + public void readStatistics() { + try { + ConfiguredExecutable confDisembl = Configurator + .configureExecutable(disembl, Executable.ExecProvider.Local); + // For local execution use relavive - AsyncExecutor sexec = Configurator.getAsyncEngine(confDisembl); - String jobId = sexec.submitJob(confDisembl); - FilePuller fw = FilePuller.newFilePuller(confDisembl - .getWorkDirectory() - + File.separator + Jronn.getStatFile(), - FileWatcher.MIN_CHUNK_SIZE_BYTES); - int count = 0; - long position = 0; - fw.waitForFile(4); - JobStatus status = sexec.getJobStatus(jobId); - while (status != JobStatus.FINISHED) { - if (fw.hasMoreData()) { - ChunkHolder ch = fw.pull(position); - String chunk = ch.getChunk(); - position = ch.getNextPosition(); + AsyncExecutor sexec = Configurator.getAsyncEngine(confDisembl); + String jobId = sexec.submitJob(confDisembl); + FilePuller fw = FilePuller.newFilePuller( + confDisembl.getWorkDirectory() + File.separator + + Jronn.getStatFile(), + FileWatcher.MIN_CHUNK_SIZE_BYTES); + int count = 0; + long position = 0; + fw.waitForFile(4); + JobStatus status = sexec.getJobStatus(jobId); + while (status != JobStatus.FINISHED) { + if (fw.hasMoreData()) { + ChunkHolder ch = fw.pull(position); + String chunk = ch.getChunk(); + position = ch.getNextPosition(); + } + count++; + // Make sure the loop is terminated if the job fails + if ((status == JobStatus.UNDEFINED || status == JobStatus.FAILED)) { + break; + } + Thread.sleep(300); + status = sexec.getJobStatus(jobId); + } + assertTrue(count > 1); + ConfiguredExecutable al = sexec.getResults(jobId); + assertNotNull(al.getResults()); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (InterruptedException e) { + e.printStackTrace(); + fail(e.getMessage()); } - count++; - // Make sure the loop is terminated if the job fails - if ((status == JobStatus.UNDEFINED || status == JobStatus.FAILED)) { - break; - } - Thread.sleep(300); - status = sexec.getJobStatus(jobId); - } - assertTrue(count > 1); - ConfiguredExecutable al = sexec.getResults(jobId); - assertNotNull(al.getResults()); - } catch (JobSubmissionException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (ResultNotAvailableException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (InterruptedException e) { - e.printStackTrace(); - fail(e.getMessage()); } - } - @Test(groups = { AllTestSuit.test_group_runner }) - public void testPersistance() { - try { - Disembl disembl = new Disembl(); - disembl.setError("errrr.txt").setInput(AllTestSuit.test_input) - .setOutput("outtt.txt"); - assertEquals(disembl.getInput(), AllTestSuit.test_input); - assertEquals(disembl.getError(), "errrr.txt"); - assertEquals(disembl.getOutput(), "outtt.txt"); - ConfiguredExecutable cDisembl = Configurator - .configureExecutable(disembl, Executable.ExecProvider.Local); + @Test(groups = {AllTestSuit.test_group_runner}) + public void testPersistance() { + try { + Disembl disembl = new Disembl(); + disembl.setError("errrr.txt").setInput(AllTestSuit.test_input) + .setOutput("outtt.txt"); + assertEquals(disembl.getInput(), AllTestSuit.test_input); + assertEquals(disembl.getError(), "errrr.txt"); + assertEquals(disembl.getOutput(), "outtt.txt"); + ConfiguredExecutable cDisembl = Configurator + .configureExecutable(disembl, Executable.ExecProvider.Local); - SyncExecutor sexec = Configurator.getSyncEngine(cDisembl); - sexec.executeJob(); - ConfiguredExecutable al = sexec.waitForResult(); - assertNotNull(al.getResults()); - // Save run configuration - assertTrue(cDisembl.saveRunConfiguration()); + SyncExecutor sexec = Configurator.getSyncEngine(cDisembl); + sexec.executeJob(); + ConfiguredExecutable al = sexec.waitForResult(); + assertNotNull(al.getResults()); + // Save run configuration + assertTrue(cDisembl.saveRunConfiguration()); - // See if loaded configuration is the same as saved - RunConfiguration loadedRun = RunConfiguration - .load(new FileInputStream(new File(cDisembl - .getWorkDirectory(), RunConfiguration.rconfigFile))); - assertEquals(((ConfExecutable) cDisembl) - .getRunConfiguration(), loadedRun); - // Load run configuration as ConfExecutable - ConfiguredExecutable resurrectedCDisembl = (ConfiguredExecutable) cDisembl - .loadRunConfiguration(new FileInputStream(new File(cDisembl - .getWorkDirectory(), RunConfiguration.rconfigFile))); - assertNotNull(resurrectedCDisembl); - assertEquals(resurrectedCDisembl.getExecutable().getInput(), - AllTestSuit.test_input); - assertEquals(resurrectedCDisembl.getExecutable().getError(), - "errrr.txt"); - assertEquals(resurrectedCDisembl.getExecutable().getOutput(), - "outtt.txt"); - // See in details whether executables are the same - assertEquals(resurrectedCDisembl.getExecutable(), disembl); + // See if loaded configuration is the same as saved + RunConfiguration loadedRun = RunConfiguration + .load(new FileInputStream(new File(cDisembl + .getWorkDirectory(), RunConfiguration.rconfigFile))); + assertEquals( + ((ConfExecutable) cDisembl).getRunConfiguration(), + loadedRun); + // Load run configuration as ConfExecutable + ConfiguredExecutable resurrectedCDisembl = (ConfiguredExecutable) cDisembl + .loadRunConfiguration(new FileInputStream(new File(cDisembl + .getWorkDirectory(), RunConfiguration.rconfigFile))); + assertNotNull(resurrectedCDisembl); + assertEquals(resurrectedCDisembl.getExecutable().getInput(), + AllTestSuit.test_input); + assertEquals(resurrectedCDisembl.getExecutable().getError(), + "errrr.txt"); + assertEquals(resurrectedCDisembl.getExecutable().getOutput(), + "outtt.txt"); + // See in details whether executables are the same + assertEquals(resurrectedCDisembl.getExecutable(), disembl); - ConfiguredExecutable resJronn = Configurator - .configureExecutable(resurrectedCDisembl.getExecutable(), - Executable.ExecProvider.Local); + ConfiguredExecutable resJronn = Configurator + .configureExecutable(resurrectedCDisembl.getExecutable(), + Executable.ExecProvider.Local); - sexec = Configurator.getSyncEngine(resJronn, - Executable.ExecProvider.Local); - sexec.executeJob(); - al = sexec.waitForResult(); - assertNotNull(al); + sexec = Configurator.getSyncEngine(resJronn, + Executable.ExecProvider.Local); + sexec.executeJob(); + al = sexec.waitForResult(); + assertNotNull(al); - } catch (JobSubmissionException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (JobExecutionException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (ResultNotAvailableException e) { - e.printStackTrace(); - fail(e.getMessage()); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (JobExecutionException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getMessage()); + } } - } - @Test(groups = { AllTestSuit.test_group_runner }) - public void testConfigurationLoading() { - try { - RunnerConfig disemblConfig = ConfExecutable - .getRunnerOptions(Disembl.class); - assertNotNull(disemblConfig); - assertTrue(disemblConfig.getArguments().size() > 0); + @Test(groups = {AllTestSuit.test_group_runner}) + public void testConfigurationLoading() { + try { + RunnerConfig disemblConfig = ConfExecutable + .getRunnerOptions(Disembl.class); + assertNotNull(disemblConfig); + assertTrue(disemblConfig.getArguments().size() > 0); - PresetManager disemblPresets = ConfExecutable - .getRunnerPresets(Disembl.class); - assertNull(disemblPresets); // there is no presets + PresetManager disemblPresets = ConfExecutable + .getRunnerPresets(Disembl.class); + assertNull(disemblPresets); // there is no presets - LimitsManager disemblLimits = ConfExecutable - .getRunnerLimits(Disembl.class); - assertNotNull(disemblLimits); - assertTrue(disemblLimits.getLimits().size() > 0); - disemblLimits.validate(disemblPresets); + LimitsManager disemblLimits = ConfExecutable + .getRunnerLimits(Disembl.class); + assertNotNull(disemblLimits); + assertTrue(disemblLimits.getLimits().size() > 0); + disemblLimits.validate(disemblPresets); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (ValidationException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (ValidationException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } } - } } diff --git a/testsrc/compbio/runner/disorder/JronnTester.java b/testsrc/compbio/runner/disorder/JronnTester.java index 9385eb6..d784387 100644 --- a/testsrc/compbio/runner/disorder/JronnTester.java +++ b/testsrc/compbio/runner/disorder/JronnTester.java @@ -30,7 +30,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; -import java.util.List; +import java.util.Map; import javax.xml.bind.ValidationException; @@ -39,7 +39,7 @@ import org.ggf.drmaa.JobInfo; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import compbio.data.sequence.AnnotatedSequence; +import compbio.data.sequence.Score; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.FilePuller; @@ -76,14 +76,14 @@ public class JronnTester { jronn.setInput(AllTestSuit.test_input).setOutput(test_outfile); } - @Test(groups = { AllTestSuit.test_group_cluster, - AllTestSuit.test_group_runner }) - public void testRunOnCluster() { + @Test(groups = {AllTestSuit.test_group_cluster, + AllTestSuit.test_group_runner}) + public void testRunOnCluster() { assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment"); try { ConfiguredExecutable confJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Cluster); + .configureExecutable(jronn, Executable.ExecProvider.Cluster); JobRunner runner = JobRunner.getInstance(confJronn); assertNotNull(runner, "Runner is NULL"); @@ -103,7 +103,7 @@ public class JronnTester { assertNotNull("Exit status is null", exits); // cut 4 trailing zeros from the number int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits) - .intValue(); + .intValue(); assertEquals(0, exitsInt); System.out.println(sm.getAllStats()); @@ -111,7 +111,7 @@ public class JronnTester { e.printStackTrace(); fail("Parse Exception: " + e.getMessage()); } - //assertFalse(runner.cleanup()); + // assertFalse(runner.cleanup()); assertTrue(sm.hasExited()); assertFalse(sm.wasAborted()); assertFalse(sm.hasDump()); @@ -133,14 +133,14 @@ public class JronnTester { * This tests fails from time to time depending on the cluster load or some * other factors. Any client code has to adjust for this issue */ - @Test(groups = { AllTestSuit.test_group_cluster, - AllTestSuit.test_group_runner }) - public void testRunOnClusterAsync() { + @Test(groups = {AllTestSuit.test_group_cluster, + AllTestSuit.test_group_runner}) + public void testRunOnClusterAsync() { assertFalse(SysPrefs.isWindows, - "Cluster execution can only be in unix environment"); + "Cluster execution can only be in unix environment"); try { ConfiguredExecutable confJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Cluster); + .configureExecutable(jronn, Executable.ExecProvider.Cluster); AsyncExecutor aengine = Configurator.getAsyncEngine(confJronn); String jobId = aengine.submitJob(confJronn); assertNotNull(jobId, "Runner is NULL"); @@ -152,11 +152,12 @@ public class JronnTester { Thread.sleep(1000); status = aengine.getJobStatus(jobId); ConfiguredExecutable result = (ConfiguredExecutable) aengine - .getResults(jobId); + .getResults(jobId); assertNotNull(result); System.out.println("RES:" + result); - // Some times the job could be removed from the cluster accounting - // before it has been reported to finish. Make sure + // Some times the job could be removed from the cluster + // accounting + // before it has been reported to finish. Make sure // to stop waiting in such case if (status == JobStatus.UNDEFINED) { break; @@ -174,18 +175,18 @@ public class JronnTester { } } - @Test(groups = { AllTestSuit.test_group_runner }) + @Test(groups = {AllTestSuit.test_group_runner}) public void testRunLocally() { try { ConfiguredExecutable confJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Local); + .configureExecutable(jronn, Executable.ExecProvider.Local); // For local execution use relative LocalRunner lr = new LocalRunner(confJronn); lr.executeJob(); ConfiguredExecutable al1 = lr.waitForResult(); assertNotNull(al1.getResults()); - List al2 = confJronn.getResults(); + Map al2 = confJronn.getResults(); assertNotNull(al2); assertEquals(al2.size(), 3); assertEquals(al1.getResults(), al2); @@ -201,19 +202,19 @@ public class JronnTester { } } - @Test(groups = { AllTestSuit.test_group_runner }) + @Test(groups = {AllTestSuit.test_group_runner}) public void testRunLocallyOnTwoCpu() { try { jronn.setNCore(2); ConfiguredExecutable confJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Local); - + .configureExecutable(jronn, Executable.ExecProvider.Local); + // For local execution use relative LocalRunner lr = new LocalRunner(confJronn); lr.executeJob(); ConfiguredExecutable al1 = lr.waitForResult(); assertNotNull(al1.getResults()); - List al2 = confJronn.getResults(); + Map al2 = confJronn.getResults(); assertNotNull(al2); assertEquals(al2.size(), 3); assertEquals(al1.getResults(), al2); @@ -229,19 +230,18 @@ public class JronnTester { } } - - @Test(groups = { AllTestSuit.test_group_runner }) + @Test(groups = {AllTestSuit.test_group_runner}) public void readStatistics() { try { ConfiguredExecutable confJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Local); + .configureExecutable(jronn, Executable.ExecProvider.Local); // For local execution use relavive AsyncExecutor sexec = Configurator.getAsyncEngine(confJronn); String jobId = sexec.submitJob(confJronn); - FilePuller fw = FilePuller.newFilePuller(confJronn - .getWorkDirectory() - + File.separator + Jronn.getStatFile(), + FilePuller fw = FilePuller.newFilePuller( + confJronn.getWorkDirectory() + File.separator + + Jronn.getStatFile(), FileWatcher.MIN_CHUNK_SIZE_BYTES); int count = 0; long position = 0; @@ -279,17 +279,17 @@ public class JronnTester { } } - @Test(groups = { AllTestSuit.test_group_runner }) + @Test(groups = {AllTestSuit.test_group_runner}) public void testPersistance() { try { Jronn jronn = new Jronn(); jronn.setError("errrr.txt").setInput(AllTestSuit.test_input) - .setOutput("outtt.txt"); + .setOutput("outtt.txt"); assertEquals(jronn.getInput(), AllTestSuit.test_input); assertEquals(jronn.getError(), "errrr.txt"); assertEquals(jronn.getOutput(), "outtt.txt"); ConfiguredExecutable cJronn = Configurator - .configureExecutable(jronn, Executable.ExecProvider.Local); + .configureExecutable(jronn, Executable.ExecProvider.Local); SyncExecutor sexec = Configurator.getSyncEngine(cJronn); sexec.executeJob(); @@ -300,28 +300,28 @@ public class JronnTester { // See if loaded configuration is the same as saved RunConfiguration loadedRun = RunConfiguration - .load(new FileInputStream(new File(cJronn - .getWorkDirectory(), RunConfiguration.rconfigFile))); + .load(new FileInputStream(new File(cJronn + .getWorkDirectory(), RunConfiguration.rconfigFile))); assertEquals( ((ConfExecutable) cJronn).getRunConfiguration(), loadedRun); // Load run configuration as ConfExecutable ConfiguredExecutable resurrectedCMuscle = (ConfiguredExecutable) cJronn - .loadRunConfiguration(new FileInputStream(new File(cJronn - .getWorkDirectory(), RunConfiguration.rconfigFile))); + .loadRunConfiguration(new FileInputStream(new File(cJronn + .getWorkDirectory(), RunConfiguration.rconfigFile))); assertNotNull(resurrectedCMuscle); assertEquals(resurrectedCMuscle.getExecutable().getInput(), AllTestSuit.test_input); assertEquals(resurrectedCMuscle.getExecutable().getError(), "errrr.txt"); assertEquals(resurrectedCMuscle.getExecutable().getOutput(), - "outtt.txt"); + "outtt.txt"); // See in details whether executables are the same assertEquals(resurrectedCMuscle.getExecutable(), jronn); ConfiguredExecutable resJronn = Configurator - .configureExecutable(resurrectedCMuscle.getExecutable(), - Executable.ExecProvider.Local); + .configureExecutable(resurrectedCMuscle.getExecutable(), + Executable.ExecProvider.Local); sexec = Configurator.getSyncEngine(resJronn, Executable.ExecProvider.Local); @@ -347,20 +347,20 @@ public class JronnTester { } } - @Test(groups = { AllTestSuit.test_group_runner }) + @Test(groups = {AllTestSuit.test_group_runner}) public void testConfigurationLoading() { try { RunnerConfig jronnConfig = ConfExecutable - .getRunnerOptions(Jronn.class); + .getRunnerOptions(Jronn.class); assertNotNull(jronnConfig); assertTrue(jronnConfig.getArguments().size() > 0); PresetManager jronnPresets = ConfExecutable - .getRunnerPresets(Jronn.class); + .getRunnerPresets(Jronn.class); assertNull(jronnPresets); // there is no presets LimitsManager jronnLimits = ConfExecutable - .getRunnerLimits(Jronn.class); + .getRunnerLimits(Jronn.class); assertNotNull(jronnLimits); assertTrue(jronnLimits.getLimits().size() > 0); jronnLimits.validate(jronnPresets); diff --git a/webservices/compbio/ws/client/IOHelper.java b/webservices/compbio/ws/client/IOHelper.java index af9a52c..79357e5 100644 --- a/webservices/compbio/ws/client/IOHelper.java +++ b/webservices/compbio/ws/client/IOHelper.java @@ -11,9 +11,11 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import java.util.Set; import compbio.data.sequence.Alignment; import compbio.data.sequence.ClustalAlignmentUtil; +import compbio.data.sequence.Score; public class IOHelper { @@ -109,4 +111,29 @@ public class IOHelper { } } + /** + * Outputs AAcon results into the file represented by the outStream + * + * @param outStream + * @param result + * the AACon scores to output + */ + static void writeOut(OutputStream outStream, Set result) { + try { + Score.write(result, outStream); + } catch (IOException e) { + System.err + .println("Problems writing output file! Stack trace is below: "); + e.printStackTrace(); + } finally { + if (outStream != null) { + try { + outStream.close(); + } catch (IOException ignored) { + // e.printStackTrace(); + } + } + } + } + } diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index 9da8abe..1673e18 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -38,18 +38,22 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.ws.Service; import javax.xml.ws.WebServiceException; +import compbio.data.msa.Annotation; import compbio.data.msa.JABAService; import compbio.data.msa.Metadata; import compbio.data.msa.MsaWS; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.Score; import compbio.data.sequence.SequenceUtil; +import compbio.data.sequence.UnknownFileFormatException; import compbio.metadata.JobSubmissionException; import compbio.metadata.Option; import compbio.metadata.Preset; @@ -147,23 +151,25 @@ public class Jws2Client { } Alignment alignment = null; if (inputFile != null) { + OutputStream outStream = null; + if (outFile != null) { + outStream = IOHelper.getOutStream(outFile); + } else { + // this stream is going to be closed later which is fine as + // std.out will not be + outStream = System.out; + } if (service == Services.AAConWS) { - System.out.println("calc conserv!"); + Set result = analize(inputFile, ((Annotation) msaws), + preset, customOptions); + IOHelper.writeOut(outStream, result); } else { - alignment = align(inputFile, (MsaWS) msaws, preset, customOptions); - OutputStream outStream = null; - if (outFile != null) { - outStream = IOHelper.getOutStream(outFile); - } else { - // this stream is going to be closed later which is fine as - // std.out will not be - outStream = System.out; - } IOHelper.writeOut(outStream, alignment); - // stream is closed in the method no need to close it here } + + // stream is closed in the method no need to close it here } boolean listParameters = CmdHelper.listParameters(cmd); @@ -182,6 +188,75 @@ public class Jws2Client { ((Closeable) msaws).close(); log.fine("Disconnected successfully!"); } + /** + * Calculate conservation for sequences loaded from the file + * + * @param wsproxy + * a web service proxy + * @param file + * the file to read the results from + * @param preset + * Preset to use optional + * @param customOptions + * the list of options + * @return Set the conservation scores + * @throws UnknownFileFormatException + */ + Set analize(File file, Annotation wsproxy, Preset preset, + List> customOptions) { + + List fastalist = null; + Set scores = null; + try { + fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); + + String jobId = null; + if (customOptions != null && preset != null) { + System.out + .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!"); + } + if (customOptions != null) { + jobId = wsproxy.customAnalize(fastalist, customOptions); + } else if (preset != null) { + jobId = wsproxy.presetAnalize(fastalist, preset); + } else { + jobId = wsproxy.analize(fastalist); + } + Thread.sleep(1000); + scores = wsproxy.getAnnotation(jobId); + + } catch (IOException e) { + System.err + .println("Exception while reading the input file. " + + "Check that the input file contains a list of fasta formatted sequences! " + + "Exception details are below:"); + e.printStackTrace(); + } catch (JobSubmissionException e) { + System.err + .println("Exception while submitting job to a web server. " + + "Exception details are below:"); + e.printStackTrace(); + } catch (ResultNotAvailableException e) { + System.err.println("Exception while waiting for results. " + + "Exception details are below:"); + e.printStackTrace(); + } catch (InterruptedException ignored) { + // ignore and propagate an interruption + Thread.currentThread().interrupt(); + } catch (WrongParameterException e) { + System.err + .println("Exception while parsing the web method input parameters. " + + "Exception details are below:"); + e.printStackTrace(); + } catch (UnknownFileFormatException e) { + System.err + .println("Exception while attempting to read the input file " + + "Exception details are below:"); + System.out.println(e.getMessage()); + e.printStackTrace(); + } + return scores; + } /** * Connects to a web service by the host and the service name diff --git a/webservices/compbio/ws/server/JronnWS.java b/webservices/compbio/ws/server/JronnWS.java new file mode 100644 index 0000000..bcb6af5 --- /dev/null +++ b/webservices/compbio/ws/server/JronnWS.java @@ -0,0 +1,177 @@ +package compbio.ws.server; + +import java.io.File; +import java.util.HashSet; +import java.util.List; + +import javax.annotation.Resource; +import javax.jws.WebService; +import javax.xml.ws.WebServiceContext; + +import org.apache.log4j.Logger; + +import compbio.data.msa.Annotation; +import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.Score; +import compbio.engine.AsyncExecutor; +import compbio.engine.Configurator; +import compbio.engine.client.ConfiguredExecutable; +import compbio.metadata.ChunkHolder; +import compbio.metadata.JobStatus; +import compbio.metadata.JobSubmissionException; +import compbio.metadata.Limit; +import compbio.metadata.LimitExceededException; +import compbio.metadata.LimitsManager; +import compbio.metadata.Option; +import compbio.metadata.Preset; +import compbio.metadata.PresetManager; +import compbio.metadata.ResultNotAvailableException; +import compbio.metadata.RunnerConfig; +import compbio.metadata.UnsupportedRuntimeException; +import compbio.metadata.WrongParameterException; +import compbio.runner.Util; +import compbio.runner.conservation.AACon; +import compbio.runner.disorder.Jronn; + +@WebService(endpointInterface = "compbio.data.msa.Annotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "JronnWS") +public class JronnWS implements Annotation { + + // Ask for resource injection + @Resource + WebServiceContext wsContext; + + private static Logger statLog = Logger.getLogger("JronnWS-stats"); + + private static Logger log = Logger.getLogger(JronnWS.class); + + private static final RunnerConfig aaconOptions = Util + .getSupportedOptions(Jronn.class); + + private static final PresetManager aaconPresets = Util + .getPresets(Jronn.class); + + ConfiguredExecutable init(List sequences) + throws JobSubmissionException { + Jronn jronn = new Jronn(); + jronn.setInput("fasta.in").setOutput("aacon.out"); + return Configurator.configureExecutable(jronn, sequences); + } + + @Override + public HashSet getAnnotation(String jobId) + throws ResultNotAvailableException { + WSUtil.validateJobId(jobId); + AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); + ConfiguredExecutable aacon = (ConfiguredExecutable) asyncEngine + .getResults(jobId); + HashSet mas = aacon.getResults(); + log.trace(jobId + " getConservation : " + mas); + return mas; + } + /* + * @SuppressWarnings("unchecked") public JalviewAnnotation + * getJalviewAnnotation(String jobId) throws ResultNotAvailableException { + * MultiAnnotatedSequence result = getResult(jobId); // TODO // + * log(jobId, "getResults"); return result.toJalviewAnnotation(); } + */ + + @Override + public Limit getLimit(String presetName) { + return new Jronn().getLimit(presetName); + } + + @Override + public LimitsManager getLimits() { + return new Jronn().getLimits(); + } + + @Override + public ChunkHolder pullExecStatistics(String jobId, long position) { + WSUtil.validateJobId(jobId); + String file = Configurator.getWorkDirectory(jobId) + File.separator + + Jronn.getStatFile(); + return WSUtil.pullFile(file, position); + } + + @Override + public boolean cancelJob(String jobId) { + WSUtil.validateJobId(jobId); + return WSUtil.cancelJob(jobId); + } + + @Override + public JobStatus getJobStatus(String jobId) { + WSUtil.validateJobId(jobId); + return WSUtil.getJobStatus(jobId); + } + + @Override + public PresetManager getPresets() { + return aaconPresets; + } + + @Override + public RunnerConfig getRunnerOptions() { + return aaconOptions; + } + + String analize(List sequences, + ConfiguredExecutable confExec, Logger log, String method, + Limit limit) throws JobSubmissionException { + if (limit != null && limit.isExceeded(sequences)) { + throw LimitExceededException.newLimitExceeded(limit, sequences); + } + + compbio.runner.Util.writeInput(sequences, confExec); + AsyncExecutor engine = Configurator.getAsyncEngine(confExec); + String jobId = engine.submitJob(confExec); + return jobId; + } + + @Override + public String analize(List sequences) + throws UnsupportedRuntimeException, LimitExceededException, + JobSubmissionException { + WSUtil.validateFastaInput(sequences); + ConfiguredExecutable confAAcon = init(sequences); + + // set default conservation method to fastest - SHENKIN + // TODO: This violates encapsulation, should be moved to the runners + // level. + // confAAcon.addParameters(Arrays.asList("-m=SHENKIN")); + return analize(sequences, confAAcon, null, "analize", getLimit("")); + } + + @Override + public String customAnalize(List sequences, + List> options) throws UnsupportedRuntimeException, + LimitExceededException, JobSubmissionException, + WrongParameterException { + WSUtil.validateFastaInput(sequences); + ConfiguredExecutable confJronn = init(sequences); + // Could not do that! Space separated values + // will all be treated as keys! thus duplicates removed + // String params = cbuilder.getCommand(); + List params = WSUtil.getCommands(options, + AACon.KEY_VALUE_SEPARATOR); + confJronn.addParameters(params); + return analize(sequences, confJronn, null, "customAnalize", + getLimit("")); + } + + @Override + public String presetAnalize(List sequences, + Preset preset) throws UnsupportedRuntimeException, + LimitExceededException, JobSubmissionException, + WrongParameterException { + WSUtil.validateFastaInput(sequences); + if (preset == null) { + throw new WrongParameterException("Preset must be provided!"); + } + ConfiguredExecutable confJronn = init(sequences); + confJronn.addParameters(preset.getOptions()); + Limit limit = getLimit(preset.getName()); + return WSUtil.align(sequences, confJronn, null, "presetAnalize", limit); + } + +} -- 1.7.10.2