X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FJws2Client.java;h=eda6533fc8d2d02ed04fd7a52724f729c66b1b89;hb=3644426ec0e9e9ceb798bd426085d8d9dd8dbb56;hp=5c7a879cae518e987f2352c9f683bda54cb837ec;hpb=6e1c873d0879f462b1fb1a1efa444cf993a9e76a;p=jabaws.git diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index 5c7a879..eda6533 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -47,9 +47,12 @@ import javax.xml.ws.WebServiceException; import compbio.data.msa.JABAService; import compbio.data.msa.Metadata; import compbio.data.msa.MsaWS; +import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.ScoreManager; import compbio.data.sequence.SequenceUtil; +import compbio.data.sequence.UnknownFileFormatException; import compbio.metadata.JobSubmissionException; import compbio.metadata.Option; import compbio.metadata.Preset; @@ -147,23 +150,25 @@ public class Jws2Client { } Alignment alignment = null; if (inputFile != null) { - if (service == Services.AAConWS) { - System.out.println("calc conserv!"); + 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.getServiceType() == SequenceAnnotation.class) { + ScoreManager result = analize(inputFile, + ((SequenceAnnotation) 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 } + outStream.close(); } boolean listParameters = CmdHelper.listParameters(cmd); @@ -182,11 +187,83 @@ 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 + */ + ScoreManager analize(File file, SequenceAnnotation wsproxy, + Preset preset, List> customOptions) { + + List fastalist = null; + ScoreManager scores = null; + try { + fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); + assert !fastalist.isEmpty() : "Input is empty!"; + + 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 { + System.out.println("\n\ncalling analise........."); + jobId = wsproxy.analize(fastalist); + } + Thread.sleep(2000); + + 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 * - * @param + * @param T * web service type * @param host * @param service @@ -212,8 +289,13 @@ public class Jws2Client { serv = service.getService(url, V2_QUALIFIED_SERVICE_NAME); } } + if (serv == null) { + System.err.println("Could not connect to " + url + + " the server is down?"); + // FIXME + } JABAService serviceIF = service.getInterface(serv); - log.log(Level.FINE, "Connected successfully!"); + log.log(Level.INFO, "Connected successfully!"); return serviceIF; } @@ -351,7 +433,7 @@ public class Jws2Client { /** * Starts command line client, if no parameter are supported print help. Two - * parameters are required for successfull call the JWS2 host name and a + * parameters are required for successful call the JWS2 host name and a * service name. * * @param args