JAL-3187 basic first version for tooltips only (rendering yet to do)
[jalview.git] / src / jalview / gui / FeatureRenderer.java
index 46f574e..c2a84c6 100644 (file)
@@ -21,6 +21,9 @@
 package jalview.gui;
 
 import jalview.api.FeatureColourI;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.Mapping;
+import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceFeature;
@@ -574,4 +577,49 @@ public class FeatureRenderer
   {
     Arrays.sort(renderOrder, order);
   }
+
+  /**
+   * Answers a (possibly empty) list of features in this alignment at a position
+   * (or range) which is mappable from the given sequence residue position in a
+   * mapped alignment.
+   * 
+   * @param sequence
+   * @param pos
+   * @return
+   */
+  public List<SequenceFeature> findComplementFeaturesAtResidue(
+          SequenceI sequence, int pos)
+  {
+    SequenceI ds = sequence.getDatasetSequence();
+    List<SequenceFeature> result = new ArrayList<>();
+    List<AlignedCodonFrame> mappings = this.av.getAlignment()
+            .getCodonFrame(sequence);
+    for (AlignedCodonFrame acf : mappings)
+    {
+      Mapping mapping = acf.getMappingForSequence(sequence);
+      if (mapping.getMap().getFromRatio() == mapping.getMap().getToRatio())
+      {
+        continue; // we are only looking for 3:1 or 1:3 mappings
+      }
+      SearchResultsI sr = new SearchResults();
+      acf.markMappedRegion(ds, pos, sr);
+      for (SearchResultMatchI match : sr.getResults())
+      {
+        for (int i = match.getStart(); i <= match.getEnd(); i++)
+        {
+          List<SequenceFeature> fs = findFeaturesAtResidue(
+                  match.getSequence(), i);
+          for (SequenceFeature sf : fs)
+          {
+            if (!result.contains(sf))
+            {
+              result.addAll(fs);
+            }
+          }
+        }
+      }
+    }
+    
+    return result;
+  }
 }