From 134057b8c18c9be3c77d830b96c396885db32c6c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 9 Sep 2015 12:33:38 +0100 Subject: [PATCH] JAL-1619 'align protein as cDNA' now leaves unmapped protein unchanged --- src/jalview/analysis/AlignmentUtils.java | 15 ++++++++++++--- test/jalview/analysis/AlignmentUtilsTests.java | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 1e259c2..3af4913 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -901,6 +901,9 @@ public class AlignmentUtils */ public static int alignProteinAsDna(AlignmentI protein, AlignmentI dna) { + List unmappedProtein = new ArrayList(); + unmappedProtein.addAll(protein.getSequences()); + Set 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> alignedCodons) + Map> alignedCodons, + List 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; diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 9c8e28c..d789cf2 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -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()); } /** -- 1.7.10.2