From: pvtroshin Date: Thu, 23 Dec 2010 14:29:57 +0000 (+0000) Subject: Moving a method from AACon to SequenceUtil X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e98ca8829b7c42c00f2f2588e1168d3f31eb248f;p=jabaws.git Moving a method from AACon to SequenceUtil git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3567 e3abac25-378b-4346-85de-24260fe3988d --- diff --git a/binaries/aaconservation.jar b/binaries/aaconservation.jar index e16b9a8..5f76eab 100644 Binary files a/binaries/aaconservation.jar and b/binaries/aaconservation.jar differ diff --git a/datamodel/compbio/data/sequence/SequenceUtil.java b/datamodel/compbio/data/sequence/SequenceUtil.java index 20628a1..f061ac7 100644 --- a/datamodel/compbio/data/sequence/SequenceUtil.java +++ b/datamodel/compbio/data/sequence/SequenceUtil.java @@ -483,7 +483,8 @@ public final class SequenceUtil { assert spacePos > 0 : "Space is expected as delimited between method " + "name and values!"; String methodLine = line.substring(0, spacePos); - ConservationMethod method = ConservationMethod.getMethod(methodLine); + ConservationMethod method = ConservationMethod + .getMethod(methodLine); assert method != null : "Method " + methodLine + " is not recognized! "; Scanner valuesScanner = new Scanner(line.substring(spacePos)); @@ -497,4 +498,37 @@ public final class SequenceUtil { return annotations; } + /** + * Reads and parses Fasta or Clustal formatted file into a list of + * FastaSequence objects + * + * @param inFilePath + * the path to the input file + * @throws IOException + * if the file denoted by inFilePath cannot be read + * @throws UnknownFileFormatException + * if the inFilePath points to the file which format cannot be + * recognised + * @return the List of FastaSequence objects + * + */ + public static List openInputStream(String inFilePath) + throws IOException, UnknownFileFormatException { + + // This stream gets closed in isValidClustalFile method + InputStream inStrForValidation = new FileInputStream(inFilePath); + // This stream is closed in the calling methods + InputStream inStr = new FileInputStream(inFilePath); + List fastaSeqs = null; + if (ClustalAlignmentUtil.isValidClustalFile(inStrForValidation)) { + Alignment al = ClustalAlignmentUtil.readClustalFile(inStr); + // alignment cannot be null see + // ClustalAlignmentUtil.readClustalFile(inStr); + fastaSeqs = al.getSequences(); + } else { + fastaSeqs = SequenceUtil.readFasta(inStr); + } + return fastaSeqs; + } + } diff --git a/webservices/compbio/ws/client/AAConClient.java b/webservices/compbio/ws/client/AAConClient.java index 5fa373d..34fc751 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,12 +29,10 @@ 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; @@ -48,6 +46,7 @@ import compbio.data.msa.Annotation; 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; @@ -70,57 +69,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); + Annotation msaws = connect(); Preset preset = null; if (presetName != null) { preset = MetadataHelper.getPreset(msaws, presetName); @@ -133,7 +115,7 @@ public class AAConClient { } Set 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,12 +147,11 @@ 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) { try { @@ -191,29 +172,27 @@ 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 Annotation} * @throws WebServiceException + * if cannot connect to a web service */ - public static Annotation connect(String host, Services service) - throws WebServiceException { + public static Annotation 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"); + @SuppressWarnings("unchecked") Annotation serviceIF = serv .getPort(portName, Annotation.class); @@ -222,29 +201,27 @@ public class AAConClient { } /** - * 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 Set analize(File file, Annotation wsproxy, Preset preset, List> customOptions) { - FileInputStream instream = null; + List fastalist = null; Set 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]