Merge branch 'develop' into feature/JAL-3390hideUnmappedStructure
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index 77cc4d6..8e0335f 100644 (file)
@@ -22,6 +22,7 @@ package jalview.analysis;
 
 import static jalview.io.gff.GffConstants.CLINICAL_SIGNIFICANCE;
 
+import jalview.commands.RemoveGapColCommand;
 import jalview.datamodel.AlignedCodon;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
@@ -2440,17 +2441,17 @@ public class AlignmentUtils
   }
 
   /**
-   * Computes non-synonymous peptide variants from codon variants and adds them
-   * as sequence_variant features on the protein sequence (one feature per
-   * allele variant). Selected attributes (variant id, clinical significance)
-   * are copied over to the new features.
+   * Computes non-synonymous peptide variants from codon variants and adds them as
+   * sequence_variant features on the protein sequence (one feature per allele
+   * variant). Selected attributes (variant id, clinical significance) are copied
+   * over to the new features.
    * 
    * @param peptide
-   *          the protein sequence
+   *                        the protein dataset (ungapped) sequence
    * @param peptidePos
-   *          the position to compute peptide variants for
+   *                        the position to compute peptide variants for
    * @param codonVariants
-   *          a list of dna variants per codon position
+   *                        a list of dna variants per codon position
    * @return the number of features added
    */
   static int computePeptideVariants(SequenceI peptide, int peptidePos,
@@ -2837,6 +2838,17 @@ public class AlignmentUtils
    */
   public static int alignAs(AlignmentI unaligned, AlignmentI aligned)
   {
+    /*
+     * easy case - aligning a copy of aligned sequences
+     */
+    if (alignAsSameSequences(unaligned, aligned))
+    {
+      return unaligned.getHeight();
+    }
+
+    /*
+     * fancy case - aligning via mappings between sequences
+     */
     List<SequenceI> unmapped = new ArrayList<>();
     Map<Integer, Map<SequenceI, Character>> columnMap = buildMappedColumnsMap(
             unaligned, aligned, unmapped);
@@ -2902,9 +2914,7 @@ public class AlignmentUtils
    *                    - 'guide' alignment containing sequences derived from same
    *                    dataset as unaligned
    * @return
-   * @deprecated probably obsolete and incomplete
    */
-  @Deprecated
   static boolean alignAsSameSequences(AlignmentI unaligned,
           AlignmentI aligned)
   {
@@ -2975,6 +2985,12 @@ public class AlignmentUtils
       }
     }
 
+    /*
+     * finally remove gapped columns (e.g. introns)
+     */
+    new RemoveGapColCommand("", unaligned.getSequencesArray(), 0,
+            unaligned.getWidth() - 1, unaligned);
+
     return true;
   }