import java.net.MalformedURLException;\r
import java.net.URL;\r
import java.util.Arrays;\r
+import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.logging.Level;\r
import java.util.logging.Logger;\r
\r
import compbio.data.msa.JABAService;\r
import compbio.data.msa.Metadata;\r
import compbio.data.msa.MsaWS;\r
+import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.Alignment;\r
import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.Score;\r
import compbio.data.sequence.SequenceUtil;\r
+import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.metadata.JobSubmissionException;\r
import compbio.metadata.Option;\r
import compbio.metadata.Preset;\r
}\r
Alignment alignment = null;\r
if (inputFile != null) {\r
+ OutputStream outStream = null;\r
+ if (outFile != null) {\r
+ outStream = IOHelper.getOutStream(outFile);\r
+ } else {\r
+ // this stream is going to be closed later which is fine as\r
+ // std.out will not be\r
+ outStream = System.out;\r
+ }\r
if (service == Services.AAConWS) {\r
- System.out.println("calc conserv!");\r
+ Map<String, HashSet<Score>> result = analize(inputFile,\r
+ ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
+ IOHelper.writeOut(outStream, result);\r
} else {\r
-\r
alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
customOptions);\r
- OutputStream outStream = null;\r
- if (outFile != null) {\r
- outStream = IOHelper.getOutStream(outFile);\r
- } else {\r
- // this stream is going to be closed later which is fine as\r
- // std.out will not be\r
- outStream = System.out;\r
- }\r
IOHelper.writeOut(outStream, alignment);\r
- // stream is closed in the method no need to close it here\r
}\r
+\r
+ // stream is closed in the method no need to close it here\r
}\r
\r
boolean listParameters = CmdHelper.listParameters(cmd);\r
((Closeable) msaws).close();\r
log.fine("Disconnected successfully!");\r
}\r
+ /**\r
+ * Calculate conservation for sequences loaded from the file\r
+ * \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
+ * the list of options\r
+ * @return Set<Score> the conservation scores\r
+ * @throws UnknownFileFormatException\r
+ */\r
+ <T> Map<String, HashSet<Score>> analize(File file,\r
+ SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
+ List<Option<T>> customOptions) {\r
+\r
+ List<FastaSequence> fastalist = null;\r
+ Map<String, HashSet<Score>> scores = null;\r
+ try {\r
+ fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
+\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 = wsproxy.customAnalize(fastalist, customOptions);\r
+ } else if (preset != null) {\r
+ jobId = wsproxy.presetAnalize(fastalist, preset);\r
+ } else {\r
+ jobId = wsproxy.analize(fastalist);\r
+ }\r
+ Thread.sleep(1000);\r
+ scores = wsproxy.getAnnotation(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
+ System.err\r
+ .println("Exception while parsing the web method input parameters. "\r
+ + "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
+ System.out.println(e.getMessage());\r
+ e.printStackTrace();\r
+ }\r
+ return scores;\r
+ }\r
\r
/**\r
* Connects to a web service by the host and the service name\r