X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FAAConClient.java;h=4619c602dd08b91d1f216bf9c5cd95d6f03f859a;hb=3644426ec0e9e9ceb798bd426085d8d9dd8dbb56;hp=5fa373d08f3df3ded3b38bb57998c3090386a4fc;hpb=6695d8f2418a044b900e9a23dfc3bd04e0f7c222;p=jabaws.git diff --git a/webservices/compbio/ws/client/AAConClient.java b/webservices/compbio/ws/client/AAConClient.java index 5fa373d..4619c60 100644 --- a/webservices/compbio/ws/client/AAConClient.java +++ b/webservices/compbio/ws/client/AAConClient.java @@ -1,6 +1,6 @@ -/* Copyright (c) 2009 Peter Troshin +/* Copyright (c) 2010 Peter Troshin * - * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 + * Amino Acid Conservation Web Service client @version: 1.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 @@ -29,14 +29,11 @@ import static compbio.ws.client.Constraints.pseparator; import java.io.Closeable; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; 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; @@ -44,10 +41,11 @@ import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.WebServiceException; -import compbio.data.msa.Annotation; +import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.FastaSequence; -import compbio.data.sequence.Score; +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; @@ -70,57 +68,40 @@ public class AAConClient { private static final Logger log = Logger.getLogger(AAConClient.class .getCanonicalName()); + /** + * The fully qualified web service namespace + */ static final String QUALIFIED_SERVICE_NAME = "http://msa.data.compbio/01/12/2010/"; - // static final String hostname = "http://www.compbio.dundee.ac.uk/aacon"; - static final String hostname = "http://localhost:8080/jabaws"; - - static final String serviceName = "AAConWS"; + /** + * Web service host + */ + static final String hostname = "http://www.compbio.dundee.ac.uk/aacon"; + // static final String hostname = "http://localhost:8080/jabaws"; /** - * Attempt to construct the URL object from the string - * - * @param urlstr - * @return true if it succeed false otherwise + * Web service name */ - public static boolean validURL(String urlstr) { - try { - if (urlstr == null || urlstr.trim().length() == 0) { - return false; - } - new URL(urlstr); - } catch (MalformedURLException e) { - return false; - } - return true; - } + static final String serviceName = "AAConWS"; /** * Connects to the service and do the job as requested, if something goes * wrong reports or/and prints usage help. * - * @param - * web service type * @param cmd * command line options * @throws IOException + * if the system cannot read/write from/into the file system */ @SuppressWarnings("unchecked") AAConClient(String[] cmd) throws IOException { - Services service = Services.getService(serviceName); - if (service == null) { - System.out.println("Service " + serviceName - + " is no supported! Valid values are: " - + Arrays.toString(Services.values())); - printUsage(1); - } File inputFile = IOHelper.getFile(cmd, inputkey, true); File outFile = IOHelper.getFile(cmd, outputkey, false); File parametersFile = IOHelper.getFile(cmd, paramFile, true); String presetName = CmdHelper.getPresetName(cmd); - Annotation msaws = connect(hostname, service); + SequenceAnnotation msaws = connect(); Preset preset = null; if (presetName != null) { preset = MetadataHelper.getPreset(msaws, presetName); @@ -131,9 +112,9 @@ public class AAConClient { customOptions = MetadataHelper.processParameters(prms, msaws.getRunnerOptions()); } - Set result = null; + ScoreManager result = null; if (inputFile != null) { - System.out.println("calc conserv!"); + System.out.println("Calculating conservation..."); result = analize(inputFile, msaws, preset, customOptions); OutputStream outStream = null; if (outFile != null) { @@ -165,16 +146,15 @@ public class AAConClient { } /** - * Outputs clustal formatted alignment into the file represented by the - * outStream + * Outputs AAcon results into the file represented by the outStream * * @param outStream - * @param align - * the alignment to output + * @param result + * the AACon scores to output */ - static void writeOut(OutputStream outStream, Set result) { + static void writeOut(OutputStream outStream, ScoreManager result) { try { - Score.write(result, outStream); + result.writeOut(outStream); } catch (IOException e) { System.err .println("Problems writing output file! Stack trace is below: "); @@ -191,60 +171,57 @@ public class AAConClient { } /** - * Connects to a web service by the host and the service name + * Connects to a AACon web service by the host and the service name + * * - * @param T - * web service type - * @param host - * @param service - * @return MsaWS + * @return {@link AlignmentAnnotation} * @throws WebServiceException + * if cannot connect to a web service */ - public static Annotation connect(String host, Services service) + public static SequenceAnnotation connect() throws WebServiceException { URL url = null; log.log(Level.FINE, "Attempting to connect..."); try { - url = new URL(host + "/" + service.toString() + "?wsdl"); + url = new URL(hostname + "/" + "AAConWS" + "?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); // ignore as the host name is already verified } - Service serv = service.getService(url, QUALIFIED_SERVICE_NAME); - @SuppressWarnings("unchecked") + QName qname = new QName(QUALIFIED_SERVICE_NAME, "AAConWS"); + Service serv = Service.create(url, qname); QName portName = new QName(QUALIFIED_SERVICE_NAME, "AAConWS" + "Port"); - Annotation serviceIF = serv - .getPort(portName, Annotation.class); + @SuppressWarnings("unchecked") + SequenceAnnotation serviceIF = serv.getPort(portName, + SequenceAnnotation.class); log.log(Level.FINE, "Connected successfully!"); return serviceIF; } /** - * Align sequences from the file using MsaWS + * Calculate conservation for sequences loaded from the file * - * @param - * web service type e.g. Clustal - * @param file - * to write the resulting alignment to * @param wsproxy - * MsaWS required + * a web service proxy + * @param file + * the file to read the results from * @param preset * Preset to use optional * @param customOptions - * file which contains new line separated list of options - * @return Alignment + * the list of options + * @return Set the conservation scores + * @throws UnknownFileFormatException */ - static Set analize(File file, Annotation wsproxy, + static ScoreManager analize(File file, SequenceAnnotation wsproxy, Preset preset, List> customOptions) { - FileInputStream instream = null; + List fastalist = null; - Set scores = null; + ScoreManager scores = null; try { - instream = new FileInputStream(file); - fastalist = SequenceUtil.readFasta(instream); - instream.close(); + fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); + String jobId = null; if (customOptions != null && preset != null) { System.out @@ -279,21 +256,22 @@ public class AAConClient { // 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(); - } finally { - if (instream != null) { - try { - instream.close(); - } catch (IOException ignored) { - // ignore - } - } } return scores; } /** - * Prints Jws2Client usage information to standard out + * Prints AAConClient usage information to standard out * * @param exitStatus */ @@ -335,9 +313,7 @@ public class AAConClient { } /** - * Starts command line client, if no parameter are supported print help. Two - * parameters are required for successfull call the JWS2 host name and a - * service name. + * Starts command line client, if no parameters are supplied prints help. * * @param args * Usage: ACTION [OPTIONS]