JAL-34 mouse over ruler in one alignment highlights location of aligned positions...
[jalview.git] / src / jalview / util / MappingUtils.java
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