JAL-1705 refine feature copying to including 5' and 3' overlaps
[jalview.git] / src / jalview / ext / ensembl / EnsemblSeqProxy.java
index e241874..cbeaae9 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ext.ensembl;
 
+import jalview.analysis.AlignmentUtils;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
@@ -847,7 +848,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       peptide = peptide.getDatasetSequence();
     }
   
-    mapExonFeaturesToProtein(dnaSeq, peptide, dnaToProtein);
+    AlignmentUtils.transferFeatures(dnaSeq, peptide, dnaToProtein,
+            SequenceOntology.EXON);
 
     LinkedHashMap<Integer, String[][]> variants = buildDnaVariantsMap(
             dnaSeq, dnaToProtein);
@@ -878,47 +880,6 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
   }
 
   /**
-   * Transfers exon features to the corresponding mapped regions of the protein
-   * sequence. This is useful because it allows visualisation of exon boundaries
-   * on the peptide (using 'colour by label' for the exon name). Returns the
-   * number of features written.
-   * 
-   * @param dnaSeq
-   * @param peptide
-   * @param dnaToProtein
-   */
-  static int mapExonFeaturesToProtein(SequenceI dnaSeq, SequenceI peptide,
-          MapList dnaToProtein)
-  {
-    SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
-    if (sfs == null)
-    {
-      return 0;
-    }
-
-    SequenceOntology so = SequenceOntology.getInstance();
-    int count = 0;
-
-    for (SequenceFeature sf : sfs)
-    {
-      if (so.isA(sf.getType(), SequenceOntology.EXON))
-      {
-        int start = sf.getBegin();
-        int end = sf.getEnd();
-        int[] mapsTo = dnaToProtein.locateInTo(start, end);
-        if (mapsTo != null)
-        {
-          SequenceFeature copy = new SequenceFeature(SequenceOntology.EXON,
-                  sf.getDescription(), mapsTo[0], mapsTo[1], 0f, null);
-          peptide.addSequenceFeature(copy);
-          count++;
-        }
-      }
-    }
-    return count;
-  }
-
-  /**
    * Builds a map whose key is position in the protein sequence, and value is an
    * array of all variants for the coding codon positions
    *