JAL-34 mouse over ruler in one alignment highlights location of aligned positions...
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 18 Jan 2024 10:08:17 +0000 (10:08 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 18 Jan 2024 10:08:17 +0000 (10:08 +0000)
src/jalview/gui/ScalePanel.java
src/jalview/util/MappingUtils.java

index 4a42861..ba71716 100755 (executable)
@@ -40,15 +40,23 @@ import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.ToolTipManager;
 
+import jalview.api.AlignViewportI;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceGroup;
 import jalview.renderer.ScaleRenderer;
 import jalview.renderer.ScaleRenderer.ScaleMark;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.ViewportListenerI;
 import jalview.viewmodel.ViewportRanges;
+import jalview.workers.AlignmentComparisonThread;
 
 /**
  * The panel containing the sequence ruler (when not in wrapped mode), and
@@ -392,6 +400,21 @@ public class ScalePanel extends JPanel
     final int res = ap.getSeqPanel().findAlignmentColumn(evt);
 
     highlightAllStructPos(res);
+    if (av.getCalcManager().getRegisteredWorkersOfClass(AlignmentComparisonThread.class)!=null)
+    {
+      AlignmentI alignment = av.getAlignment();
+      AlignViewportI codingComplement = av.getCodingComplement();
+      List<AlignedCodonFrame> ourMappings = alignment
+              .getCodonFrames();
+      SearchResultsI mappedPos = MappingUtils.allMappedRegionsForColumn(res,
+              ourMappings, alignment.getSequences(),codingComplement.getAlignment().getSequences(),
+               alignment.getGapCharacter());
+      if (mappedPos.getCount()>0)
+      {
+        Desktop.getAlignFrameFor(codingComplement).alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(mappedPos,true);
+      }
+      
+    }
     if (!av.hasHiddenColumns())
     {
       return;
index 8fd39ad..f437340 100644 (file)
@@ -689,6 +689,55 @@ public final class MappingUtils
     }
     return found ? mappedTo : null;
   }
+  
+  public static SearchResultsI allMappedRegionsForColumn(int col,List<AlignedCodonFrame> mappings, List<SequenceI> fromSequences,
+          List<SequenceI> toSequences, char fromGapChar)
+  {
+    int[] mappedTo = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE };
+
+    SearchResultsI allsr=new SearchResults();
+    /*
+     * For each sequence in the 'from' alignment
+     */
+    for (SequenceI fromSeq : fromSequences)
+    {
+      /*
+       * Ignore gaps (unmapped anyway)
+       */
+      if (fromSeq.getCharAt(col) == fromGapChar)
+      {
+        continue;
+      }
+
+      /*
+       * Get the residue position and find the mapped position.
+       */
+      int residuePos = fromSeq.findPosition(col);
+      SearchResultsI sr = buildSearchResults(fromSeq, residuePos, mappings);
+      
+      for (SearchResultMatchI m : sr.getResults())
+      {
+        int mappedStartResidue = m.getStart();
+        int mappedEndResidue = m.getEnd();
+        SequenceI mappedSeq = m.getSequence();
+
+        /*
+         * Locate the aligned sequence whose dataset is mappedSeq. TODO a
+         * datamodel that can do this efficiently.
+         */
+        for (SequenceI toSeq : toSequences)
+        {
+          if (toSeq.getDatasetSequence() == mappedSeq
+                  && mappedStartResidue >= toSeq.getStart()
+                  && mappedEndResidue <= toSeq.getEnd())
+          {
+            allsr.addResult(toSeq, new int[] { mappedStartResidue,mappedEndResidue});
+          }
+        }
+      }
+    }
+    return allsr;
+  }
 
   /**
    * Returns the mapped codon or codons for a given aligned sequence column