WRITEABLE_FORMATS and READABLE_FORMATS string []
[jalview.git] / src / jalview / ws / JPredClient.java
index 9fe7e27..ec3f737 100755 (executable)
@@ -26,6 +26,8 @@ import ext.vamsas.*;
 import jalview.analysis.*;\r
 import jalview.datamodel.*;\r
 import jalview.gui.*;\r
+import jalview.io.FormatAdapter;\r
+import jalview.io.*;\r
 \r
 public class JPredClient\r
     extends WSClient\r
@@ -56,6 +58,7 @@ public class JPredClient
       wsInfo = setWebService();\r
 \r
     SequenceI seq = msf[0];\r
+\r
     altitle = "JNet prediction on " + seq.getName() +\r
         " using alignment from " + title;\r
 \r
@@ -64,8 +67,10 @@ public class JPredClient
                            AlignSeq.extractGaps("-. ", seq.getSequence()) +\r
                            "\n");\r
     SequenceI aln[] = new SequenceI[msf.length];\r
-    for (int i=0,j=msf.length; i<j;i++)\r
-      aln[i] = new jalview.datamodel.Sequence(msf[i]);\r
+    for (int i=0,j=msf.length; i<j;i++) {\r
+        aln[i] = new jalview.datamodel.Sequence(msf[i]);\r
+    }\r
+\r
     SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);\r
 \r
     if (!locateWebService())\r
@@ -104,7 +109,7 @@ public class JPredClient
     WebServiceName = "JNetWS";\r
     WebServiceJobTitle = "JNet secondary structure prediction";\r
     WebServiceReference =\r
-        "\"Cuff J. A and Barton G.J (1999) Application of enhanced " +\r
+        "\"Cuff J. A and Barton G.J (2000) Application of " +\r
         "multiple sequence alignment profiles to improve protein secondary structure prediction, " +\r
         "Proteins 40:502-511\".";\r
     WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";\r
@@ -123,6 +128,8 @@ public class JPredClient
     {\r
       this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties\r
       ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub\r
+      //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);\r
+\r
     }\r
     catch (Exception ex)\r
     {\r
@@ -136,7 +143,7 @@ public class JPredClient
                              " Service location failed\nfor URL :" + WsURL +\r
                              "\n" +\r
                              ex.getMessage());\r
-      wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);\r
+      wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);\r
 \r
       return false;\r
     }\r
@@ -171,9 +178,9 @@ public class JPredClient
       this.sequence.setSeq(AlignSeq.extractGaps("-. ",\r
                                                 msf[0].getSequence()));\r
 \r
-      jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();\r
       this.msa = new vamsas.objects.simple.Msfalignment();\r
-      msa.setMsf(mwrite.print(msf));\r
+      jalview.io.PileUpfile pileup = new jalview.io.PileUpfile();\r
+      msa.setMsf(pileup.print(msf));\r
     }\r
 \r
     public void run()\r
@@ -234,6 +241,7 @@ public class JPredClient
         catch (Exception ex)\r
         {\r
           allowedServerExceptions--;\r
+\r
           wsInfo.appendProgressText("\nJPredWS Server exception!\n" +\r
                                     ex.getMessage());\r
 \r
@@ -304,26 +312,36 @@ public class JPredClient
       }\r
       catch (Exception e)\r
       {\r
-        wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);\r
+        if (e.getMessage().indexOf("Exception")>-1) {\r
+          wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);\r
+          wsInfo.setProgressText(\r
+              "Failed to submit the prediction. (Just close the window)\n"\r
+              +\r
+              "It is most likely that there is a problem with the server.\n");\r
+          System.err.println(\r
+              "JPredWS Client: Failed to submit the prediction. Quite possibly because of a server error - see below)\n" +\r
+              e.getMessage() + "\n");\r
+\r
+          jalview.bin.Cache.log.warn("Server Exception",e);\r
+        } else {\r
+          wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);\r
+          // JBPNote - this could be a popup informing the user of the problem.\r
+          wsInfo.setProgressText("Failed to submit the prediction:\n"\r
+                                 +e.getMessage()+\r
+                                 wsInfo.getProgressText());\r
+\r
+          jalview.bin.Cache.log.debug("Failed Submission",e);\r
+\r
+        }\r
         allowedServerExceptions = -1;\r
         jobComplete = true;\r
 \r
-        wsInfo.setProgressText("Failed to submit the prediction. (Just close the window)\n"\r
-                                  + ((e.getMessage().indexOf("Exception")>-1) ? (\r
-                                  "It is most likely that there is a problem with the server.\n")\r
-                              : e.getMessage())\r
-                                  +wsInfo.getProgressText());\r
-        System.err.println(\r
-            "JPredWS Client: Failed to submit the prediction (Possibly a server error - see below)\n" +\r
-            e.getMessage() + "\n");\r
-\r
-        jalview.bin.Cache.log.debug("Failed Submission",e);\r
       }\r
     }\r
 \r
 \r
 \r
-    private void addFloatAnnotations(Alignment al, int[] gapmap,\r
+  /*  private void addFloatAnnotations(Alignment al, int[] gapmap,\r
                                      Vector values, String Symname,\r
                                      String Visname, float min,\r
                                      float max, int winLength)\r
@@ -339,7 +357,7 @@ public class JPredClient
 \r
       al.addAnnotation(new AlignmentAnnotation(Symname, Visname,\r
                                                annotations, min, max, winLength));\r
-    }\r
+    }*/\r
 \r
     void parseResult()\r
     {\r
@@ -385,23 +403,24 @@ public class JPredClient
         {\r
           jalview.bin.Cache.log.debug("Getting associated alignment.");\r
           // we ignore the returned alignment if we only predicted on a single sequence\r
-          String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),\r
+          String format = new jalview.io.IdentifyFile().Identify(result.getAligfile(),\r
               "Paste");\r
 \r
-          if (jalview.io.FormatAdapter.formats.contains(format))\r
+          if (jalview.io.FormatAdapter.isValidFormat(format))\r
           {\r
-            al = new Alignment(jalview.io.FormatAdapter.readFile(\r
+            al = new Alignment(new FormatAdapter().readFile(\r
                 result.getAligfile(), "Paste", format));\r
+            SequenceI sqs[] = new SequenceI[al.getHeight()];\r
             for (int i=0, j=al.getHeight(); i<j; i++) {\r
-              SequenceI sq = al.getSequenceAt(i);\r
-              if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(\r
-                  sq, (Hashtable) SequenceInfo.get(sq.getName())))\r
+              sqs[i] = al.getSequenceAt(i);\r
+            }\r
+            if (!jalview.analysis.SeqsetUtils.deuniquify(\r
+                  (Hashtable) SequenceInfo,sqs))\r
               {\r
                 throw (new Exception(\r
-                    "Couldn't recover sequence properties for JNet "\r
-                    +((i==0) ? "Query sequence" : "alignment sequence ("+i+")")));\r
+                    "Couldn't recover sequence properties for alignment."));\r
               }\r
-            }\r
+\r
             noMsa = false;\r
             FirstSeq = 0;\r
           }\r
@@ -424,101 +443,15 @@ public class JPredClient
           }\r
         }\r
 \r
+        al.setDataset(null);\r
 \r
-        AlignmentAnnotation annot;\r
-        Annotation[] annotations = null;\r
-        int i = 0;\r
-        int width = preds[0].getSequence().length();\r
-\r
-        int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();\r
-\r
-        if (gapmap.length != width)\r
-        {\r
-          throw (new Exception(\r
-              "Jnet Client Error\nNumber of residues in supposed query sequence :\n" +\r
-              al.getSequenceAt(FirstSeq).getName() + "\n" +\r
-              al.getSequenceAt(FirstSeq).getSequence() +\r
-              "\nDiffer from number of prediction sites in \n" +\r
-              result.getPredfile() + "\n"));\r
+        try {\r
+          jalview.io.JnetAnnotationMaker.add_annotation(prediction, al, FirstSeq,\r
+              noMsa);\r
         }\r
-\r
-        // JBPNote Should also rename the query sequence sometime...\r
-        i = 0;\r
-\r
-        while (i < preds.length)\r
-        {\r
-          String id = preds[i].getName().toUpperCase();\r
-\r
-          if (id.startsWith("LUPAS") || id.startsWith("JNET") ||\r
-              id.startsWith("JPRED"))\r
-          {\r
-            annotations = new Annotation[al.getWidth()];\r
-\r
-            if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||\r
-                id.equals("JNETFREQ") || id.equals("JNETHMM") ||\r
-                id.equals("JNETALIGN") || id.equals("JPRED"))\r
-            {\r
-              for (int j = 0; j < width; j++)\r
-              {\r
-                annotations[gapmap[j]] = new Annotation("", "",\r
-                    preds[i].getCharAt(j), 0);\r
-              }\r
-            }\r
-            else if (id.equals("JNETCONF"))\r
-            {\r
-              for (int j = 0; j < width; j++)\r
-              {\r
-                float value = Float.parseFloat(preds[i].getCharAt(\r
-                    j) + "");\r
-                annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
-                    j) + "", "", preds[i].getCharAt(j),\r
-                    value);\r
-              }\r
-            }\r
-            else\r
-            {\r
-              for (int j = 0; j < width; j++)\r
-              {\r
-                annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(\r
-                    j) + "", "", ' ', 0);\r
-              }\r
-            }\r
-\r
-            if (id.equals("JNETCONF"))\r
-            {\r
-              annot = new AlignmentAnnotation(preds[i].getName(),\r
-                                              "JNet Output", annotations, 0f,\r
-                                              10f, 1);\r
-            }\r
-            else\r
-            {\r
-              annot = new AlignmentAnnotation(preds[i].getName(),\r
-                                              "JNet Output", annotations);\r
-            }\r
-\r
-            al.addAnnotation(annot);\r
-\r
-            if (noMsa)\r
-            {\r
-              al.deleteSequence(preds[i]);\r
-            }\r
-          }\r
-\r
-          i++;\r
+        catch (Exception e) {\r
+          jalview.bin.Cache.log.error("JNet Client: JPred Annotation Parse Error", e);\r
         }\r
-\r
-        Hashtable scores = prediction.getScores();\r
-\r
-        /*  addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPH"),\r
-                              "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);\r
-\r
-          addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPB"),\r
-         "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);\r
-\r
-          addFloatAnnotations(al, gapmap,  (Vector)scores.get("JNETPROPC"),\r
-                              "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);\r
-         */\r
-\r
         wsInfo.setProgressText(OutputHeader);\r
         jalview.bin.Cache.log.debug("Finished parsing output.");\r
         AlignFrame af = new AlignFrame(al);\r
@@ -529,8 +462,7 @@ public class JPredClient
       }\r
       catch (Exception ex)\r
       {\r
-        jalview.bin.Cache.log.warn("Exception whilst parsing JNet style secondary structure prediction.");\r
-        jalview.bin.Cache.log.debug("Exception: ",ex);\r
+        jalview.bin.Cache.log.warn("Exception whilst parsing JNet style secondary structure prediction.",ex);\r
       }\r
     }\r
   }\r