import java.io.Closeable;\r
import java.io.File;\r
import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
import java.io.IOException;\r
import java.io.PrintWriter;\r
import java.io.Writer;\r
import javax.xml.ws.WebServiceException;\r
\r
import compbio.data.msa.JABAService;\r
-import compbio.data.msa.FoldWS;\r
import compbio.data.msa.Metadata;\r
import compbio.data.msa.MsaWS;\r
import compbio.data.msa.RegistryWS;\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.AlignmentMetadata;\r
+import compbio.data.sequence.JpredAlignment;\r
import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.RNAStruct;\r
import compbio.data.sequence.ScoreManager;\r
-import compbio.data.sequence.ClustalAlignmentUtil;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.JobStatus;\r
import compbio.metadata.Option;\r
+import compbio.metadata.Limit;\r
import compbio.metadata.Preset;\r
+import compbio.metadata.PresetManager;\r
import compbio.metadata.ResultNotAvailableException;\r
import compbio.metadata.WrongParameterException;\r
import compbio.util.FileUtil;\r
*/\r
public class Jws2Client {\r
\r
- /*\r
- * Use java.util.Logger instead of log4j logger to reduce the size of the\r
- * client package\r
+ /**\r
+ * Use java.util.Logger instead of log4j logger to reduce the size of the client package\r
*/\r
- private static final Logger log = Logger.getLogger(Jws2Client.class\r
- .getCanonicalName());\r
+ private static final Logger log = Logger.getLogger(Jws2Client.class.getCanonicalName());\r
\r
/**\r
* Attempt to construct the URL object from the string\r
* command line options\r
* @throws IOException\r
*/\r
+ @SuppressWarnings("unchecked")\r
<T> Jws2Client(String[] cmd) throws IOException {\r
\r
\r
String hostname = CmdHelper.getHost(cmd);\r
if (hostname == null) {\r
System.err.println("Host name is not provided!");\r
- printUsage(1);\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
\r
if (!validURL(hostname)) {\r
System.err.println("Host name is not valid!");\r
- printUsage(1);\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
- // Just list available services and quit\r
+\r
boolean listServices = CmdHelper.listServices(cmd);\r
if (listServices) {\r
- listServices(hostname);\r
+ listAllServices(hostname);\r
System.exit(0);\r
}\r
\r
String serviceName = CmdHelper.getServiceName(cmd);\r
if (serviceName == null) {\r
System.err.println("Service name is no provided!");\r
- printUsage(1);\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
+\r
Services service = Services.getService(serviceName);\r
if (service == null) {\r
- System.err.println("Service " + serviceName\r
- + " is no recognized! Valid values are: "\r
- + Arrays.toString(Services.values()));\r
- printUsage(1);\r
+ String mess = "Service " + serviceName + " is no available! Valid values are: ";\r
+ System.err.println(mess + Arrays.toString(Services.values()));\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
- // Test service and quit\r
- boolean testService = CmdHelper.testService(cmd);\r
- if (testService) {\r
+\r
+ if (CmdHelper.testService(cmd)) {\r
testService(hostname, service, new PrintWriter(System.out, true));\r
System.exit(0);\r
}\r
\r
- File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
- File outFile = IOHelper.getFile(cmd, outputkey, false);\r
- File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
- String presetName = CmdHelper.getPresetName(cmd);\r
-\r
- Metadata<T> msaws = (Metadata<T>) connect(hostname, service);\r
- Metadata<T> foldws = (Metadata<T>) connect(hostname, service);\r
+ Metadata<T> thews = (Metadata<T>) connect(hostname, service);\r
Preset<T> preset = null;\r
- if (presetName != null) {\r
- preset = MetadataHelper.getPreset(msaws, presetName);\r
+ if (null != CmdHelper.getPresetName(cmd)) {\r
+ preset = MetadataHelper.getPreset(thews, CmdHelper.getPresetName(cmd));\r
}\r
+\r
List<Option<T>> customOptions = null;\r
- if (parametersFile != null) {\r
- List<String> prms = IOHelper.loadParameters(parametersFile);\r
- customOptions = MetadataHelper.processParameters(prms,\r
- msaws.getRunnerOptions());\r
+ if (null != IOHelper.getFile(cmd, paramFile, true)) {\r
+ List<String> prms = IOHelper.loadParameters(IOHelper.getFile(cmd, paramFile, true));\r
+ customOptions = MetadataHelper.processParameters(prms, thews.getRunnerOptions());\r
}\r
-// System.out.println("The Options read from the command line: " + customOptions);\r
- \r
- Alignment alignment = null;\r
- String rnastruct = null;\r
- if (inputFile != null) {\r
+\r
+ if (null != IOHelper.getFile(cmd, inputkey, true)) {\r
+ File infile = IOHelper.getFile(cmd, inputkey, true);\r
+ File outfile = IOHelper.getFile(cmd, outputkey, false);\r
Writer writer = null;\r
- if (outFile != null) {\r
- writer = IOHelper.getWriter(outFile);\r
+ if (outfile != null) {\r
+ writer = IOHelper.getWriter(outfile);\r
} else {\r
- // this stream is going to be closed later which is fine as\r
- // std.out will not be\r
writer = new PrintWriter(System.out, true);\r
}\r
if (service.getServiceType() == SequenceAnnotation.class) {\r
- ScoreManager result = analize(inputFile,\r
- ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
-\r
+ ScoreManager result = analize(infile, ((SequenceAnnotation<T>) thews), preset, customOptions);\r
IOHelper.writeOut(writer, result);\r
+ writer.close();\r
} else if (service.getServiceType() == MsaWS.class) {\r
- alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
- customOptions);\r
- IOHelper.writeOut(writer, alignment);\r
- } else if (service.getServiceType() == FoldWS.class) {\r
- rnastruct = fold(inputFile, (FoldWS<T>) foldws, preset, customOptions);\r
- // No IOHelper method for rnastruct/String yet\r
- if (writer != null) {\r
- writer.write(rnastruct);\r
+ Alignment alignment = align(infile, (MsaWS<T>) thews, preset, customOptions);\r
+ if (serviceName.equalsIgnoreCase("JpredWS")) {\r
+ writer.close();\r
+ JpredAlignment jpred = (JpredAlignment)alignment;\r
+ if (outfile != null) {\r
+ FileOutputStream fout = new FileOutputStream(outfile);\r
+ SequenceUtil.writeFastaKeepTheStream(fout, jpred.getJpredSequences(), 60);\r
+ fout.close();\r
+ } else {\r
+ SequenceUtil.writeFasta(System.out, jpred.getJpredSequences());\r
+ }\r
+ } else {\r
+ IOHelper.writeOut(writer, alignment);\r
+ writer.close();\r
}\r
+ AlignmentMetadata md = alignment.getMetadata();\r
+ System.out.println("Output has been prepared with " + md.getProgram());\r
}\r
- writer.close();\r
}\r
\r
- boolean listParameters = CmdHelper.listParameters(cmd);\r
- if (listParameters) {\r
- System.out.println(MetadataHelper.getParametersList(msaws));\r
+ if (CmdHelper.listParameters(cmd)) {\r
+ List<Option<T>> opts = MetadataHelper.getParametersList(thews, hostname);\r
+ for (Option<T> o : opts) {\r
+ System.out.println("##############################################################################\n" + o.toString());\r
+ }\r
}\r
- boolean listPreset = CmdHelper.listPresets(cmd);\r
- if (listPreset) {\r
- System.out.println(MetadataHelper.getPresetList(msaws));\r
+ if (CmdHelper.listPresets(cmd)) {\r
+ PresetManager<T> psm = MetadataHelper.getPresetList(thews);\r
+ if (null != psm) {\r
+ System.out.print(psm);\r
+ } else {\r
+ System.out.println("No presets are defined for the Web service");\r
+ }\r
}\r
- boolean listLimits = CmdHelper.listLimits(cmd);\r
- if (listLimits) {\r
- System.out.println(MetadataHelper.getLimits(msaws));\r
+ if (CmdHelper.listLimits(cmd)) {\r
+ List<Limit<T>> lims = MetadataHelper.getLimits(thews);\r
+ for (Limit<T> l : lims) {\r
+ System.out.println("##############################################################################\n" + l.toString());\r
+ }\r
}\r
log.fine("Disconnecting...");\r
- ((Closeable) msaws).close();\r
+ ((Closeable) thews).close();\r
log.fine("Disconnected successfully!");\r
}\r
\r
/**\r
+ * Connects to a web service by the host and the service name web service type\r
+ * \r
+ * @param host\r
+ * the fully qualified name of JABAWS server including JABAWS\r
+ * context name e.g\r
+ * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
+ * @param service\r
+ * the name of the JABAWS service to connect to\r
+ * @return JABAService<T>\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ * if fails to connect to the service on the host\r
+ */\r
+ public static JABAService connect(String host, Services service)\r
+ throws WebServiceException, ConnectException {\r
+ URL url = null;\r
+ log.log(Level.FINE, "Attempting to connect with " + service.toString() + "...");\r
+ System.out.println ("Attempting to connect with " + service.toString() + "...");\r
+ try {\r
+ url = new URL(host + "/" + service.toString() + "?wsdl");\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ // ignore as the host name is already verified\r
+ }\r
+ Service serv = null;\r
+ try {\r
+ serv = service.getService(url, service.getServiceNamespace());\r
+ } catch (WebServiceException wse) {\r
+ wse.printStackTrace();\r
+ }\r
+ if (serv == null) {\r
+ throw new ConnectException("Could not connect to " + url + ". Is the server down?");\r
+ }\r
+ JABAService serviceIF = service.getInterface(serv);\r
+ log.log(Level.INFO, "Connected successfully!");\r
+\r
+ return serviceIF;\r
+ }\r
+\r
+ /**\r
+ * Get a connection of JABAWS registry\r
+ * \r
+ * @param host\r
+ * the fully qualified name of JABAWS server including JABAWS\r
+ * context name e.g\r
+ * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
+ * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
+ * service\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ */\r
+ public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
+ throws WebServiceException, ConnectException {\r
+ URL url = null;\r
+ String service = "RegistryWS";\r
+ log.log(Level.FINE, "Attempting to connect...");\r
+\r
+ try {\r
+ url = new URL(host + "/" + service + "?wsdl");\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ // ignore as the host name is already verified\r
+ }\r
+ QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
+ Service serv = Service.create(url, qname);\r
+\r
+ if (serv == null) {\r
+ throw new ConnectException("Could not connect to " + url + ". Is the server down?");\r
+ }\r
+\r
+ QName portName = new QName(serv.getServiceName().getNamespaceURI(), service + "Port");\r
+ compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName, compbio.data.msa.RegistryWS.class);\r
+ log.log(Level.INFO, "Connected to " + service + " successfully!");\r
+\r
+ return serviceIF;\r
+ }\r
+\r
+ /**\r
* Asks registry to test the service on the host hostname\r
* \r
* @param hostname\r
* @throws ConnectException\r
* @throws WebServiceException\r
*/\r
- public static void testService(String hostname, Services service,\r
- PrintWriter writer) throws ConnectException, WebServiceException {\r
+ public static void testService(String hostname, Services service, PrintWriter writer)\r
+ throws ConnectException, WebServiceException {\r
RegistryWS registry = connectToRegistry(hostname);\r
if (registry != null) {\r
String message = registry.testService(service);\r
writer.flush();\r
}\r
\r
- public static Set<Services> getServices(String hostname)\r
- throws WebServiceException, ConnectException {\r
+ private static void listAllServices(String hostname) throws WebServiceException, IOException {\r
RegistryWS registry = connectToRegistry(hostname);\r
- Set<Services> services = Collections.EMPTY_SET;\r
+ Set<Services> func_services = Collections.emptySet();\r
+ //Set<Services> nonfunc_services = Collections.emptySet();\r
if (registry != null) {\r
- services = registry.getSupportedServices();\r
+ func_services = registry.getSupportedServices();\r
+ //nonfunc_services = registry.getNonoperatedServices();\r
FileUtil.closeSilently(((Closeable) registry));\r
- }\r
- return services;\r
- }\r
-\r
- private static void listServices(String hostname)\r
- throws WebServiceException, IOException {\r
- Set<Services> services = Jws2Client.getServices(hostname);\r
- if (!services.isEmpty()) {\r
- System.out.println("Supported services are: "\r
- + Services.toString(services));\r
} else {\r
System.out.println("Failed to connect to the registry! ");\r
+ return;\r
}\r
+ if (!func_services.isEmpty()) {\r
+ System.out.println("There are " + func_services.size() + " services at " + hostname + ":");\r
+ String mess = "\n\rThe list:\n";\r
+ System.out.println(mess + Services.toString(func_services));\r
+ }\r
+ /*\r
+ if (!nonfunc_services.isEmpty()) {\r
+ System.out.println("There are " + nonfunc_services.size() + " non-available services at " + hostname + ":");\r
+ String mess = "The list (internal tests failed): ";\r
+ System.out.println(mess + Services.toString(nonfunc_services));\r
+ }\r
+ */\r
}\r
\r
/**\r
- * Calculate conservation for sequences loaded from the file\r
+ * Calculate conservation for sequences loaded from a FASTA record list structure \r
* \r
+ * @param fastalist\r
+ * the list of FASTA records\r
* @param wsproxy\r
* a web service proxy\r
- * @param file\r
- * the file to read the results from\r
* @param preset\r
* Preset to use optional\r
* @param customOptions\r
* @return Set<Score> the conservation scores\r
* @throws UnknownFileFormatException\r
*/\r
- static <T> ScoreManager analize(List<FastaSequence> fastalist,\r
- SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
- List<Option<T>> customOptions) {\r
-\r
+ static <T> ScoreManager analize(List<FastaSequence> fastalist, SequenceAnnotation<T> wsproxy, Preset<T> preset, List<Option<T>> customOptions) {\r
ScoreManager scores = null;\r
try {\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
+ System.out.println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
}\r
if (customOptions != null) {\r
jobId = wsproxy.customAnalize(fastalist, customOptions);\r
} else {\r
jobId = wsproxy.analize(fastalist);\r
}\r
- System.out.println("\n\ncalling analise.........");\r
+ System.out.println("\n\rcalling predictor.........");\r
Thread.sleep(1000);\r
+ /*\r
+ JobStatus status = wsproxy.getJobStatus(jobId);\r
+ System.out.println("\njob " + jobId + " status: " + status);\r
+ */\r
scores = wsproxy.getAnnotation(jobId);\r
-\r
} catch (JobSubmissionException e) {\r
- System.err\r
- .println("Exception while submitting job to a web server. "\r
- + "Exception details are below:");\r
+ System.err.println("Exception while submitting job to a web server. 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
+ System.err.println("Exception while waiting for results. Exception details are below:");\r
e.printStackTrace();\r
} catch (InterruptedException e) {\r
- // ignore and propagate an interruption\r
Thread.currentThread().interrupt();\r
- System.err.println("Exception while waiting for results. "\r
- + "Exception details are below:");\r
+ System.err.println("Exception while waiting for results. Exception details are below:");\r
e.printStackTrace();\r
} catch (WrongParameterException e) {\r
- System.err\r
- .println("Exception while parsing the web method input parameters. "\r
- + "Exception details are below:");\r
+ String mess = "Parsing the web method input parameters failed Exception details are below:";\r
+ System.err.println(mess);\r
e.printStackTrace();\r
}\r
return scores;\r
* @throws IOException\r
* @throws UnknownFileFormatException\r
*/\r
- static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
- Preset<T> preset, List<Option<T>> customOptions) {\r
+ static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy, Preset<T> preset, List<Option<T>> customOptions) {\r
List<FastaSequence> fastalist = null;\r
try {\r
fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
assert !fastalist.isEmpty() : "Input is empty!";\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
+ String mess = "Reading the input file failed. Check that the file contains a list of FASTA records!\n";\r
+ System.err.println(mess + "Exception details are below:");\r
e.printStackTrace();\r
} catch (UnknownFileFormatException e) {\r
- System.err\r
- .println("Exception while attempting to read the input file "\r
- + "Exception details are below:");\r
+ String mess = "Reading the input file failed. Exception details are below:";\r
+ System.err.println(mess);\r
System.out.println(e.getMessage());\r
e.printStackTrace();\r
}\r
return analize(fastalist, wsproxy, preset, customOptions);\r
}\r
- /**\r
- * Connects to a web service by the host and the service name web service\r
- * type\r
- * \r
- * @param host\r
- * the fully qualified name of JABAWS server including JABAWS\r
- * context name e.g\r
- * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
- * @param service\r
- * the name of the JABAWS service to connect to\r
- * @return JABAService<T>\r
- * @throws WebServiceException\r
- * @throws ConnectException\r
- * if fails to connect to the service on the host\r
- */\r
- public static JABAService connect(String host, Services service)\r
- throws WebServiceException, ConnectException {\r
- URL url = null;\r
- log.log(Level.FINE, "Attempting to connect...");\r
- try {\r
- url = new URL(host + "/" + service.toString() + "?wsdl");\r
- } catch (MalformedURLException e) {\r
- e.printStackTrace();\r
- // ignore as the host name is already verified\r
- }\r
- Service serv = null;\r
- try {\r
- serv = service.getService(url, JABAService.SERVICE_NAMESPACE);\r
- } catch (WebServiceException wse) {\r
- System.out.println("Connecting to JABAWS version 2 service");\r
- if (isV2service(wse)) {\r
- serv = service\r
- .getService(url, JABAService.V2_SERVICE_NAMESPACE);\r
- }\r
- }\r
- if (serv == null) {\r
- throw new ConnectException("Could not connect to " + url\r
- + " the server is down?");\r
- }\r
- JABAService serviceIF = service.getInterface(serv);\r
- log.log(Level.INFO, "Connected successfully!");\r
-\r
- return serviceIF;\r
- }\r
-\r
- static boolean isV2service(WebServiceException wse) {\r
- String message = wse.getMessage();\r
- int idx = message.indexOf("not a valid service");\r
- if (idx > 0) {\r
- if (message.substring(idx).contains(\r
- JABAService.V2_SERVICE_NAMESPACE)) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Get a connection of JABAWS registry\r
- * \r
- * @param host\r
- * the fully qualified name of JABAWS server including JABAWS\r
- * context name e.g\r
- * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
- * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
- * service\r
- * @throws WebServiceException\r
- * @throws ConnectException\r
- */\r
- public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
- throws WebServiceException, ConnectException {\r
- URL url = null;\r
- String service = "RegistryWS";\r
- log.log(Level.FINE, "Attempting to connect...");\r
-\r
- try {\r
- url = new URL(host + "/" + service + "?wsdl");\r
- } catch (MalformedURLException e) {\r
- e.printStackTrace();\r
- // ignore as the host name is already verified\r
- }\r
- QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
- Service serv = Service.create(url, qname);\r
-\r
- if (serv == null) {\r
- throw new ConnectException("Could not connect to " + url\r
- + " the server is down?");\r
- }\r
-\r
- QName portName = new QName(serv.getServiceName().getNamespaceURI(),\r
- service + "Port");\r
- compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName,\r
- compbio.data.msa.RegistryWS.class);\r
-\r
- log.log(Level.INFO, "Connected to " + service + " successfully!");\r
-\r
- return serviceIF;\r
- }\r
\r
/**\r
* Align sequences from the file using MsaWS\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
+ List<FastaSequence> 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
+ System.out.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 {\r
jobId = msaws.align(fastalist);\r
}\r
- System.out.println("\n\ncalling align.........");\r
+ System.out.println("\ncalling program.........");\r
+ /*\r
+ long startTime = System.nanoTime();\r
+ while (JobStatus.RUNNING == msaws.getJobStatus(jobId)) {\r
+ Thread.sleep(1000);\r
+ long endTime = System.nanoTime();\r
+ System.out.println("job " + jobId + " time executing: "+ (endTime - startTime) / 1000000 +" msec, status: " + msaws.getJobStatus(jobId));\r
+ }\r
+ */\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
+ System.err.println("Exception while reading the input file. Check that the input file is a FASTA file! "\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
+ System.err.println("Exception while submitting job to a web server. 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
+ System.err.println("Exception while waiting for results. Exception details are below:");\r
e.printStackTrace();\r
} catch (InterruptedException ignored) {\r
// ignore and propagate an interruption\r
}\r
\r
/**\r
- * Return RNA secondary structure from a file using FoldWS\r
- * \r
- * @param <T>\r
- * web service type e.g. Clustal\r
- * @param file\r
- * to read the results from\r
- * @param foldws\r
- * FoldWS required\r
- * @param preset\r
- * Preset to use optional\r
- * @param customOptions\r
- * file which contains new line separated list of options\r
- * @return String\r
- */\r
- \r
- static <T> String fold(File file, FoldWS<T> foldws, Preset<T> preset,\r
- List<Option<T>> customOptions) {\r
- FileInputStream instream = null;\r
- Alignment alignment = null;\r
- String rnastruct = null;\r
- try {\r
- instream = new FileInputStream(file);\r
- alignment = ClustalAlignmentUtil.readClustalFile(instream);\r
- instream.close();\r
- String jobId = null;\r
- if (customOptions != null && preset != null) {\r
- System.out.println("WARN: Parameters (-f) are defined together"\r
- + "with a preset (-r), ignoring preset! ");\r
- }\r
- if (customOptions != null) {\r
- jobId = foldws.customFold(alignment, customOptions);\r
- } else if (preset != null) {\r
- jobId = foldws.presetFold(alignment, preset);\r
- } else {\r
- jobId = foldws.fold(alignment);\r
- }\r
- System.out.println("\n\ncalling fold.........");\r
- Thread.sleep(1000);\r
- rnastruct = foldws.getResult(jobId);\r
- \r
- } catch (IOException e) {\r
- System.err.println("Exception while reading the input file. Exception details: ");\r
- e.printStackTrace();\r
- } catch (UnknownFileFormatException e) {\r
- System.err.println("Exception while reading input file. Doesnt look like a Clustal format file");\r
- e.printStackTrace();\r
- } catch (JobSubmissionException e) {\r
- System.err.println("Exception while submitting job to the web server. ");\r
- e.printStackTrace();\r
- } catch (ResultNotAvailableException e) {\r
- System.err.println("Exception while waiting for results. Exception details: ");\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 rnastruct;\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(Constraints.help_text);\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 successful call the JWS2 host name and a\r
* service name.\r
* \r
*/\r
public static void main(String[] args) {\r
-\r
if (args == null) {\r
- printUsage(1);\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
if (args.length < 2) {\r
- System.err.println("Host and service names are required!");\r
- printUsage(1);\r
+ System.err.println("Host (-h=<host>, e.g. -h=http://www.compbio.dundee.ac.uk/jabaws) and service (-s=<ServiceName>, e.g. -s=Jpred) are required!");\r
+ System.out.println(Constraints.help_text);\r
+ System.exit(1);\r
}\r
-\r
try {\r
new Jws2Client(args);\r
} catch (IOException e) {\r
- log.log(Level.SEVERE, "IOException in client! " + e.getMessage(),\r
- e.getCause());\r
+ log.log(Level.SEVERE, "IOException in client! " + e.getMessage(), e.getCause());\r
System.err.println("Cannot write output file! Stack trace: ");\r
e.printStackTrace();\r
}\r