X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fserver%2FWSUtil.java;h=89c73755a6ad8e663dcb67586109669b904da9a4;hb=b56011664ec5d11bb5d0cd09395e646586888700;hp=62996e521d709b0c67b26be0e1814ba382b97acc;hpb=fab6bab770b548a0c99ed6f5dfb46f5aa99f67c7;p=jabaws.git diff --git a/webservices/compbio/ws/server/WSUtil.java b/webservices/compbio/ws/server/WSUtil.java index 62996e5..89c7375 100644 --- a/webservices/compbio/ws/server/WSUtil.java +++ b/webservices/compbio/ws/server/WSUtil.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,37 +19,54 @@ package compbio.ws.server; import java.security.InvalidParameterException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; + +import org.apache.log4j.Logger; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.ScoreManager; +import compbio.runner.RunnerUtil; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.ProgressGetter; import compbio.engine.client.ConfiguredExecutable; +import compbio.engine.client.EngineUtil; import compbio.metadata.ChunkHolder; import compbio.metadata.JobStatus; import compbio.metadata.JobSubmissionException; import compbio.metadata.Limit; import compbio.metadata.LimitExceededException; import compbio.metadata.Option; -import compbio.util.Timer; +import compbio.metadata.ResultNotAvailableException; +import compbio.ws.client.Services; +import compbio.ws.client.ServicesUtil; public final class WSUtil { public static final void validateJobId(String jobId) throws InvalidParameterException { - if (!compbio.engine.client.Util.isValidJobId(jobId)) { - throw new InvalidParameterException( - "JobId is not provided or cannot be recognised! Given value: " - + jobId); + if (!EngineUtil.isValidJobId(jobId)) { + throw new InvalidParameterException("JobId is not provided or cannot be recognised! Given value: " + jobId); } } public static final void validateFastaInput(List sequences) - throws InvalidParameterException { + throws JobSubmissionException { if (sequences == null || sequences.isEmpty()) { - throw new InvalidParameterException( - "List of fasta sequences required but not provided! "); + throw new JobSubmissionException("List of fasta sequences required but not provided! "); + } + Set names = new HashSet(); + for (FastaSequence fs : sequences) { + boolean unique = names.add(fs.getId()); + if (!unique) { + throw new JobSubmissionException( + "Input sequences must have unique names! \nSequence " + fs.getId() + " is a duplicate!"); + } + if (fs.getLength() == 0) { + throw new JobSubmissionException("Sequence must not be empty! Sequence: " + fs.getId() + " was empty"); + } } } @@ -77,19 +94,56 @@ public final class WSUtil { } public static String align(List sequences, - ConfiguredExecutable confExec, WSLogger logger, + ConfiguredExecutable confExec, Logger logger, String callingMethod, Limit limit) throws LimitExceededException, JobSubmissionException { - Timer timer = Timer.getMilliSecondsTimer(); + if (limit != null && limit.isExceeded(sequences)) { throw LimitExceededException.newLimitExceeded(limit, sequences); } - compbio.runner.Util.writeInput(sequences, confExec); + RunnerUtil.writeInput(sequences, confExec); AsyncExecutor engine = Configurator.getAsyncEngine(confExec); String jobId = engine.submitJob(confExec); - if (logger != null) { - logger.log(timer, callingMethod, jobId); + reportUsage(confExec, logger); + return jobId; + } + + + static void reportUsage(ConfiguredExecutable confExec, Logger logger) { + if (GAUtils.IS_GA_ENABLED) { + Services service = ServicesUtil.getServiceByRunner(confExec.getExecutable().getClass()); + GAUtils.reportUsage(service); + logger.info("Reporting GA usage for " + service); + } + } + + public static 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); } + RunnerUtil.writeInput(sequences, confExec); + AsyncExecutor engine = Configurator.getAsyncEngine(confExec); + String jobId = engine.submitJob(confExec); + reportUsage(confExec, log); + return jobId; + } + + // Same as analize(...) but RNAalifold takes clustal input not fasta + // An if condition in the above method might be a better solution but + // you need a way of finding out the type of confExec at runtime + + public static String fold(List sequences, + ConfiguredExecutable confExec, Logger log, String method, + Limit limit) throws JobSubmissionException { + if (limit != null && limit.isExceeded(sequences)) { + throw LimitExceededException.newLimitExceeded(limit, sequences); + } + RunnerUtil.writeClustalInput(sequences, confExec, '-'); + AsyncExecutor engine = Configurator.getAsyncEngine(confExec); + String jobId = engine.submitJob(confExec); + reportUsage(confExec, log); return jobId; } @@ -105,4 +159,51 @@ public final class WSUtil { return oList; } + public static void validateAAConInput(List sequences) + throws JobSubmissionException { + validateFastaInput(sequences); + int len = 0; + for (FastaSequence fs : sequences) { + if (len == 0) { + len = fs.getLength(); + continue; + } + if (fs.getLength() != len) { + throw new JobSubmissionException( + "All sequences must be of the same length. Please align the sequences " + + " prior to submission! The first sequence length is : " + len + + " but the sequence '" + fs.getId() + "' length is " + fs.getLength()); + } + } + } + + public static void validateJpredInput(List sequences) + throws JobSubmissionException { + validateFastaInput(sequences); + int len = 0; + for (FastaSequence fs : sequences) { + if (len == 0) { + len = fs.getLength(); + continue; + } + if (fs.getLength() != len) { + System.out.println("FASTA rec: id = " + fs.getId() + ": seq = " + fs.getSequence()); + throw new JobSubmissionException( + "All sequences must be of the same length. Please align the sequences " + + " prior to submission! The first sequence length is : " + len + + " but the sequence '" + fs.getId() + "' length is " + fs.getLength()); + } + } + } + + public static ScoreManager getAnnotation(String jobId, Logger log) + throws ResultNotAvailableException { + WSUtil.validateJobId(jobId); + AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); + ConfiguredExecutable aacon = (ConfiguredExecutable) asyncEngine.getResults(jobId); + ScoreManager mas = aacon.getResults(); + log.trace(jobId + " getConservation : " + mas); + return mas; + } + }