JAL-4134 map between column and node selections better (but not quite right still...
authorJames Procter <j.procter@dundee.ac.uk>
Mon, 22 May 2023 15:35:38 +0000 (16:35 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Mon, 22 May 2023 15:35:38 +0000 (16:35 +0100)
src/jalview/gui/TreeCanvas.java

index bb028bf..425f710 100755 (executable)
@@ -1109,12 +1109,33 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     }
     ColumnSelection cs = av.getColumnSelection();
     HiddenColumns hc = av.getAlignment().getHiddenColumns();
-    int offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
+    AlignmentAnnotation aa = tp.getAssocAnnotation();
+    int offp=-1;
+    if (aa != null)
+    {
+      ContactMatrixI cm = av.getContactMatrix(aa);
+      if (cm instanceof MappableContactMatrixI)
+      {
+        MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
+        int pos[]=mcm.getMappedPositionsFor(rseq, colm);
+        if (pos!=null)
+        {
+          offp=rseq.findIndex(pos[0])-1;
+        } else {
+          offp=-2;
+        }
+      }
+    }
+    if (offp==-1)
+    {
+      // assume a direct mapping to reference or column number
+        offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
             : colm;
+    }
 
     if (!av.hasHiddenColumns())
     {
-      return cs.contains(offp - 1);
+      return cs.contains(offp);
     }
     if (hc.isVisible(offp - 1))
     {
@@ -1191,7 +1212,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
           continue;
         }
         // TODO: handle ranges...
-        offp = seqpos[0];
+        offp = seqpos[0]-1;
       }
       else
       {