JAL-1705 add xref seqs to 'parent' dataset only if same type (nuc/prot)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 Mar 2016 16:29:08 +0000 (16:29 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 Mar 2016 16:29:08 +0000 (16:29 +0000)
src/jalview/gui/AlignFrame.java

index 5438ce8..9e52fa3 100644 (file)
@@ -4748,7 +4748,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 break;
               }
             }
-            Alignment al = makeCrossReferencesAlignment(
+            AlignmentI al = makeCrossReferencesAlignment(
                     alignment.getDataset(), xrefs);
 
             AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
@@ -4896,31 +4896,45 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
 
       /**
-       * Makes an alignment containing the given sequences; the sequences are
-       * added to the given alignment dataset, and the dataset is set on (shared
-       * by) the new alignment
+       * Makes an alignment containing the given sequences. If this is of the
+       * same type as the given dataset (nucleotide/protein), then the new
+       * alignment shares the same dataset, and its dataset sequences are added
+       * to it. Otherwise a new dataset sequence is created for the
+       * cross-references.
        * 
        * @param dataset
        * @param seqs
        * @return
        */
-      protected Alignment makeCrossReferencesAlignment(Alignment dataset,
-              Alignment seqs)
+      protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
+              AlignmentI seqs)
       {
+        boolean sameType = dataset.isNucleotide() == seqs.isNucleotide();
+
         SequenceI[] sprods = new SequenceI[seqs.getHeight()];
         for (int s = 0; s < sprods.length; s++)
         {
           sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
-          if (dataset.getSequences() == null
-                  || !dataset.getSequences().contains(
-                          sprods[s].getDatasetSequence()))
+          if (sameType)
           {
-            dataset.addSequence(sprods[s].getDatasetSequence());
+            if (dataset.getSequences() == null
+                    || !dataset.getSequences().contains(
+                            sprods[s].getDatasetSequence()))
+            {
+              dataset.addSequence(sprods[s].getDatasetSequence());
+            }
           }
           sprods[s].updatePDBIds();
         }
         Alignment al = new Alignment(sprods);
-        al.setDataset(dataset);
+        if (sameType)
+        {
+          al.setDataset((Alignment) dataset);
+        }
+        else
+        {
+          al.createDatasetAlignment();
+        }
         return al;
       }