JAL-1619 'align protein as cDNA' now leaves unmapped protein unchanged
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 9 Sep 2015 11:33:38 +0000 (12:33 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 9 Sep 2015 11:33:38 +0000 (12:33 +0100)
src/jalview/analysis/AlignmentUtils.java
test/jalview/analysis/AlignmentUtilsTests.java

index 1e259c2..3af4913 100644 (file)
@@ -901,6 +901,9 @@ public class AlignmentUtils
    */
   public static int alignProteinAsDna(AlignmentI protein, AlignmentI dna)
   {
+    List<SequenceI> unmappedProtein = new ArrayList<SequenceI>();
+    unmappedProtein.addAll(protein.getSequences());
+
     Set<AlignedCodonFrame> mappings = protein.getCodonFrames();
 
     /*
@@ -921,10 +924,11 @@ public class AlignmentUtils
         {
           addCodonPositions(dnaSeq, prot, protein.getGapCharacter(),
                   seqMap, alignedCodons);
+          unmappedProtein.remove(prot);
         }
       }
     }
-    return alignProteinAs(protein, alignedCodons);
+    return alignProteinAs(protein, alignedCodons, unmappedProtein);
   }
 
   /**
@@ -935,10 +939,12 @@ public class AlignmentUtils
    * @param alignedCodons
    *          an ordered map of codon positions (columns), with sequence/peptide
    *          values present in each column
+   * @param unmappedProtein
    * @return
    */
   protected static int alignProteinAs(AlignmentI protein,
-          Map<AlignedCodon, Map<SequenceI, String>> alignedCodons)
+          Map<AlignedCodon, Map<SequenceI, String>> alignedCodons,
+          List<SequenceI> unmappedProtein)
   {
     /*
      * Prefill aligned sequences with gaps before inserting aligned protein
@@ -950,7 +956,10 @@ public class AlignmentUtils
     String allGaps = String.valueOf(gaps);
     for (SequenceI seq : protein.getSequences())
     {
-      seq.setSequence(allGaps);
+      if (!unmappedProtein.contains(seq))
+      {
+        seq.setSequence(allGaps);
+      }
     }
 
     int column = 0;
index 9c8e28c..d789cf2 100644 (file)
@@ -547,8 +547,10 @@ public class AlignmentUtilsTests
     SequenceI prot1 = new Sequence("Seq1", "CHYQ");
     SequenceI prot2 = new Sequence("Seq2", "CHYQ");
     SequenceI prot3 = new Sequence("Seq3", "CHYQ");
+    SequenceI prot4 = new Sequence("Seq4", "R-QSV"); // unmapped, unchanged
     AlignmentI protein = new Alignment(new SequenceI[]
-    { prot1, prot2, prot3 });
+ { prot1, prot2,
+        prot3, prot4 });
     protein.setDataset(null);
 
     MapList map = new MapList(new int[]
@@ -568,6 +570,7 @@ public class AlignmentUtilsTests
     assertEquals("C-H--Y-Q-", prot1.getSequenceAsString());
     assertEquals("-C--H-Y-Q", prot2.getSequenceAsString());
     assertEquals("C--H--Y-Q", prot3.getSequenceAsString());
+    assertEquals("R-QSV", prot4.getSequenceAsString());
   }
 
   /**