Reverted some changes I made for testing back to their original states.
[jabaws.git] / webservices / compbio / ws / server / WSUtil.java
index 1890d65..e80b1e5 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright (c) 2009 Peter Troshin\r
+/* Copyright (c) 2011 Peter Troshin\r
  *  \r
- *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0\r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
  * \r
  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
  *  Apache License version 2 as published by the Apache Software Foundation\r
@@ -25,6 +25,7 @@ import java.util.Set;
 \r
 import org.apache.log4j.Logger;\r
 \r
+import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.FastaSequence;\r
 import compbio.data.sequence.ScoreManager;\r
 import compbio.engine.AsyncExecutor;\r
@@ -38,6 +39,8 @@ import compbio.metadata.Limit;
 import compbio.metadata.LimitExceededException;\r
 import compbio.metadata.Option;\r
 import compbio.metadata.ResultNotAvailableException;\r
+import compbio.ws.client.Services;\r
+import compbio.ws.client.ServicesUtil;\r
 \r
 public final class WSUtil {\r
 \r
@@ -106,8 +109,42 @@ public final class WSUtil {
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
+               reportUsage(confExec, logger);\r
                return jobId;\r
        }\r
+       \r
+       // Hardcoded gapchar '-' in this method\r
+       \r
+//     public static <T> String fold(Alignment alignment,\r
+//                     ConfiguredExecutable<T> confExec, Logger logger,\r
+//                     String callingMethod, Limit<T> limit)\r
+//                     throws LimitExceededException, JobSubmissionException {\r
+//             \r
+//             List<FastaSequence> sequences = alignment.getSequences();\r
+//             if (limit != null && limit.isExceeded(sequences)) {\r
+//                     throw LimitExceededException.newLimitExceeded(limit, sequences);\r
+//             }\r
+//             compbio.runner.Util.writeClustalInput(sequences, confExec, '-');\r
+//             System.out.println("WSUtil-fold: Writing the clustal input file on the server: to file: "\r
+//                             + confExec.getInput());\r
+//             System.out.println("WSUtil-fold: The executable is configured with parameters: " \r
+//                             + confExec.getParameters());\r
+////           System.out.println("WSUTil-fold: Dump the configured executable:\n" \r
+////                           + confExec.toString());\r
+//             AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
+//             String jobId = engine.submitJob(confExec);\r
+//             reportUsage(confExec, logger);\r
+//             return jobId;\r
+//     }\r
+\r
+       static <T> void reportUsage(ConfiguredExecutable<T> confExec, Logger logger) {\r
+               if (GAUtils.IS_GA_ENABLED) {\r
+                       Services service = ServicesUtil.getServiceByRunner(confExec\r
+                                       .getExecutable().getClass());\r
+                       GAUtils.reportUsage(service);\r
+                       logger.info("Reporting GA usage for " + service);\r
+               }\r
+       }\r
 \r
        public static <T> String analize(List<FastaSequence> sequences,\r
                        ConfiguredExecutable<T> confExec, Logger log, String method,\r
@@ -116,11 +153,27 @@ public final class WSUtil {
                        throw LimitExceededException.newLimitExceeded(limit, sequences);\r
                }\r
                log.debug("Method: " + method + " with task: " + confExec.getTaskId());\r
-\r
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
-\r
+               reportUsage(confExec, log);\r
+               return jobId;\r
+       }\r
+       \r
+       // Same as analize but Alifold takes clustal input not fasta\r
+       \r
+       public static <T> String fold(List<FastaSequence> sequences,\r
+                       ConfiguredExecutable<T> confExec, Logger log, String method,\r
+                       Limit<T> limit) throws JobSubmissionException {\r
+               if (limit != null && limit.isExceeded(sequences)) {\r
+                       throw LimitExceededException.newLimitExceeded(limit, sequences);\r
+               }\r
+               log.debug("Method: " + method + " with task: " + confExec.getTaskId());\r
+               // This line is different from the above method\r
+               compbio.runner.Util.writeClustalInput(sequences, confExec, '-');\r
+               AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
+               String jobId = engine.submitJob(confExec);\r
+               reportUsage(confExec, log);\r
                return jobId;\r
        }\r
 \r
@@ -161,7 +214,10 @@ public final class WSUtil {
                AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
                ConfiguredExecutable<T> aacon = (ConfiguredExecutable<T>) asyncEngine\r
                                .getResults(jobId);\r
+               \r
+               \r
                ScoreManager mas = aacon.getResults();\r
+               \r
                log.trace(jobId + " getConservation : " + mas);\r
                return mas;\r
        }\r