- return alignment;\r
- }\r
-\r
- /**\r
- * Returns a list of options supported by web service\r
- * \r
- * @param <T>\r
- * web service type\r
- * @param msaws\r
- * web service proxy\r
- * @return List of options supported by a web service\r
- */\r
- <T> List<Option<T>> getParametersList(MsaWS<T> msaws) {\r
- assert msaws != null;\r
- return msaws.getRunnerOptions().getArguments();\r
- }\r
-\r
- /**\r
- * Returns an objects from which the list of presets supported by web\r
- * service <T> can be obtained\r
- * \r
- * @param <T>\r
- * web service type\r
- * @param msaws\r
- * web service proxy\r
- * @return PresetManager, object which operates on presets\r
- */\r
- <T> PresetManager<T> getPresetList(MsaWS<T> msaws) {\r
- assert msaws != null;\r
- PresetManager<T> presetman = msaws.getPresets();\r
- return presetman;\r
- }\r
-\r
- /**\r
- * Returns a list of limits supported by web service Each limit correspond\r
- * to a particular preset.\r
- * \r
- * @param <T>\r
- * web service type\r
- * @param msaws\r
- * web service proxy\r
- * @return List of limits supported by a web service\r
- */\r
- <T> List<Limit<T>> getLimits(MsaWS<T> msaws) {\r
- assert msaws != null;\r
- LimitsManager<T> lmanger = msaws.getLimits();\r
-\r
- return lmanger != null ? lmanger.getLimits() : null;\r
- }\r
-\r
- /**\r
- * Prints Jws2Client usage information to standard out\r
- * \r
- * @param exitStatus\r
- */\r
- static void printUsage(int exitStatus) {\r
- System.out.println();\r
- System.out.println("Usage: <Class or Jar file name> " + hostkey\r
- + pseparator + "host_and_context " + servicekey + pseparator\r
- + "serviceName ACTION [OPTIONS] ");\r
- System.out.println();\r
- System.out\r
- .println(hostkey\r
- + pseparator\r
- + "<host_and_context> - a full URL to the JWS2 web server including context path e.g. http://10.31.1.159:8080/ws");\r
- System.out.println(servicekey + pseparator + "<ServiceName> - one of "\r
- + Arrays.toString(Services.values()));\r
- System.out.println();\r
- System.out.println("ACTIONS: ");\r
- System.out\r
- .println(inputkey\r
- + pseparator\r
- + "<inputFile> - full path to fasta formatted sequence file, from which to align sequences");\r
- System.out.println(paramList\r
- + " - lists parameters supported by web service");\r
- System.out.println(presetList\r
- + " - lists presets supported by web service");\r
- System.out.println(limitList + " - lists web services limits");\r
- System.out\r
- .println("Please note that if input file is specified other actions are ignored");\r
-\r
- System.out.println();\r
- System.out.println("OPTIONS (only for use with -i action):");\r
-\r
- System.out.println(presetkey + pseparator\r
- + "<presetName> - name of the preset to use");\r
- System.out\r
- .println(outputkey\r
- + pseparator\r
- + "<outputFile> - full path to the file where to write an alignment");\r
- System.out\r
- .println("-f=<parameterInputFile> - the name of the file with the list of parameters to use.");\r
- System.out\r
- .println("Please note that -r and -f options cannot be used together. "\r
- + "Alignment is done with either preset or a parameters from the file, but not both!");\r
-\r
- System.exit(exitStatus);\r
- }\r
-\r
- /**\r
- * Starts command line client, if no parameter are supported print help. Two\r
- * parameters are required for successfull call the JWS2 host name and a\r
- * service name.\r
- * \r
- * @param args\r
- * Usage: <Class or Jar file name> -h=host_and_context\r
- * -s=serviceName ACTION [OPTIONS]\r
- * \r
- * -h=<host_and_context> - a full URL to the JWS2 web server\r
- * including context path e.g. http://10.31.1.159:8080/ws\r
- * \r
- * -s=<ServiceName> - one of [MafftWS, MuscleWS, ClustalWS,\r
- * TcoffeeWS, ProbconsWS] ACTIONS:\r
- * \r
- * -i=<inputFile> - full path to fasta formatted sequence file,\r
- * from which to align sequences\r
- * \r
- * -parameters - lists parameters supported by web service\r
- * \r
- * -presets - lists presets supported by web service\r
- * \r
- * -limits - lists web services limits Please note that if input\r
- * file is specified other actions are ignored\r
- * \r
- * OPTIONS: (only for use with -i action):\r
- * \r
- * -r=<presetName> - name of the preset to use\r
- * \r
- * -o=<outputFile> - full path to the file where to write an\r
- * alignment -f=<parameterInputFile> - the name of the file with\r
- * the list of parameters to use. Please note that -r and -f\r
- * options cannot be used together. Alignment is done with either\r
- * preset or a parameters from the file, but not both!\r
- * \r
- */\r
- public static void main(String[] args) {\r
-\r
- if (args == null) {\r
- printUsage(1);\r
+\r
+ /**\r
+ * Align sequences from the file using MsaWS\r
+ * \r
+ * @param <T>\r
+ * web service type e.g. Clustal\r
+ * @param file\r
+ * to write the resulting alignment to\r
+ * @param msaws\r
+ * MsaWS required\r
+ * @param preset\r
+ * Preset to use optional\r
+ * @param customOptions\r
+ * file which contains new line separated list of options\r
+ * @return Alignment\r
+ */\r
+ static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
+ List<Option<T>> customOptions) {\r
+ FileInputStream instream = null;\r
+ List<FastaSequence> fastalist = null;\r
+ Alignment alignment = null;\r
+ try {\r
+ instream = new FileInputStream(file);\r
+ fastalist = SequenceUtil.readFasta(instream);\r
+ instream.close();\r
+ String jobId = null;\r
+ if (customOptions != null && preset != null) {\r
+ System.out\r
+ .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
+ }\r
+ if (customOptions != null) {\r
+ jobId = msaws.customAlign(fastalist, customOptions);\r
+ } else if (preset != null) {\r
+ jobId = msaws.presetAlign(fastalist, preset);\r
+ } else {\r
+ jobId = msaws.align(fastalist);\r
+ }\r
+ System.out.println("\n\ncalling align.........");\r
+ Thread.sleep(1000);\r
+ alignment = msaws.getResult(jobId);\r
+\r
+ } catch (IOException e) {\r
+ System.err\r
+ .println("Exception while reading the input file. "\r
+ + "Check that the input file contains a list of fasta formatted sequences! "\r
+ + "Exception details are below:");\r
+ e.printStackTrace();\r
+ } catch (JobSubmissionException e) {\r
+ System.err\r
+ .println("Exception while submitting job to a web server. "\r
+ + "Exception details are below:");\r
+ e.printStackTrace();\r
+ } catch (ResultNotAvailableException e) {\r
+ System.err.println("Exception while waiting for results. "\r
+ + "Exception details are below:");\r
+ e.printStackTrace();\r
+ } catch (InterruptedException ignored) {\r
+ // ignore and propagate an interruption\r
+ Thread.currentThread().interrupt();\r
+ } catch (WrongParameterException e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ if (instream != null) {\r
+ try {\r
+ instream.close();\r
+ } catch (IOException ignored) {\r
+ // ignore\r
+ }\r
+ }\r
+ }\r
+ return alignment;\r