JAL-4028 experiment - THISISAPLACEHOLDER sequences get additional sequence data ...
[jalview.git] / src / jalview / datamodel / Sequence.java
index e0a9d35..1563dff 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.analysis.AlignSeq;
-import jalview.datamodel.features.SequenceFeatures;
-import jalview.datamodel.features.SequenceFeaturesI;
-import jalview.util.Comparison;
-import jalview.util.DBRefUtils;
-import jalview.util.MapList;
-import jalview.util.StringUtils;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -39,6 +31,13 @@ import java.util.ListIterator;
 import java.util.Vector;
 
 import fr.orsay.lri.varna.models.rna.RNA;
+import jalview.analysis.AlignSeq;
+import jalview.datamodel.features.SequenceFeatures;
+import jalview.datamodel.features.SequenceFeaturesI;
+import jalview.util.Comparison;
+import jalview.util.DBRefUtils;
+import jalview.util.MapList;
+import jalview.util.StringUtils;
 
 /**
  * 
@@ -523,6 +522,7 @@ public class Sequence extends ASequence implements SequenceI
   public void setStart(int start)
   {
     this.start = start;
+    sequenceChanged();
   }
 
   /**
@@ -1414,6 +1414,7 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public void addDBRef(DBRefEntry entry)
   {
+    // TODO JAL-3980 maintain as sorted list
     if (datasetSequence != null)
     {
       datasetSequence.addDBRef(entry);
@@ -1424,6 +1425,7 @@ public class Sequence extends ASequence implements SequenceI
     {
       dbrefs = new DBModList<>();
     }
+    // TODO JAL-3979 LOOK UP RATHER THAN SWEEP FOR EFFICIENCY
 
     for (int ib = 0, nb = dbrefs.size(); ib < nb; ib++)
     {
@@ -1599,33 +1601,46 @@ public class Sequence extends ASequence implements SequenceI
               getStart(), getEnd());
 
       datasetSequence = dsseq;
+      updateDatasetFrom(dsseq, this);
+    }
+    return datasetSequence;
+  }
 
-      dsseq.setDescription(description);
-      // move features and database references onto dataset sequence
-      dsseq.sequenceFeatureStore = sequenceFeatureStore;
-      sequenceFeatureStore = null;
-      dsseq.dbrefs = dbrefs;
-      dbrefs = null;
-      // TODO: search and replace any references to this sequence with
-      // references to the dataset sequence in Mappings on dbref
-      dsseq.pdbIds = pdbIds;
-      pdbIds = null;
-      datasetSequence.updatePDBIds();
-      if (annotation != null)
+  /**
+   * used by createDatasetSequence - transfers dataset-only properties to dsseq
+   * from sequence2
+   * 
+   * @param dsseq
+   *          - newly created dataset sequenceI for sequence
+   * @param sequence2
+   *          - sequence object that needs a dataset
+   */
+  protected void updateDatasetFrom(Sequence dsseq, Sequence sequence2)
+  {
+    dsseq.setDescription(description);
+    // move features and database references onto dataset sequence
+    dsseq.sequenceFeatureStore = sequenceFeatureStore;
+    sequenceFeatureStore = null;
+    dsseq.dbrefs = dbrefs;
+    dbrefs = null;
+    // TODO: search and replace any references to this sequence with
+    // references to the dataset sequence in Mappings on dbref
+    dsseq.pdbIds = pdbIds;
+    pdbIds = null;
+    datasetSequence.updatePDBIds();
+    if (annotation != null)
+    {
+      // annotation is cloned rather than moved, to preserve what's currently
+      // on the alignment
+      for (AlignmentAnnotation aa : annotation)
       {
-        // annotation is cloned rather than moved, to preserve what's currently
-        // on the alignment
-        for (AlignmentAnnotation aa : annotation)
-        {
-          AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
-          _aa.sequenceRef = datasetSequence;
-          _aa.adjustForAlignment(); // uses annotation's own record of
-                                    // sequence-column mapping
-          datasetSequence.addAlignmentAnnotation(_aa);
-        }
+        AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
+        _aa.sequenceRef = datasetSequence;
+        _aa.adjustForAlignment(); // uses annotation's own record of
+                                  // sequence-column mapping
+        datasetSequence.addAlignmentAnnotation(_aa);
       }
     }
-    return datasetSequence;
   }
 
   /*
@@ -1798,13 +1813,30 @@ public class Sequence extends ASequence implements SequenceI
   public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
           String label)
   {
+    return getAlignmentAnnotations(calcId, label, null, true);
+  }
+
+  @Override
+  public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
+          String label, String description)
+  {
+    return getAlignmentAnnotations(calcId, label, description, false);
+  }
+
+  private List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
+          String label, String description, boolean ignoreDescription)
+  {
     List<AlignmentAnnotation> result = new ArrayList<>();
     if (this.annotation != null)
     {
       for (AlignmentAnnotation ann : annotation)
       {
-        if (ann.calcId != null && ann.calcId.equals(calcId)
-                && ann.label != null && ann.label.equals(label))
+        if ((ann.calcId != null && ann.calcId.equals(calcId))
+                && (ann.label != null && ann.label.equals(label))
+                && ((ignoreDescription && description == null)
+                        || (ann.description != null
+                                && ann.description.equals(description))))
+
         {
           result.add(ann);
         }