Webservice works! but only supports some parameters. Replacing RNAstuct
[jabaws.git] / webservices / compbio / ws / client / Jws2Client.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.ws.client;\r
20 \r
21 import static compbio.ws.client.Constraints.inputkey;\r
22 import static compbio.ws.client.Constraints.outputkey;\r
23 import static compbio.ws.client.Constraints.paramFile;\r
24 \r
25 import java.io.Closeable;\r
26 import java.io.File;\r
27 import java.io.FileInputStream;\r
28 import java.io.IOException;\r
29 import java.io.PrintWriter;\r
30 import java.io.Writer;\r
31 import java.net.ConnectException;\r
32 import java.net.MalformedURLException;\r
33 import java.net.URL;\r
34 import java.util.Arrays;\r
35 import java.util.Collections;\r
36 import java.util.List;\r
37 import java.util.Set;\r
38 import java.util.logging.Level;\r
39 import java.util.logging.Logger;\r
40 \r
41 import javax.xml.namespace.QName;\r
42 import javax.xml.ws.Service;\r
43 import javax.xml.ws.WebServiceException;\r
44 \r
45 import compbio.data.msa.JABAService;\r
46 import compbio.data.msa.FoldWS;\r
47 import compbio.data.msa.Metadata;\r
48 import compbio.data.msa.MsaWS;\r
49 import compbio.data.msa.RegistryWS;\r
50 import compbio.data.msa.SequenceAnnotation;\r
51 import compbio.data.sequence.Alignment;\r
52 import compbio.data.sequence.FastaSequence;\r
53 import compbio.data.sequence.RNAstruct;\r
54 import compbio.data.sequence.ScoreManager;\r
55 import compbio.data.sequence.ClustalAlignmentUtil;\r
56 import compbio.data.sequence.SequenceUtil;\r
57 import compbio.data.sequence.UnknownFileFormatException;\r
58 import compbio.metadata.JobSubmissionException;\r
59 import compbio.metadata.Option;\r
60 import compbio.metadata.Preset;\r
61 import compbio.metadata.ResultNotAvailableException;\r
62 import compbio.metadata.WrongParameterException;\r
63 import compbio.util.FileUtil;\r
64 \r
65 /**\r
66  * A command line client for JAva Bioinformatics Analysis Web Services\r
67  * \r
68  * @author pvtroshin\r
69  * @version 1.0\r
70  */\r
71 public class Jws2Client {\r
72 \r
73         /*\r
74          * Use java.util.Logger instead of log4j logger to reduce the size of the\r
75          * client package\r
76          */\r
77         private static final Logger log = Logger.getLogger(Jws2Client.class\r
78                         .getCanonicalName());\r
79 \r
80         /**\r
81          * Attempt to construct the URL object from the string\r
82          * \r
83          * @param urlstr\r
84          * @return true if it succeed false otherwise\r
85          */\r
86         public static boolean validURL(String urlstr) {\r
87                 try {\r
88                         if (urlstr == null || urlstr.trim().length() == 0) {\r
89                                 return false;\r
90                         }\r
91                         new URL(urlstr);\r
92                 } catch (MalformedURLException e) {\r
93                         return false;\r
94                 }\r
95                 return true;\r
96         }\r
97 \r
98         /**\r
99          * Connects to the service and do the job as requested, if something goes\r
100          * wrong reports or/and prints usage help.\r
101          * \r
102          * @param <T>\r
103          *            web service type\r
104          * @param cmd\r
105          *            command line options\r
106          * @throws IOException\r
107          */\r
108         <T> Jws2Client(String[] cmd) throws IOException {\r
109                 \r
110 \r
111                 String hostname = CmdHelper.getHost(cmd);\r
112                 if (hostname == null) {\r
113                         System.err.println("Host name is not provided!");\r
114                         printUsage(1);\r
115                 }\r
116 \r
117                 if (!validURL(hostname)) {\r
118                         System.err.println("Host name is not valid!");\r
119                         printUsage(1);\r
120                 }\r
121                 // Just list available services and quit\r
122                 boolean listServices = CmdHelper.listServices(cmd);\r
123                 if (listServices) {\r
124                         listServices(hostname);\r
125                         System.exit(0);\r
126                 }\r
127 \r
128                 String serviceName = CmdHelper.getServiceName(cmd);\r
129                 if (serviceName == null) {\r
130                         System.err.println("Service name is no provided!");\r
131                         printUsage(1);\r
132                 }\r
133                 Services service = Services.getService(serviceName);\r
134                 if (service == null) {\r
135                         System.err.println("Service " + serviceName\r
136                                         + " is no recognized! Valid values are: "\r
137                                         + Arrays.toString(Services.values()));\r
138                         printUsage(1);\r
139                 }\r
140                 // Test service and quit\r
141                 boolean testService = CmdHelper.testService(cmd);\r
142                 if (testService) {\r
143                         testService(hostname, service, new PrintWriter(System.out, true));\r
144                         System.exit(0);\r
145                 }\r
146 \r
147                 File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
148                 File outFile = IOHelper.getFile(cmd, outputkey, false);\r
149                 File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
150                 String presetName = CmdHelper.getPresetName(cmd);\r
151 \r
152                 Metadata<T> msaws = (Metadata<T>) connect(hostname, service);\r
153                 Metadata<T> foldws = (Metadata<T>) connect(hostname, service);\r
154                 Preset<T> preset = null;\r
155                 if (presetName != null) {\r
156                         preset = MetadataHelper.getPreset(msaws, presetName);\r
157                 }\r
158                 List<Option<T>> customOptions = null;\r
159                 if (parametersFile != null) {\r
160                         List<String> prms = IOHelper.loadParameters(parametersFile);\r
161                         customOptions = MetadataHelper.processParameters(prms,\r
162                                         msaws.getRunnerOptions());\r
163                 }\r
164                 Alignment alignment = null;\r
165                 RNAstruct rnastruct = null;\r
166                 if (inputFile != null) {\r
167                         Writer writer = null;\r
168                         if (outFile != null) {\r
169                                 writer = IOHelper.getWriter(outFile);\r
170                         } else {\r
171                                 // this stream is going to be closed later which is fine as\r
172                                 // std.out will not be\r
173                                 writer = new PrintWriter(System.out, true);\r
174                         }\r
175                         if (service.getServiceType() == SequenceAnnotation.class) {\r
176                                 ScoreManager result = analize(inputFile,\r
177                                                 ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
178 \r
179                                 IOHelper.writeOut(writer, result);\r
180                         } else if (service.getServiceType() == MsaWS.class) {\r
181                                 alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
182                                                 customOptions);\r
183                                 IOHelper.writeOut(writer, alignment);\r
184                         } else if (service.getServiceType() == FoldWS.class) {\r
185                                 rnastruct = fold(inputFile, (FoldWS<T>) foldws, preset, customOptions);\r
186                                 // No IOHelper method for rnastruct/String yet\r
187                                 if (writer != null) {\r
188                                         writer.write(rnastruct.toString());\r
189                                 }\r
190                         }\r
191                         writer.close();\r
192                 }\r
193 \r
194                 boolean listParameters = CmdHelper.listParameters(cmd);\r
195                 if (listParameters) {\r
196                         System.out.println(MetadataHelper.getParametersList(msaws));\r
197                 }\r
198                 boolean listPreset = CmdHelper.listPresets(cmd);\r
199                 if (listPreset) {\r
200                         System.out.println(MetadataHelper.getPresetList(msaws));\r
201                 }\r
202                 boolean listLimits = CmdHelper.listLimits(cmd);\r
203                 if (listLimits) {\r
204                         System.out.println(MetadataHelper.getLimits(msaws));\r
205                 }\r
206                 log.fine("Disconnecting...");\r
207                 ((Closeable) msaws).close();\r
208                 log.fine("Disconnected successfully!");\r
209         }\r
210 \r
211         /**\r
212          * Asks registry to test the service on the host hostname\r
213          * \r
214          * @param hostname\r
215          * @param service\r
216          * @param writer\r
217          * @throws ConnectException\r
218          * @throws WebServiceException\r
219          */\r
220         public static void testService(String hostname, Services service,\r
221                         PrintWriter writer) throws ConnectException, WebServiceException {\r
222                 RegistryWS registry = connectToRegistry(hostname);\r
223                 if (registry != null) {\r
224                         String message = registry.testService(service);\r
225                         writer.println("Service " + service + " testing results: ");\r
226                         writer.println(message);\r
227                         FileUtil.closeSilently(((Closeable) registry));\r
228                 }\r
229                 writer.flush();\r
230         }\r
231 \r
232         public static Set<Services> getServices(String hostname)\r
233                         throws WebServiceException, ConnectException {\r
234                 RegistryWS registry = connectToRegistry(hostname);\r
235                 Set<Services> services = Collections.EMPTY_SET;\r
236                 if (registry != null) {\r
237                         services = registry.getSupportedServices();\r
238                         FileUtil.closeSilently(((Closeable) registry));\r
239                 }\r
240                 return services;\r
241         }\r
242 \r
243         private static void listServices(String hostname)\r
244                         throws WebServiceException, IOException {\r
245                 Set<Services> services = Jws2Client.getServices(hostname);\r
246                 if (!services.isEmpty()) {\r
247                         System.out.println("Supported services are: "\r
248                                         + Services.toString(services));\r
249                 } else {\r
250                         System.out.println("Failed to connect to the registry! ");\r
251                 }\r
252         }\r
253 \r
254         /**\r
255          * Calculate conservation for sequences loaded from the file\r
256          * \r
257          * @param wsproxy\r
258          *            a web service proxy\r
259          * @param file\r
260          *            the file to read the results from\r
261          * @param preset\r
262          *            Preset to use optional\r
263          * @param customOptions\r
264          *            the list of options\r
265          * @return Set<Score> the conservation scores\r
266          * @throws UnknownFileFormatException\r
267          */\r
268         static <T> ScoreManager analize(List<FastaSequence> fastalist,\r
269                         SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
270                         List<Option<T>> customOptions) {\r
271 \r
272                 ScoreManager scores = null;\r
273                 try {\r
274                         String jobId = null;\r
275                         if (customOptions != null && preset != null) {\r
276                                 System.out\r
277                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
278                         }\r
279                         if (customOptions != null) {\r
280                                 jobId = wsproxy.customAnalize(fastalist, customOptions);\r
281                         } else if (preset != null) {\r
282                                 jobId = wsproxy.presetAnalize(fastalist, preset);\r
283                         } else {\r
284                                 jobId = wsproxy.analize(fastalist);\r
285                         }\r
286                         System.out.println("\n\ncalling analise.........");\r
287                         Thread.sleep(1000);\r
288                         scores = wsproxy.getAnnotation(jobId);\r
289 \r
290                 } catch (JobSubmissionException e) {\r
291                         System.err\r
292                                         .println("Exception while submitting job to a web server. "\r
293                                                         + "Exception details are below:");\r
294                         e.printStackTrace();\r
295                 } catch (ResultNotAvailableException e) {\r
296                         System.err.println("Exception while waiting for results. "\r
297                                         + "Exception details are below:");\r
298                         e.printStackTrace();\r
299                 } catch (InterruptedException e) {\r
300                         // ignore and propagate an interruption\r
301                         Thread.currentThread().interrupt();\r
302                         System.err.println("Exception while waiting for results. "\r
303                                         + "Exception details are below:");\r
304                         e.printStackTrace();\r
305                 } catch (WrongParameterException e) {\r
306                         System.err\r
307                                         .println("Exception while parsing the web method input parameters. "\r
308                                                         + "Exception details are below:");\r
309                         e.printStackTrace();\r
310                 }\r
311                 return scores;\r
312 \r
313         }\r
314 \r
315         /**\r
316          * Calculate conservation for sequences loaded from the file\r
317          * \r
318          * @param wsproxy\r
319          *            a web service proxy\r
320          * @param file\r
321          *            the file to read the results from\r
322          * @param preset\r
323          *            Preset to use optional\r
324          * @param customOptions\r
325          *            the list of options\r
326          * @return Set<Score> the conservation scores\r
327          * @throws IOException\r
328          * @throws UnknownFileFormatException\r
329          */\r
330         static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
331                         Preset<T> preset, List<Option<T>> customOptions) {\r
332                 List<FastaSequence> fastalist = null;\r
333                 try {\r
334                         fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
335                         assert !fastalist.isEmpty() : "Input is empty!";\r
336                 } catch (IOException e) {\r
337                         System.err\r
338                                         .println("Exception while reading the input file. "\r
339                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
340                                                         + "Exception details are below:");\r
341                         e.printStackTrace();\r
342                 } catch (UnknownFileFormatException e) {\r
343                         System.err\r
344                                         .println("Exception while attempting to read the input file "\r
345                                                         + "Exception details are below:");\r
346                         System.out.println(e.getMessage());\r
347                         e.printStackTrace();\r
348                 }\r
349                 return analize(fastalist, wsproxy, preset, customOptions);\r
350         }\r
351         /**\r
352          * Connects to a web service by the host and the service name web service\r
353          * type\r
354          * \r
355          * @param host\r
356          *            the fully qualified name of JABAWS server including JABAWS\r
357          *            context name e.g\r
358          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
359          * @param service\r
360          *            the name of the JABAWS service to connect to\r
361          * @return JABAService<T>\r
362          * @throws WebServiceException\r
363          * @throws ConnectException\r
364          *             if fails to connect to the service on the host\r
365          */\r
366         public static JABAService connect(String host, Services service)\r
367                         throws WebServiceException, ConnectException {\r
368                 URL url = null;\r
369                 log.log(Level.FINE, "Attempting to connect...");\r
370                 try {\r
371                         url = new URL(host + "/" + service.toString() + "?wsdl");\r
372                 } catch (MalformedURLException e) {\r
373                         e.printStackTrace();\r
374                         // ignore as the host name is already verified\r
375                 }\r
376                 Service serv = null;\r
377                 try {\r
378                         serv = service.getService(url, JABAService.SERVICE_NAMESPACE);\r
379                 } catch (WebServiceException wse) {\r
380                         System.out.println("Connecting to JABAWS version 2 service");\r
381                         if (isV2service(wse)) {\r
382                                 serv = service\r
383                                                 .getService(url, JABAService.V2_SERVICE_NAMESPACE);\r
384                         }\r
385                 }\r
386                 if (serv == null) {\r
387                         throw new ConnectException("Could not connect to " + url\r
388                                         + " the server is down?");\r
389                 }\r
390                 JABAService serviceIF = service.getInterface(serv);\r
391                 log.log(Level.INFO, "Connected successfully!");\r
392 \r
393                 return serviceIF;\r
394         }\r
395 \r
396         static boolean isV2service(WebServiceException wse) {\r
397                 String message = wse.getMessage();\r
398                 int idx = message.indexOf("not a valid service");\r
399                 if (idx > 0) {\r
400                         if (message.substring(idx).contains(\r
401                                         JABAService.V2_SERVICE_NAMESPACE)) {\r
402                                 return true;\r
403                         }\r
404                 }\r
405                 return false;\r
406         }\r
407 \r
408         /**\r
409          * Get a connection of JABAWS registry\r
410          * \r
411          * @param host\r
412          *            the fully qualified name of JABAWS server including JABAWS\r
413          *            context name e.g\r
414          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
415          * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
416          *         service\r
417          * @throws WebServiceException\r
418          * @throws ConnectException\r
419          */\r
420         public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
421                         throws WebServiceException, ConnectException {\r
422                 URL url = null;\r
423                 String service = "RegistryWS";\r
424                 log.log(Level.FINE, "Attempting to connect...");\r
425 \r
426                 try {\r
427                         url = new URL(host + "/" + service + "?wsdl");\r
428                 } catch (MalformedURLException e) {\r
429                         e.printStackTrace();\r
430                         // ignore as the host name is already verified\r
431                 }\r
432                 QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
433                 Service serv = Service.create(url, qname);\r
434 \r
435                 if (serv == null) {\r
436                         throw new ConnectException("Could not connect to " + url\r
437                                         + " the server is down?");\r
438                 }\r
439 \r
440                 QName portName = new QName(serv.getServiceName().getNamespaceURI(),\r
441                                 service + "Port");\r
442                 compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName,\r
443                                 compbio.data.msa.RegistryWS.class);\r
444 \r
445                 log.log(Level.INFO, "Connected to " + service + " successfully!");\r
446 \r
447                 return serviceIF;\r
448         }\r
449 \r
450         /**\r
451          * Align sequences from the file using MsaWS\r
452          * \r
453          * @param <T>\r
454          *            web service type e.g. Clustal\r
455          * @param file\r
456          *            to write the resulting alignment to\r
457          * @param msaws\r
458          *            MsaWS required\r
459          * @param preset\r
460          *            Preset to use optional\r
461          * @param customOptions\r
462          *            file which contains new line separated list of options\r
463          * @return Alignment\r
464          */\r
465         static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
466                         List<Option<T>> customOptions) {\r
467                 FileInputStream instream = null;\r
468                 List<FastaSequence> fastalist = null;\r
469                 Alignment alignment = null;\r
470                 try {\r
471                         instream = new FileInputStream(file);\r
472                         fastalist = SequenceUtil.readFasta(instream);\r
473                         instream.close();\r
474                         String jobId = null;\r
475                         if (customOptions != null && preset != null) {\r
476                                 System.out\r
477                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
478                         }\r
479                         if (customOptions != null) {\r
480                                 jobId = msaws.customAlign(fastalist, customOptions);\r
481                         } else if (preset != null) {\r
482                                 jobId = msaws.presetAlign(fastalist, preset);\r
483                         } else {\r
484                                 jobId = msaws.align(fastalist);\r
485                         }\r
486                         System.out.println("\n\ncalling align.........");\r
487                         Thread.sleep(1000);\r
488                         alignment = msaws.getResult(jobId);\r
489 \r
490                 } catch (IOException e) {\r
491                         System.err\r
492                                         .println("Exception while reading the input file. "\r
493                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
494                                                         + "Exception details are below:");\r
495                         e.printStackTrace();\r
496                 } catch (JobSubmissionException e) {\r
497                         System.err\r
498                                         .println("Exception while submitting job to a web server. "\r
499                                                         + "Exception details are below:");\r
500                         e.printStackTrace();\r
501                 } catch (ResultNotAvailableException e) {\r
502                         System.err.println("Exception while waiting for results. "\r
503                                         + "Exception details are below:");\r
504                         e.printStackTrace();\r
505                 } catch (InterruptedException ignored) {\r
506                         // ignore and propagate an interruption\r
507                         Thread.currentThread().interrupt();\r
508                 } catch (WrongParameterException e) {\r
509                         e.printStackTrace();\r
510                 } finally {\r
511                         if (instream != null) {\r
512                                 try {\r
513                                         instream.close();\r
514                                 } catch (IOException ignored) {\r
515                                         // ignore\r
516                                 }\r
517                         }\r
518                 }\r
519                 return alignment;\r
520         }\r
521         \r
522         /**\r
523          * Return RNA secondary structure from a file using FoldWS\r
524          * \r
525          * @param <T>\r
526          *            web service type e.g. Clustal\r
527          * @param file\r
528          *            to read the results from\r
529          * @param foldws\r
530          *            FoldWS required\r
531          * @param preset\r
532          *            Preset to use optional\r
533          * @param customOptions\r
534          *            file which contains new line separated list of options\r
535          * @return RNAstruct\r
536          */\r
537         \r
538         static <T> RNAstruct fold(File file, FoldWS<T> foldws, Preset<T> preset,\r
539                         List<Option<T>> customOptions) {\r
540                 FileInputStream instream = null;\r
541                 Alignment alignment = null;\r
542                 RNAstruct rnastruct = null;\r
543                 try {\r
544                         instream = new FileInputStream(file);\r
545                         alignment = ClustalAlignmentUtil.readClustalFile(instream);\r
546                         instream.close();\r
547                         String jobId = null;\r
548                         if (customOptions != null && preset != null) {\r
549                                 System.out.println("WARN: Parameters (-f) are defined together"\r
550                                                 + "with a preset (-r), ignoring preset! ");\r
551                         }\r
552                         if (customOptions != null) {\r
553                                 jobId = foldws.customFold(alignment, customOptions);\r
554                         } else if (preset != null) {\r
555                                 jobId = foldws.presetFold(alignment, preset);\r
556                         } else {\r
557                                 jobId = foldws.fold(alignment);\r
558                         }\r
559                         System.out.println("\n\ncalling fold.........");\r
560                         Thread.sleep(1000);\r
561                         rnastruct = foldws.getResult(jobId);\r
562                         log.info("log test print results:\n" + rnastruct.toString());\r
563                         System.out.println("print test results:\n " + rnastruct.toString());\r
564                                 \r
565                 } catch (IOException e) {\r
566                         System.err.println("Exception while reading the input file. Exception details: ");\r
567                         e.printStackTrace();\r
568                 } catch (UnknownFileFormatException e) {\r
569                         System.err.println("Exception while reading input file. Doesnt look like a Clustal format file");\r
570                         e.printStackTrace();\r
571                 } catch (JobSubmissionException e) {\r
572                         System.err.println("Exception while submitting job to the web server. ");\r
573                         e.printStackTrace();\r
574                 } catch (ResultNotAvailableException e) {\r
575                         System.err.println("Exception while waiting for results. Exception details: ");\r
576                         e.printStackTrace();\r
577                 } catch (InterruptedException ignored) {\r
578                         // ignore and propagate an interruption\r
579                         Thread.currentThread().interrupt();\r
580                 } catch (WrongParameterException e) {\r
581                         e.printStackTrace();\r
582                 } finally {\r
583                         if (instream != null) {\r
584                                 try {\r
585                                         instream.close();\r
586                                 } catch (IOException ignored) {\r
587                                         // ignore\r
588                                 }\r
589                         }\r
590                 }\r
591                 return rnastruct;\r
592         }\r
593                 \r
594         /**\r
595          * Prints Jws2Client usage information to standard out\r
596          * \r
597          * @param exitStatus\r
598          */\r
599         static void printUsage(int exitStatus) {\r
600                 System.out.println(Constraints.help_text);\r
601                 System.exit(exitStatus);\r
602         }\r
603 \r
604         /**\r
605          * Starts command line client, if no parameter are supported print help. Two\r
606          * parameters are required for successful call the JWS2 host name and a\r
607          * service name.\r
608          * \r
609          * @param args\r
610          *            Usage: <Class or Jar file name> -h=host_and_context\r
611          *            -s=serviceName ACTION [OPTIONS]\r
612          * \r
613          *            -h=<host_and_context> - a full URL to the JWS2 web server\r
614          *            including context path e.g. http://10.31.1.159:8080/ws\r
615          * \r
616          *            -s=<ServiceName> - one of [MafftWS, MuscleWS, ClustalWS,\r
617          *            TcoffeeWS, ProbconsWS] ACTIONS:\r
618          * \r
619          *            -i=<inputFile> - full path to fasta formatted sequence file,\r
620          *            from which to align sequences\r
621          * \r
622          *            -parameters - lists parameters supported by web service\r
623          * \r
624          *            -presets - lists presets supported by web service\r
625          * \r
626          *            -limits - lists web services limits Please note that if input\r
627          *            file is specified other actions are ignored\r
628          * \r
629          *            OPTIONS: (only for use with -i action):\r
630          * \r
631          *            -r=<presetName> - name of the preset to use\r
632          * \r
633          *            -o=<outputFile> - full path to the file where to write an\r
634          *            alignment -f=<parameterInputFile> - the name of the file with\r
635          *            the list of parameters to use. Please note that -r and -f\r
636          *            options cannot be used together. Alignment is done with either\r
637          *            preset or a parameters from the file, but not both!\r
638          * \r
639          */\r
640         public static void main(String[] args) {\r
641 \r
642                 if (args == null) {\r
643                         printUsage(1);\r
644                 }\r
645                 if (args.length < 2) {\r
646                         System.err.println("Host and service names are required!");\r
647                         printUsage(1);\r
648                 }\r
649 \r
650                 try {\r
651                         new Jws2Client(args);\r
652                 } catch (IOException e) {\r
653                         log.log(Level.SEVERE, "IOException in client! " + e.getMessage(),\r
654                                         e.getCause());\r
655                         System.err.println("Cannot write output file! Stack trace: ");\r
656                         e.printStackTrace();\r
657                 }\r
658         }\r
659 }\r