From c51a54a28c41171770462a417afa0a3fb26e10ce Mon Sep 17 00:00:00 2001 From: James Procter Date: Thu, 18 Jan 2024 10:08:17 +0000 Subject: [PATCH] JAL-34 mouse over ruler in one alignment highlights location of aligned positions in the other alignment. Really notice a need to allow those positions to be persisted without ultraprecise mouse control --- src/jalview/gui/ScalePanel.java | 23 +++++++++++++++++ src/jalview/util/MappingUtils.java | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 4a42861..ba71716 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -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 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; diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 8fd39ad..f437340 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -689,6 +689,55 @@ public final class MappingUtils } return found ? mappedTo : null; } + + public static SearchResultsI allMappedRegionsForColumn(int col,List mappings, List fromSequences, + List 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 -- 1.7.10.2