JAL-1950 JAL-2937 allow copy of group without sequences being also copied to cloned...
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index b558f40..cffe0d9 100755 (executable)
@@ -198,11 +198,27 @@ public class SequenceGroup implements AnnotatedCollectionI
    */
   public SequenceGroup(SequenceGroup seqsel)
   {
+    this(seqsel, true);
+  }
+
+  /**
+   * copy constructor
+   * 
+   * @param seqsel
+   * @param keepsequences
+   *          if false do not add sequences from seqsel to new instance
+   */
+  public SequenceGroup(SequenceGroup seqsel, boolean keepsequences)
+  {
     this();
+
     if (seqsel != null)
     {
       sequences = new ArrayList<>();
-      sequences.addAll(seqsel.sequences);
+      if (keepsequences)
+      {
+        sequences.addAll(seqsel.sequences);
+      }
       if (seqsel.groupName != null)
       {
         groupName = new String(seqsel.groupName);
@@ -236,8 +252,10 @@ public class SequenceGroup implements AnnotatedCollectionI
       ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
       hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
       hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
-      if (seqsel.conservationData != null)
+      if (keepsequences && seqsel.conservationData != null)
       {
+        // todo avoid doing this if we don't actually want derived calculations
+        // !
         recalcConservation(); // safer than
         // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
       }
@@ -262,7 +280,8 @@ public class SequenceGroup implements AnnotatedCollectionI
     return showSequenceLogo;
   }
 
-  public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
+  public SequenceI[] getSelectionAsNewSequences(AlignmentI align,
+          boolean copyAnnotation)
   {
     int iSize = sequences.size();
     SequenceI[] seqs = new SequenceI[iSize];
@@ -276,14 +295,8 @@ public class SequenceGroup implements AnnotatedCollectionI
       if (seqs[ipos] != null)
       {
         seqs[ipos].setDescription(seq.getDescription());
-        seqs[ipos].setDBRefs(seq.getDBRefs());
-        seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
-        if (seq.getDatasetSequence() != null)
-        {
-          seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
-        }
 
-        if (seq.getAnnotation() != null)
+        if (seq.getAnnotation() != null && copyAnnotation)
         {
           AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
           // Only copy annotation that is either a score or referenced by the