JAL-1587 propagate JPred annotation from legacy jpred service to the dataset
authorJim Procter <jprocter@dundee.ac.uk>
Mon, 17 Nov 2014 14:41:56 +0000 (14:41 +0000)
committerJim Procter <jprocter@dundee.ac.uk>
Mon, 17 Nov 2014 14:41:56 +0000 (14:41 +0000)
src/jalview/ws/jws1/JPredThread.java

index 85969fc..dc245ae 100644 (file)
@@ -144,8 +144,15 @@ class JPredThread extends JWS1Thread implements WSClientI
             }
           }
           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);
 
@@ -187,7 +194,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 +216,52 @@ 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", 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