Formatting
[jalview.git] / src / jalview / ws / JPredClient.java
index aee3418..2475fb1 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -26,26 +26,29 @@ import ext.vamsas.*;
 import jalview.analysis.*;
 import jalview.bin.*;
 import jalview.datamodel.*;
-import jalview.datamodel.AlignmentView;
 import jalview.gui.*;
 
 public class JPredClient
     extends WSClient
 {
-    /**
-     * crate a new GUI JPred Job
-     * @param sh ServiceHandle
-     * @param title String
-     * @param msa boolean - true - submit alignment as a sequence profile
-     * @param alview AlignmentView
-     * @param viewonly TODO
-     */
-    public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa, AlignmentView alview, AlignFrame parentFrame, boolean viewonly) {
+  /**
+   * crate a new GUI JPred Job
+   * @param sh ServiceHandle
+   * @param title String
+   * @param msa boolean - true - submit alignment as a sequence profile
+   * @param alview AlignmentView
+   * @param viewonly TODO
+   */
+  public JPredClient(ext.vamsas.ServiceHandle sh, String title, boolean msa,
+                     AlignmentView alview, AlignFrame parentFrame,
+                     boolean viewonly)
+  {
     super();
-    wsInfo=setWebService(sh);
+    wsInfo = setWebService(sh);
     startJPredClient(title, msa, alview, parentFrame, viewonly);
 
   }
+
   /**
    * startJPredClient
    * TODO: refine submission to cope with local prediction of visible regions or multiple single sequence jobs
@@ -58,7 +61,8 @@ public class JPredClient
    * @param viewonly if true then the prediction will be made just on the concatenated visible regions
    */
   private void startJPredClient(String title, boolean msa,
-                                jalview.datamodel.AlignmentView alview, AlignFrame parentFrame, boolean viewonly)
+                                jalview.datamodel.AlignmentView alview,
+                                AlignFrame parentFrame, boolean viewonly)
   {
     AlignmentView input = alview;
     if (wsInfo == null)
@@ -71,42 +75,47 @@ public class JPredClient
       Cache.log.warn("Couldn't find a Jpred webservice to invoke!");
       return;
     }
-    SeqCigar[] msf=null;
-    SequenceI seq=null;
-    int[] delMap=null;
+    SeqCigar[] msf = null;
+    SequenceI seq = null;
+    int[] delMap = null;
     // original JNetClient behaviour - submit full length of sequence or profile
     // and mask result.
     msf = input.getSequences();
     seq = msf[0].getSeq('-');
 
-    if (viewonly) {
+    if (viewonly)
+    {
       int[] viscontigs = alview.getVisibleContigs();
-      int spos=0;
-      int i=0;
-      if (viscontigs!=null) {
+      int spos = 0;
+      int i = 0;
+      if (viscontigs != null)
+      {
         // Construct the delMap - mapping from the positions within the input to Jnet to the contigs in the original sequence
 
-        delMap = new int[seq.getEnd()-seq.getStart()+1];
+        delMap = new int[seq.getEnd() - seq.getStart() + 1];
         int gapMap[] = seq.gapMap();
-        for (int contig = 0; contig<viscontigs.length; contig += 2)
+        for (int contig = 0; contig < viscontigs.length; contig += 2)
         {
 
-          while (spos<gapMap.length && gapMap[spos]<viscontigs[contig]) {
+          while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
+          {
             spos++;
           }
-          while (spos<gapMap.length && gapMap[spos]<=viscontigs[contig+1]) {
+          while (spos < gapMap.length && gapMap[spos] <= viscontigs[contig + 1])
+          {
             delMap[i++] = spos++;
           }
         }
         int tmap[] = new int[i];
         System.arraycopy(delMap, 0, tmap, 0, i);
-        delMap=tmap;
+        delMap = tmap;
       }
     }
     if (msa && msf.length > 1)
     {
 
-      String altitle = "JNet prediction on "+(viewonly?"visible ":"") + seq.getName() +
+      String altitle = "JNet prediction on " + (viewonly ? "visible " : "") +
+          seq.getName() +
           " using alignment from " + title;
 
       SequenceI aln[] = new SequenceI[msf.length];
@@ -115,9 +124,9 @@ public class JPredClient
         aln[i] = msf[i].getSeq('-');
       }
 
-
       Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
-      if (viewonly) {
+      if (viewonly)
+      {
         // Remove hidden regions from sequence objects.
         String seqs[] = alview.getSequenceStrings('-');
         for (int i = 0, j = msf.length; i < j; i++)
@@ -126,49 +135,62 @@ public class JPredClient
         }
         seq.setSequence(seqs[0]);
       }
-      wsInfo.setProgressText("Job details for "+(viewonly?"visible ":"")+"MSA based prediction (" +
-          title + ") on sequence :\n>" + seq.getName() +
-          "\n" +
-          AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
-          "\n");
+      wsInfo.setProgressText("Job details for " + (viewonly ? "visible " : "") +
+                             "MSA based prediction (" +
+                             title + ") on sequence :\n>" + seq.getName() +
+                             "\n" +
+                             AlignSeq.extractGaps("-. ",
+                                                  seq.getSequenceAsString()) +
+                             "\n");
       JPredThread jthread = new JPredThread(wsInfo, altitle, server,
-                                            SequenceInfo, aln, delMap, alview, parentFrame, WsURL);
+                                            SequenceInfo, aln, delMap, alview,
+                                            parentFrame, WsURL);
       wsInfo.setthisService(jthread);
       jthread.start();
     }
     else
     {
-      if (!msa && msf.length>1)
+      if (!msa && msf.length > 1)
+      {
         throw new Error("Implementation Error! Multiple single sequence prediction jobs are not yet supported.");
-      String altitle = "JNet prediction for "+(viewonly?"visible ":"")+"sequence " + seq.getName() +
+      }
+      String altitle = "JNet prediction for " + (viewonly ? "visible " : "") +
+          "sequence " + seq.getName() +
           " from " +
           title;
       String seqname = seq.getName();
       Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(
           seq);
-      if (viewonly) {
+      if (viewonly)
+      {
         // Remove hidden regions from input sequence
         String seqs[] = alview.getSequenceStrings('-');
         seq.setSequence(seqs[0]);
       }
-      wsInfo.setProgressText("Job details for prediction on "+(viewonly?"visible ":"")+"sequence :\n>" +
-          seqname + "\n" +
-          AlignSeq.extractGaps("-. ", seq.getSequenceAsString()) +
-          "\n");
+      wsInfo.setProgressText("Job details for prediction on " +
+                             (viewonly ? "visible " : "") + "sequence :\n>" +
+                             seqname + "\n" +
+                             AlignSeq.extractGaps("-. ",
+                                                  seq.getSequenceAsString()) +
+                             "\n");
       JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
-                                            SequenceInfo, seq, delMap, alview, parentFrame);
+                                            SequenceInfo, seq, delMap, alview,
+                                            parentFrame);
       wsInfo.setthisService(jthread);
       jthread.start();
     }
   }
-  public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq, AlignFrame parentFrame)
+
+  public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI seq,
+                     AlignFrame parentFrame)
   {
     super();
     wsInfo = setWebService(sh);
     startJPredClient(title, seq, parentFrame);
   }
 
-  public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa, AlignFrame parentFrame)
+  public JPredClient(ext.vamsas.ServiceHandle sh, String title, SequenceI[] msa,
+                     AlignFrame parentFrame)
   {
     wsInfo = setWebService(sh);
     startJPredClient(title, msa, parentFrame);
@@ -184,7 +206,8 @@ public class JPredClient
     startJPredClient(title, seq, null);
   }
 
-  private void startJPredClient(String title, SequenceI[] msf, AlignFrame parentFrame)
+  private void startJPredClient(String title, SequenceI[] msf,
+                                AlignFrame parentFrame)
   {
     if (wsInfo == null)
     {
@@ -209,17 +232,19 @@ public class JPredClient
     Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);
 
     Jpred server = locateWebService();
-    if (server==null)
+    if (server == null)
     {
       return;
     }
 
-    JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo, aln,null, null, parentFrame, WsURL);
+    JPredThread jthread = new JPredThread(wsInfo, altitle, server, SequenceInfo,
+                                          aln, null, null, parentFrame, WsURL);
     wsInfo.setthisService(jthread);
     jthread.start();
   }
 
-  public void startJPredClient(String title, SequenceI seq, AlignFrame parentFrame)
+  public void startJPredClient(String title, SequenceI seq,
+                               AlignFrame parentFrame)
   {
     if (wsInfo == null)
     {
@@ -235,12 +260,14 @@ public class JPredClient
     Hashtable SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
 
     Jpred server = locateWebService();
-    if (server==null)
+    if (server == null)
     {
       return;
     }
 
-    JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL, SequenceInfo, seq,null, null, parentFrame);
+    JPredThread jthread = new JPredThread(wsInfo, altitle, server, WsURL,
+                                          SequenceInfo, seq, null, null,
+                                          parentFrame);
     wsInfo.setthisService(jthread);
     jthread.start();
   }
@@ -264,11 +291,11 @@ public class JPredClient
   private ext.vamsas.Jpred locateWebService()
   {
     ext.vamsas.JpredServiceLocator loc = new JpredServiceLocator(); // Default
-    ext.vamsas.Jpred server=null;
+    ext.vamsas.Jpred server = null;
     try
     {
       server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
-      ( (JpredSoapBindingStub)server).setTimeout(60000); // one minute stub
+      ( (JpredSoapBindingStub) server).setTimeout(60000); // one minute stub
       //((JpredSoapBindingStub)this.server)._setProperty(org.apache.axis.encoding.C, Boolean.TRUE);
 
     }
@@ -291,4 +318,3 @@ public class JPredClient
     return server;
   }
 }
-