JAL-2144 TODO - new methods for canonicalisation and comparison of source strings...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 5dba850..891fdd6 100644 (file)
@@ -473,7 +473,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       @Override
       public void focusGained(FocusEvent e)
       {
-        Desktop.setCurrentAlignFrame(AlignFrame.this);
+        Jalview.setCurrentAlignFrame(AlignFrame.this);
       }
     });
 
@@ -4651,7 +4651,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       final boolean dna = viewport.getAlignment().isNucleotide();
       List<String> ptypes = (seqs == null || seqs.length == 0) ? null
               : new CrossRef(seqs, dataset)
-                      .findXrefSourcesForSequences();
+                      .findXrefSourcesForSequences(dna);
 
       for (final String source : ptypes)
       {
@@ -4691,7 +4691,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param source
    *          the database to show cross-references for
    */
-  protected void showProductsFor(final SequenceI[] sel, final boolean dna,
+  protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
           final String source)
   {
     Runnable foo = new Runnable()
@@ -4710,8 +4710,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   .getAlignment();
           AlignmentI dataset = alignment.getDataset() == null ? alignment
                   : alignment.getDataset();
-          AlignmentI xrefs = new CrossRef(sel, alignment)
-                  .findXrefSequences(source);
+          boolean dna = alignment.isNucleotide();
+          if (_odna!=dna)
+          {
+            System.err
+                    .println("Conflict: showProducts for alignment originally "
+                            + "thought to be "
+                            + (_odna ? "DNA" : "Protein")
+                            + " now searching for "
+                            + (dna ? "DNA" : "Protein") + " Context.");
+          }
+          AlignmentI xrefs = new CrossRef(sel, dataset)
+                  .findXrefSequences(source, dna);
           if (xrefs == null)
           {
             return;
@@ -4724,6 +4734,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
           AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset,
                   xrefs);
+          if (!dna)
+          {
+            xrefsAlignment = AlignmentUtils.makeCdsAlignment(
+                    xrefsAlignment.getSequencesArray(), dataset, sel);
+            xrefsAlignment.alignAs(alignment);
+          }
 
           AlignFrame newFrame = new AlignFrame(xrefsAlignment, DEFAULT_WIDTH,
                   DEFAULT_HEIGHT);
@@ -4751,14 +4767,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
            * sequences). If we are DNA, drop introns and update mappings
            */
           AlignmentI copyAlignment = null;
-          final SequenceI[] sequenceSelection = AlignFrame.this.viewport
-                  .getSequenceSelection();
-          // List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
           boolean copyAlignmentIsAligned = false;
           if (dna)
           {
-            copyAlignment = AlignmentUtils.makeCdsAlignment(
-                    sequenceSelection, dataset);
+            copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
+                    xrefsAlignment.getSequencesArray());
             if (copyAlignment.getHeight() == 0)
             {
               System.err.println("Failed to make CDS alignment");
@@ -4778,8 +4791,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else
           {
-            copyAlignment = AlignmentUtils.makeCopyAlignment(
-                    sequenceSelection, xrefs.getSequencesArray());
+            copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
+                    xrefs.getSequencesArray(), dataset);
           }
           copyAlignment.setGapCharacter(AlignFrame.this.viewport
                   .getGapCharacter());
@@ -4812,7 +4825,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * align cdna to protein - currently only if 
              * fetching and aligning Ensembl transcripts!
              */
-            if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
+            // TODO: generalise for other sources of locus/transcript/cds data
+            if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
             {
               copyAlignment.alignAs(xrefsAlignment);
             }
@@ -4871,6 +4885,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
        * Makes an alignment containing the given sequences, and adds them to the
        * given dataset, which is also set as the dataset for the new alignment
        * 
+       * TODO: refactor to DatasetI method
+       * 
        * @param dataset
        * @param seqs
        * @return
@@ -4891,7 +4907,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           sprods[s].updatePDBIds();
         }
         Alignment al = new Alignment(sprods);
-        al.setDataset((Alignment) dataset);
+        al.setDataset(dataset);
         return al;
       }
 
@@ -5940,8 +5956,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void setAnnotationsVisibility(boolean visible,
           boolean forSequences, boolean forAlignment)
   {
-    for (AlignmentAnnotation aa : alignPanel.getAlignment()
-            .getAlignmentAnnotation())
+    AlignmentAnnotation[] anns = alignPanel.getAlignment()
+            .getAlignmentAnnotation();
+    if (anns == null)
+    {
+      return;
+    }
+    for (AlignmentAnnotation aa : anns)
     {
       /*
        * don't display non-positional annotations on an alignment
@@ -6078,7 +6099,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void runGroovy_actionPerformed()
   {
-    Desktop.setCurrentAlignFrame(this);
+    Jalview.setCurrentAlignFrame(this);
     groovy.ui.Console console = Desktop.getGroovyConsole();
     if (console != null)
     {