Merge: 497958b 68dcaa7
[jalview.git] / src / jalview / ws / jws1 / JPredThread.java
index 85969fc..4e95b14 100644 (file)
  */
 package jalview.ws.jws1;
 
-import java.util.*;
-
-import jalview.analysis.*;
-import jalview.bin.*;
-import jalview.datamodel.*;
-import jalview.gui.*;
-import jalview.io.*;
-import jalview.util.*;
+import jalview.analysis.AlignSeq;
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.WebserviceInfo;
+import jalview.io.FormatAdapter;
+import jalview.util.Comparison;
+import jalview.util.MessageManager;
 import jalview.ws.AWsJob;
 import jalview.ws.JobStateSummary;
 import jalview.ws.WSClientI;
+
+import java.util.Hashtable;
+import java.util.List;
+
 import vamsas.objects.simple.JpredResult;
 
 class JPredThread extends JWS1Thread implements WSClientI
@@ -138,14 +147,21 @@ class JPredThread extends JWS1Thread implements WSClientI
               sqs[i] = al.getSequenceAt(i);
             }
             if (!jalview.analysis.SeqsetUtils.deuniquify(
-                    (Hashtable) SequenceInfo, sqs))
+                    SequenceInfo, sqs))
             {
               throw (new Exception(MessageManager.getString("exception.couldnt_recover_sequence_properties_for_alignment")));
             }
           }
           FirstSeq = 0;
-          al.setDataset(null);
+          if (currentView.getDataset() != null)
+          {
+            al.setDataset(currentView.getDataset());
 
+          }
+          else
+          {
+            al.setDataset(null);
+          }
           jalview.io.JnetAnnotationMaker.add_annotation(prediction, al,
                   FirstSeq, false, predMap);
 
@@ -162,8 +178,8 @@ class JPredThread extends JWS1Thread implements WSClientI
         if (predMap != null)
         {
           char gc = getGapChar();
-          SequenceI[] sqs = (SequenceI[]) ((java.lang.Object[]) input
-                  .getAlignmentAndColumnSelection(gc))[0];
+          SequenceI[] sqs = (SequenceI[]) input
+                  .getAlignmentAndColumnSelection(gc)[0];
           if (this.msaIndex >= sqs.length)
           {
             throw new Error(MessageManager.getString("error.implementation_error_invalid_msa_index_for_job"));
@@ -187,7 +203,15 @@ class JPredThread extends JWS1Thread implements WSClientI
         }
         else
         {
-          al.setDataset(null);
+          if (currentView.getDataset() != null)
+          {
+            al.setDataset(currentView.getDataset());
+
+          }
+          else
+          {
+            al.setDataset(null);
+          }
           jalview.io.JnetAnnotationMaker.add_annotation(prediction, al,
                   FirstSeq, true, predMap);
           SequenceI profileseq = al.getSequenceAt(0); // this includes any gaps.
@@ -201,11 +225,53 @@ class JPredThread extends JWS1Thread implements WSClientI
           }
         }
       }
+      // transfer to dataset
+      for (AlignmentAnnotation alant : al.getAlignmentAnnotation())
+      {
+        if (alant.sequenceRef != null)
+        {
+          replaceAnnotationOnAlignmentWith(alant, alant.label,
+                  "jalview.jws1.Jpred" + (this.msa == null ? "" : "MSA"),
+                  alant.sequenceRef);
+        }
+      }
       return new Object[]
       { al, alcsel }; // , FirstSeq, noMsa};
     }
 
     /**
+     * copied from JabawsCalcWorker
+     * 
+     * @param newAnnot
+     * @param typeName
+     * @param calcId
+     * @param aSeq
+     */
+    protected void replaceAnnotationOnAlignmentWith(
+            AlignmentAnnotation newAnnot, String typeName, String calcId,
+            SequenceI aSeq)
+    {
+      SequenceI dsseq = aSeq.getDatasetSequence();
+      while (dsseq.getDatasetSequence() != null)
+      {
+        dsseq = dsseq.getDatasetSequence();
+      }
+      // look for same annotation on dataset and lift this one over
+      List<AlignmentAnnotation> dsan = dsseq.getAlignmentAnnotations(
+              calcId, typeName);
+      if (dsan != null && dsan.size() > 0)
+      {
+        for (AlignmentAnnotation dssan : dsan)
+        {
+          dsseq.removeAlignmentAnnotation(dssan);
+        }
+      }
+      AlignmentAnnotation dssan = new AlignmentAnnotation(newAnnot);
+      dsseq.addAlignmentAnnotation(dssan);
+      dssan.adjustForAlignment();
+    }
+
+    /**
      * Given an alignment where all other sequences except profileseq are
      * aligned to the ungapped profileseq, insert gaps in the other sequences to
      * realign them with the residues in profileseq
@@ -372,7 +438,7 @@ class JPredThread extends JWS1Thread implements WSClientI
       {
         if (job.getJobId().startsWith("Broken"))
         {
-          job.result = (vamsas.objects.simple.Result) new JpredResult();
+          job.result = new JpredResult();
           job.result.setInvalid(true);
           job.result.setStatus(MessageManager.formatMessage("label.submission_params", new String[]{job.getJobId().toString()}));
           throw new Exception(job.getJobId());