X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FJws2Client.java;h=dbe999a464c67ee2455d7408c5217d3c5dd90ac1;hb=b2a2fdc2bd95a64b3908d8ea2f31270b6c7199d3;hp=3322b35194617ad4fd34d1366cba6c4f72fadba8;hpb=c278475ed30f89bd64dfb0bebc86576defd8061f;p=jabaws.git diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index 3322b35..dbe999a 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -25,6 +25,7 @@ import static compbio.ws.client.Constraints.paramFile; import java.io.Closeable; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; @@ -48,13 +49,17 @@ import compbio.data.msa.MsaWS; import compbio.data.msa.RegistryWS; import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.Alignment; +import compbio.data.sequence.AlignmentMetadata; +import compbio.data.sequence.JpredAlignment; 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.Limit; import compbio.metadata.Preset; +import compbio.metadata.PresetManager; import compbio.metadata.ResultNotAvailableException; import compbio.metadata.WrongParameterException; import compbio.util.FileUtil; @@ -67,7 +72,7 @@ import compbio.util.FileUtil; */ public class Jws2Client { - /* + /** * Use java.util.Logger instead of log4j logger to reduce the size of the client package */ private static final Logger log = Logger.getLogger(Jws2Client.class.getCanonicalName()); @@ -100,7 +105,9 @@ public class Jws2Client { * command line options * @throws IOException */ + @SuppressWarnings("unchecked") Jws2Client(String[] cmd) throws IOException { + String hostname = CmdHelper.getHost(cmd); if (hostname == null) { @@ -160,27 +167,52 @@ public class Jws2Client { if (outfile != null) { writer = IOHelper.getWriter(outfile); } else { - // this stream is going to be closed later which is fine as std.out will not be writer = new PrintWriter(System.out, true); } if (service.getServiceType() == SequenceAnnotation.class) { ScoreManager result = analize(infile, ((SequenceAnnotation) thews), preset, customOptions); IOHelper.writeOut(writer, result); + writer.close(); } else if (service.getServiceType() == MsaWS.class) { Alignment alignment = align(infile, (MsaWS) thews, preset, customOptions); - IOHelper.writeOut(writer, alignment); + if (serviceName.equalsIgnoreCase("JpredWS")) { + writer.close(); + JpredAlignment jpred = (JpredAlignment)alignment; + if (outfile != null) { + FileOutputStream fout = new FileOutputStream(outfile); + SequenceUtil.writeFastaKeepTheStream(fout, jpred.getJpredSequences(), 60); + fout.close(); + } else { + SequenceUtil.writeFasta(System.out, jpred.getJpredSequences()); + } + } else { + IOHelper.writeOut(writer, alignment); + writer.close(); + } + AlignmentMetadata md = alignment.getMetadata(); + System.out.println("Output has been prepared with " + md.getProgram()); } - writer.close(); } if (CmdHelper.listParameters(cmd)) { - System.out.println(MetadataHelper.getParametersList(thews)); + List> opts = MetadataHelper.getParametersList(thews, hostname); + for (Option o : opts) { + System.out.println("##############################################################################\n" + o.toString()); + } } if (CmdHelper.listPresets(cmd)) { - System.out.println(MetadataHelper.getPresetList(thews)); + PresetManager psm = MetadataHelper.getPresetList(thews); + if (null != psm) { + System.out.print(psm); + } else { + System.out.println("No presets are defined for the Web service"); + } } if (CmdHelper.listLimits(cmd)) { - System.out.println(MetadataHelper.getLimits(thews)); + List> lims = MetadataHelper.getLimits(thews); + for (Limit l : lims) { + System.out.println("##############################################################################\n" + l.toString()); + } } log.fine("Disconnecting..."); ((Closeable) thews).close(); @@ -251,7 +283,7 @@ public class Jws2Client { e.printStackTrace(); // ignore as the host name is already verified } - QName qname = new QName(JABAService.V3_SERVICE_NAMESPACE, service); + QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service); Service serv = Service.create(url, qname); if (serv == null) { @@ -288,8 +320,8 @@ public class Jws2Client { private static void listAllServices(String hostname) throws WebServiceException, IOException { RegistryWS registry = connectToRegistry(hostname); - Set func_services = Collections.EMPTY_SET; - Set nonfunc_services = Collections.EMPTY_SET; + Set func_services = Collections.emptySet(); + Set nonfunc_services = Collections.emptySet(); if (registry != null) { func_services = registry.getSupportedServices(); nonfunc_services = registry.getNonoperatedServices(); @@ -299,11 +331,13 @@ public class Jws2Client { return; } if (!func_services.isEmpty()) { - String mess = "\n\rAvailable services: "; + System.out.println("There are " + func_services.size() + " services at " + hostname + ":"); + String mess = "\n\rThe list:\n"; System.out.println(mess + Services.toString(func_services)); } if (!nonfunc_services.isEmpty()) { - String mess = "Non-available services (internal tests failed): "; + System.out.println("There are " + nonfunc_services.size() + " non-available services at " + hostname + ":"); + String mess = "The list (internal tests failed): "; System.out.println(mess + Services.toString(nonfunc_services)); } } @@ -409,11 +443,10 @@ public class Jws2Client { static Alignment align(File file, MsaWS msaws, Preset preset, List> customOptions) { FileInputStream instream = null; - List fastalist = null; Alignment alignment = null; try { instream = new FileInputStream(file); - fastalist = SequenceUtil.readFasta(instream); + List fastalist = SequenceUtil.readFasta(instream); instream.close(); String jobId = null; if (customOptions != null && preset != null) { @@ -426,22 +459,18 @@ public class Jws2Client { } else { jobId = msaws.align(fastalist); } - System.out.println("\ncalling aligner........."); - Thread.sleep(1000); + System.out.println("\ncalling program........."); + Thread.sleep(100); alignment = msaws.getResult(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! " + System.err.println("Exception while reading the input file. Check that the input file is a FASTA file! " + "Exception details are below:"); e.printStackTrace(); } catch (JobSubmissionException e) { - System.err.println("Exception while submitting job to a web server. " - + "Exception details are below:"); + 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:"); + System.err.println("Exception while waiting for results. Exception details are below:"); e.printStackTrace(); } catch (InterruptedException ignored) { // ignore and propagate an interruption @@ -459,7 +488,7 @@ public class Jws2Client { } return alignment; } - + /** * Starts command line client, if no parameter are supported print help. Two * parameters are required for successful call the JWS2 host name and a @@ -497,7 +526,6 @@ public class Jws2Client { * */ public static void main(String[] args) { - if (args == null) { System.out.println(Constraints.help_text); System.exit(1); @@ -507,7 +535,6 @@ public class Jws2Client { System.out.println(Constraints.help_text); System.exit(1); } - try { new Jws2Client(args); } catch (IOException e) {