Fix problem with test data for RNAalifold
[jabaws.git] / webservices / compbio / ws / client / WSTester.java
index 292d121..483c162 100644 (file)
@@ -35,11 +35,9 @@ import javax.xml.ws.WebServiceException;
 import compbio.data.msa.JABAService;\r
 import compbio.data.msa.Metadata;\r
 import compbio.data.msa.MsaWS;\r
-import compbio.data.msa.FoldWS;\r
 import compbio.data.msa.SequenceAnnotation;\r
 import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.Program;\r
 import compbio.data.sequence.ScoreManager;\r
 import compbio.data.sequence.SequenceUtil;\r
 import compbio.metadata.JobStatus;\r
@@ -76,9 +74,10 @@ public class WSTester {
                        + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\n"\r
                        + "";\r
 \r
-       \r
-       \r
-       static final List<FastaSequence> seqs = loadSeqs();\r
+       public static final String fastaRNAAlignment = ">Foo\n"\r
+                       + "C-UUGCGUUAAUGAGAACAGAAACG-UAAA--CUAUAA-CCUAG-G-GGUUUCUGUUGGAUGGUUG----GCAAC\n"\r
+                       + ">Bar\n"\r
+                       + "G-UGGCGCUUAUGACGCAGUUGUCU-UAAA-CUCGAAC--UCGA-GCGGGCAAUUGCUGAU-UACGAUUAACCAC\n";\r
 \r
        private static final String FAILED = "FAILED";\r
        private static final String OK = "OK";\r
@@ -104,7 +103,7 @@ public class WSTester {
        /**\r
         * Converting input to a form accepted by WS\r
         * \r
-        * @return List of FastaSequence records\r
+        * @return List of FastaSequence records with aligned protein sequences\r
         */\r
        private static List<FastaSequence> loadAlignment() {\r
                try {\r
@@ -116,6 +115,20 @@ public class WSTester {
                }\r
                return null;\r
        }\r
+       /**\r
+        * Converting input to a form accepted by WS\r
+        * \r
+        * @return List of FastaSequence records with aligned RNA sequences\r
+        */\r
+       private static List<FastaSequence> loadRNAAlignment() {\r
+               try {\r
+                       return SequenceUtil.readFasta(new ByteArrayInputStream(fastaRNAAlignment.getBytes()));\r
+               } catch (IOException ignored) {\r
+                       // Should not happen as a source is not a external stream\r
+                       ignored.printStackTrace();\r
+               }\r
+               return null;\r
+       }\r
 \r
        private final PrintWriter writer;\r
        private final String hostname;\r
@@ -174,7 +187,7 @@ public class WSTester {
                        writer.print("Aligning with preset '" + preset.getName() + "'... ");\r
                        Alignment al = null;\r
                        try {\r
-                               String taskId = msaws.presetAlign(seqs, preset);\r
+                               String taskId = msaws.presetAlign(loadSeqs(), preset);\r
                                al = msaws.getResult(taskId);\r
                                if (al != null) {\r
                                        writer.println(OK);\r
@@ -211,14 +224,6 @@ public class WSTester {
                return succeed;\r
        }\r
        \r
-       private <T> boolean testFoldWS(FoldWS<T> foldws) throws Exception {\r
-               assert foldws != null;\r
-               \r
-               boolean succeed = testDefaultFold(foldws);\r
-               \r
-               // testMetadata(foldws);\r
-               return succeed;\r
-       }\r
        /**\r
         * Call most of web services functions and check the output\r
         * \r
@@ -243,8 +248,6 @@ public class WSTester {
                        } else if (wservice instanceof SequenceAnnotation) {\r
                                return testSequenceAnnotationWS(\r
                                                (SequenceAnnotation<T>) wservice, service);\r
-                       } else if (wservice instanceof FoldWS) {\r
-                               return testFoldWS( (FoldWS<T>) wservice);\r
                        } else {\r
                                throw new UnsupportedOperationException("The service: "\r
                                                + wservice.getClass() + " is not supported! ");\r
@@ -260,8 +263,10 @@ public class WSTester {
                writer.print("Calling analyse.........");\r
 \r
                List<FastaSequence> input = loadSeqs();\r
-               if (service == Services.AAConWS || service == Services.RNAalifoldWS) {\r
+               if (service == Services.AAConWS ) {\r
                        input = loadAlignment();\r
+               } else if (service == Services.RNAalifoldWS) {\r
+                       input = loadRNAAlignment();\r
                }\r
                boolean success = testDefaultAnalyse(input, wservice, null, null);\r
 \r
@@ -359,7 +364,7 @@ public class WSTester {
                Alignment al = null;\r
                boolean succeed = false;\r
 \r
-               String taskId = msaws.align(seqs);\r
+               String taskId = msaws.align(loadSeqs());\r
                writer.print("\nQuerying job status...");\r
                JobStatus status = msaws.getJobStatus(taskId);\r
                while (status != JobStatus.FINISHED) {\r
@@ -377,37 +382,6 @@ public class WSTester {
        }\r
        \r
        /**\r
-        * Fold using default settings\r
-        * \r
-        * @param <T>\r
-        * @param foldws\r
-        * @throws UnsupportedRuntimeException\r
-        */\r
-       \r
-       private <T> boolean testDefaultFold(FoldWS<T> foldws) throws Exception {\r
-               writer.print("Testing fold with default parameters:");\r
-               // load the input from the aligned fasta string at the top of the file\r
-               Alignment al = new Alignment(loadAlignment(), Program.CLUSTAL, '-');\r
-               String rs = null;\r
-               boolean succeed = false;\r
-               \r
-               String taskId = foldws.fold(al);\r
-               writer.print("\nQuerying job status...");\r
-               JobStatus status = foldws.getJobStatus(taskId);\r
-               while (status != JobStatus.FINISHED) {\r
-                       Thread.sleep(1000);\r
-                       status = foldws.getJobStatus(taskId);\r
-               }\r
-               writer.println(OK);\r
-               writer.print("Retrieving results...");\r
-               rs = foldws.getResult(taskId);\r
-               succeed = true;\r
-               if (rs != null) {\r
-                       writer.println(OK);\r
-               }\r
-               return succeed;\r
-       }\r
-       /**\r
         * Test JWS2 web services\r
         * \r
         * @param <T>\r
@@ -456,7 +430,6 @@ public class WSTester {
                        tester.writer.println();\r
                        tester.checkService(serv);\r
                }\r
-\r
        }\r
 \r
        /**\r
@@ -489,11 +462,9 @@ public class WSTester {
 \r
        private void reportResults(Services serv, boolean succeed) {\r
                if (succeed) {\r
-                       writer.println("Check is completed. The Service " + serv\r
-                                       + " IS WORKING\n");\r
+                       writer.println("Check is completed. The Service " + serv + " IS WORKING\n");\r
                } else {\r
-                       writer.println("Check is aborted. The Service " + serv\r
-                                       + " HAS SOME PROBLEMS\n");\r
+                       writer.println("Check is aborted. The Service " + serv + " HAS SOME PROBLEMS\n");\r
                }\r
        }\r
 }\r