Webservice which implements FoldWS and returns String. Parameters.xml file
[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 //              System.out.println("The Options read from the command line: " + customOptions);\r
165                 \r
166                 Alignment alignment = null;\r
167                 String rnastruct = null;\r
168                 if (inputFile != null) {\r
169                         Writer writer = null;\r
170                         if (outFile != null) {\r
171                                 writer = IOHelper.getWriter(outFile);\r
172                         } else {\r
173                                 // this stream is going to be closed later which is fine as\r
174                                 // std.out will not be\r
175                                 writer = new PrintWriter(System.out, true);\r
176                         }\r
177                         if (service.getServiceType() == SequenceAnnotation.class) {\r
178                                 ScoreManager result = analize(inputFile,\r
179                                                 ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
180 \r
181                                 IOHelper.writeOut(writer, result);\r
182                         } else if (service.getServiceType() == MsaWS.class) {\r
183                                 alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
184                                                 customOptions);\r
185                                 IOHelper.writeOut(writer, alignment);\r
186                         } else if (service.getServiceType() == FoldWS.class) {\r
187                                 rnastruct = fold(inputFile, (FoldWS<T>) foldws, preset, customOptions);\r
188                                 // No IOHelper method for rnastruct/String yet\r
189                                 if (writer != null) {\r
190                                         writer.write(rnastruct);\r
191                                 }\r
192                         }\r
193                         writer.close();\r
194                 }\r
195 \r
196                 boolean listParameters = CmdHelper.listParameters(cmd);\r
197                 if (listParameters) {\r
198                         System.out.println(MetadataHelper.getParametersList(msaws));\r
199                 }\r
200                 boolean listPreset = CmdHelper.listPresets(cmd);\r
201                 if (listPreset) {\r
202                         System.out.println(MetadataHelper.getPresetList(msaws));\r
203                 }\r
204                 boolean listLimits = CmdHelper.listLimits(cmd);\r
205                 if (listLimits) {\r
206                         System.out.println(MetadataHelper.getLimits(msaws));\r
207                 }\r
208                 log.fine("Disconnecting...");\r
209                 ((Closeable) msaws).close();\r
210                 log.fine("Disconnected successfully!");\r
211         }\r
212 \r
213         /**\r
214          * Asks registry to test the service on the host hostname\r
215          * \r
216          * @param hostname\r
217          * @param service\r
218          * @param writer\r
219          * @throws ConnectException\r
220          * @throws WebServiceException\r
221          */\r
222         public static void testService(String hostname, Services service,\r
223                         PrintWriter writer) throws ConnectException, WebServiceException {\r
224                 RegistryWS registry = connectToRegistry(hostname);\r
225                 if (registry != null) {\r
226                         String message = registry.testService(service);\r
227                         writer.println("Service " + service + " testing results: ");\r
228                         writer.println(message);\r
229                         FileUtil.closeSilently(((Closeable) registry));\r
230                 }\r
231                 writer.flush();\r
232         }\r
233 \r
234         public static Set<Services> getServices(String hostname)\r
235                         throws WebServiceException, ConnectException {\r
236                 RegistryWS registry = connectToRegistry(hostname);\r
237                 Set<Services> services = Collections.EMPTY_SET;\r
238                 if (registry != null) {\r
239                         services = registry.getSupportedServices();\r
240                         FileUtil.closeSilently(((Closeable) registry));\r
241                 }\r
242                 return services;\r
243         }\r
244 \r
245         private static void listServices(String hostname)\r
246                         throws WebServiceException, IOException {\r
247                 Set<Services> services = Jws2Client.getServices(hostname);\r
248                 if (!services.isEmpty()) {\r
249                         System.out.println("Supported services are: "\r
250                                         + Services.toString(services));\r
251                 } else {\r
252                         System.out.println("Failed to connect to the registry! ");\r
253                 }\r
254         }\r
255 \r
256         /**\r
257          * Calculate conservation for sequences loaded from the file\r
258          * \r
259          * @param wsproxy\r
260          *            a web service proxy\r
261          * @param file\r
262          *            the file to read the results from\r
263          * @param preset\r
264          *            Preset to use optional\r
265          * @param customOptions\r
266          *            the list of options\r
267          * @return Set<Score> the conservation scores\r
268          * @throws UnknownFileFormatException\r
269          */\r
270         static <T> ScoreManager analize(List<FastaSequence> fastalist,\r
271                         SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
272                         List<Option<T>> customOptions) {\r
273 \r
274                 ScoreManager scores = null;\r
275                 try {\r
276                         String jobId = null;\r
277                         if (customOptions != null && preset != null) {\r
278                                 System.out\r
279                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
280                         }\r
281                         if (customOptions != null) {\r
282                                 jobId = wsproxy.customAnalize(fastalist, customOptions);\r
283                         } else if (preset != null) {\r
284                                 jobId = wsproxy.presetAnalize(fastalist, preset);\r
285                         } else {\r
286                                 jobId = wsproxy.analize(fastalist);\r
287                         }\r
288                         System.out.println("\n\ncalling analise.........");\r
289                         Thread.sleep(1000);\r
290                         scores = wsproxy.getAnnotation(jobId);\r
291 \r
292                 } catch (JobSubmissionException e) {\r
293                         System.err\r
294                                         .println("Exception while submitting job to a web server. "\r
295                                                         + "Exception details are below:");\r
296                         e.printStackTrace();\r
297                 } catch (ResultNotAvailableException e) {\r
298                         System.err.println("Exception while waiting for results. "\r
299                                         + "Exception details are below:");\r
300                         e.printStackTrace();\r
301                 } catch (InterruptedException e) {\r
302                         // ignore and propagate an interruption\r
303                         Thread.currentThread().interrupt();\r
304                         System.err.println("Exception while waiting for results. "\r
305                                         + "Exception details are below:");\r
306                         e.printStackTrace();\r
307                 } catch (WrongParameterException e) {\r
308                         System.err\r
309                                         .println("Exception while parsing the web method input parameters. "\r
310                                                         + "Exception details are below:");\r
311                         e.printStackTrace();\r
312                 }\r
313                 return scores;\r
314 \r
315         }\r
316 \r
317         /**\r
318          * Calculate conservation for sequences loaded from the file\r
319          * \r
320          * @param wsproxy\r
321          *            a web service proxy\r
322          * @param file\r
323          *            the file to read the results from\r
324          * @param preset\r
325          *            Preset to use optional\r
326          * @param customOptions\r
327          *            the list of options\r
328          * @return Set<Score> the conservation scores\r
329          * @throws IOException\r
330          * @throws UnknownFileFormatException\r
331          */\r
332         static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
333                         Preset<T> preset, List<Option<T>> customOptions) {\r
334                 List<FastaSequence> fastalist = null;\r
335                 try {\r
336                         fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
337                         assert !fastalist.isEmpty() : "Input is empty!";\r
338                 } catch (IOException e) {\r
339                         System.err\r
340                                         .println("Exception while reading the input file. "\r
341                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
342                                                         + "Exception details are below:");\r
343                         e.printStackTrace();\r
344                 } catch (UnknownFileFormatException e) {\r
345                         System.err\r
346                                         .println("Exception while attempting to read the input file "\r
347                                                         + "Exception details are below:");\r
348                         System.out.println(e.getMessage());\r
349                         e.printStackTrace();\r
350                 }\r
351                 return analize(fastalist, wsproxy, preset, customOptions);\r
352         }\r
353         /**\r
354          * Connects to a web service by the host and the service name web service\r
355          * type\r
356          * \r
357          * @param host\r
358          *            the fully qualified name of JABAWS server including JABAWS\r
359          *            context name e.g\r
360          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
361          * @param service\r
362          *            the name of the JABAWS service to connect to\r
363          * @return JABAService<T>\r
364          * @throws WebServiceException\r
365          * @throws ConnectException\r
366          *             if fails to connect to the service on the host\r
367          */\r
368         public static JABAService connect(String host, Services service)\r
369                         throws WebServiceException, ConnectException {\r
370                 URL url = null;\r
371                 log.log(Level.FINE, "Attempting to connect...");\r
372                 try {\r
373                         url = new URL(host + "/" + service.toString() + "?wsdl");\r
374                 } catch (MalformedURLException e) {\r
375                         e.printStackTrace();\r
376                         // ignore as the host name is already verified\r
377                 }\r
378                 Service serv = null;\r
379                 try {\r
380                         serv = service.getService(url, JABAService.SERVICE_NAMESPACE);\r
381                 } catch (WebServiceException wse) {\r
382                         System.out.println("Connecting to JABAWS version 2 service");\r
383                         if (isV2service(wse)) {\r
384                                 serv = service\r
385                                                 .getService(url, JABAService.V2_SERVICE_NAMESPACE);\r
386                         }\r
387                 }\r
388                 if (serv == null) {\r
389                         throw new ConnectException("Could not connect to " + url\r
390                                         + " the server is down?");\r
391                 }\r
392                 JABAService serviceIF = service.getInterface(serv);\r
393                 log.log(Level.INFO, "Connected successfully!");\r
394 \r
395                 return serviceIF;\r
396         }\r
397 \r
398         static boolean isV2service(WebServiceException wse) {\r
399                 String message = wse.getMessage();\r
400                 int idx = message.indexOf("not a valid service");\r
401                 if (idx > 0) {\r
402                         if (message.substring(idx).contains(\r
403                                         JABAService.V2_SERVICE_NAMESPACE)) {\r
404                                 return true;\r
405                         }\r
406                 }\r
407                 return false;\r
408         }\r
409 \r
410         /**\r
411          * Get a connection of JABAWS registry\r
412          * \r
413          * @param host\r
414          *            the fully qualified name of JABAWS server including JABAWS\r
415          *            context name e.g\r
416          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
417          * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
418          *         service\r
419          * @throws WebServiceException\r
420          * @throws ConnectException\r
421          */\r
422         public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
423                         throws WebServiceException, ConnectException {\r
424                 URL url = null;\r
425                 String service = "RegistryWS";\r
426                 log.log(Level.FINE, "Attempting to connect...");\r
427 \r
428                 try {\r
429                         url = new URL(host + "/" + service + "?wsdl");\r
430                 } catch (MalformedURLException e) {\r
431                         e.printStackTrace();\r
432                         // ignore as the host name is already verified\r
433                 }\r
434                 QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
435                 Service serv = Service.create(url, qname);\r
436 \r
437                 if (serv == null) {\r
438                         throw new ConnectException("Could not connect to " + url\r
439                                         + " the server is down?");\r
440                 }\r
441 \r
442                 QName portName = new QName(serv.getServiceName().getNamespaceURI(),\r
443                                 service + "Port");\r
444                 compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName,\r
445                                 compbio.data.msa.RegistryWS.class);\r
446 \r
447                 log.log(Level.INFO, "Connected to " + service + " successfully!");\r
448 \r
449                 return serviceIF;\r
450         }\r
451 \r
452         /**\r
453          * Align sequences from the file using MsaWS\r
454          * \r
455          * @param <T>\r
456          *            web service type e.g. Clustal\r
457          * @param file\r
458          *            to write the resulting alignment to\r
459          * @param msaws\r
460          *            MsaWS required\r
461          * @param preset\r
462          *            Preset to use optional\r
463          * @param customOptions\r
464          *            file which contains new line separated list of options\r
465          * @return Alignment\r
466          */\r
467         static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
468                         List<Option<T>> customOptions) {\r
469                 FileInputStream instream = null;\r
470                 List<FastaSequence> fastalist = null;\r
471                 Alignment alignment = null;\r
472                 try {\r
473                         instream = new FileInputStream(file);\r
474                         fastalist = SequenceUtil.readFasta(instream);\r
475                         instream.close();\r
476                         String jobId = null;\r
477                         if (customOptions != null && preset != null) {\r
478                                 System.out\r
479                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
480                         }\r
481                         if (customOptions != null) {\r
482                                 jobId = msaws.customAlign(fastalist, customOptions);\r
483                         } else if (preset != null) {\r
484                                 jobId = msaws.presetAlign(fastalist, preset);\r
485                         } else {\r
486                                 jobId = msaws.align(fastalist);\r
487                         }\r
488                         System.out.println("\n\ncalling align.........");\r
489                         Thread.sleep(1000);\r
490                         alignment = msaws.getResult(jobId);\r
491 \r
492                 } catch (IOException e) {\r
493                         System.err\r
494                                         .println("Exception while reading the input file. "\r
495                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
496                                                         + "Exception details are below:");\r
497                         e.printStackTrace();\r
498                 } catch (JobSubmissionException e) {\r
499                         System.err\r
500                                         .println("Exception while submitting job to a web server. "\r
501                                                         + "Exception details are below:");\r
502                         e.printStackTrace();\r
503                 } catch (ResultNotAvailableException e) {\r
504                         System.err.println("Exception while waiting for results. "\r
505                                         + "Exception details are below:");\r
506                         e.printStackTrace();\r
507                 } catch (InterruptedException ignored) {\r
508                         // ignore and propagate an interruption\r
509                         Thread.currentThread().interrupt();\r
510                 } catch (WrongParameterException e) {\r
511                         e.printStackTrace();\r
512                 } finally {\r
513                         if (instream != null) {\r
514                                 try {\r
515                                         instream.close();\r
516                                 } catch (IOException ignored) {\r
517                                         // ignore\r
518                                 }\r
519                         }\r
520                 }\r
521                 return alignment;\r
522         }\r
523         \r
524         /**\r
525          * Return RNA secondary structure from a file using FoldWS\r
526          * \r
527          * @param <T>\r
528          *            web service type e.g. Clustal\r
529          * @param file\r
530          *            to read the results from\r
531          * @param foldws\r
532          *            FoldWS required\r
533          * @param preset\r
534          *            Preset to use optional\r
535          * @param customOptions\r
536          *            file which contains new line separated list of options\r
537          * @return String\r
538          */\r
539         \r
540         static <T> String fold(File file, FoldWS<T> foldws, Preset<T> preset,\r
541                         List<Option<T>> customOptions) {\r
542                 FileInputStream instream = null;\r
543                 Alignment alignment = null;\r
544                 String rnastruct = null;\r
545                 try {\r
546                         instream = new FileInputStream(file);\r
547                         alignment = ClustalAlignmentUtil.readClustalFile(instream);\r
548                         instream.close();\r
549                         String jobId = null;\r
550                         if (customOptions != null && preset != null) {\r
551                                 System.out.println("WARN: Parameters (-f) are defined together"\r
552                                                 + "with a preset (-r), ignoring preset! ");\r
553                         }\r
554                         if (customOptions != null) {\r
555                                 jobId = foldws.customFold(alignment, customOptions);\r
556                         } else if (preset != null) {\r
557                                 jobId = foldws.presetFold(alignment, preset);\r
558                         } else {\r
559                                 jobId = foldws.fold(alignment);\r
560                         }\r
561                         System.out.println("\n\ncalling fold.........");\r
562                         Thread.sleep(1000);\r
563                         rnastruct = foldws.getResult(jobId);\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