From 4099019578bbeb81b76154922851ada38fb0017d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 7 Sep 2015 15:34:58 +0100 Subject: [PATCH] JAL-1636 translate stop codon as '*', mouseover * as STOP --- src/jalview/analysis/AlignmentUtils.java | 4 ++-- src/jalview/analysis/Dna.java | 16 +++++++-------- src/jalview/appletgui/SeqPanel.java | 5 +++-- src/jalview/gui/SeqPanel.java | 5 +++-- src/jalview/schemes/ResidueProperties.java | 2 +- test/jalview/analysis/AlignmentUtilsTests.java | 25 +++++++++++++++++------- test/jalview/analysis/DnaTest.java | 4 ++-- 7 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index f9d4c08..1e259c2 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -461,10 +461,10 @@ public class AlignmentUtils final String translated = ResidueProperties.codonTranslate( codon); /* - * ? allow X in protein to match untranslatable in dna ? + * allow * in protein to match untranslatable in dna */ final char aaRes = aaSeqChars[aaResidue]; - if ((translated == null || "STOP".equals(translated)) && aaRes == 'X') + if ((translated == null || "STOP".equals(translated)) && aaRes == '*') { continue; } diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index 1d5f996..5696838 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -20,12 +20,6 @@ */ package jalview.analysis; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - import jalview.api.AlignViewportI; import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; @@ -47,9 +41,15 @@ import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.ShiftList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + public class Dna { - private static final String STOP_X = "X"; + private static final String STOP_ASTERIX = "*"; private static final Comparator comparator = new CodonComparator(); @@ -544,7 +544,7 @@ public class Dna } if (aa.equals("STOP")) { - aa = STOP_X; + aa = STOP_ASTERIX; } resSize++; } diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 10db71a..4dd131a 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -432,8 +432,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - residue = "X".equalsIgnoreCase(displayChar) ? "X" - : ResidueProperties.aa2Triplet.get(displayChar); + residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*" + .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet + .get(displayChar)); if (residue != null) { text.append(" Residue: ").append(residue); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 44b537b..01653b6 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -856,8 +856,9 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - residue = "X".equalsIgnoreCase(displayChar) ? "X" - : ResidueProperties.aa2Triplet.get(displayChar); + residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*" + .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet + .get(displayChar)); if (residue != null) { text.append(" Residue: ").append(residue); diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 209fe12..ce83875 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -1509,7 +1509,7 @@ public class ResidueProperties return _codonTranslate(lccodon); } String cdn = codonHash2.get(lccodon.toUpperCase()); - if (cdn != null && cdn.equals("*")) + if ("*".equals(cdn)) { return "STOP"; } diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 6fef829..9c8e28c 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -579,27 +579,38 @@ public class AlignmentUtilsTests { assertTrue(AlignmentUtils.translatesAs("tttcccaaaggg".toCharArray(), 0, "FPKG".toCharArray())); - // with start codon + // with start codon (not in protein) assertTrue(AlignmentUtils.translatesAs("atgtttcccaaaggg".toCharArray(), 3, "FPKG".toCharArray())); - // with stop codon1 + // with stop codon1 (not in protein) assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtaa".toCharArray(), 0, "FPKG".toCharArray())); - // with stop codon2 + // with stop codon1 (in protein as *) + assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtaa".toCharArray(), + 0, "FPKG*".toCharArray())); + // with stop codon2 (not in protein) assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtag".toCharArray(), 0, "FPKG".toCharArray())); - // with stop codon3 + // with stop codon3 (not in protein) assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtga".toCharArray(), 0, "FPKG".toCharArray())); // with start and stop codon1 assertTrue(AlignmentUtils.translatesAs( - "atgtttcccaaaggtaa".toCharArray(), 3, "FPKG".toCharArray())); + "atgtttcccaaagggtaa".toCharArray(), 3, "FPKG".toCharArray())); + // with start and stop codon1 (in protein as *) + assertTrue(AlignmentUtils.translatesAs( + "atgtttcccaaagggtaa".toCharArray(), 3, "FPKG*".toCharArray())); // with start and stop codon2 assertTrue(AlignmentUtils.translatesAs( - "atgtttcccaaaggtag".toCharArray(), 3, "FPKG".toCharArray())); + "atgtttcccaaagggtag".toCharArray(), 3, "FPKG".toCharArray())); // with start and stop codon3 assertTrue(AlignmentUtils.translatesAs( - "atgtttcccaaaggtga".toCharArray(), 3, "FPKG".toCharArray())); + "atgtttcccaaagggtga".toCharArray(), 3, "FPKG".toCharArray())); + + // with embedded stop codon + assertTrue(AlignmentUtils.translatesAs( + "atgtttTAGcccaaaTAAgggtga".toCharArray(), 3, + "F*PK*G".toCharArray())); // wrong protein assertFalse(AlignmentUtils.translatesAs("tttcccaaaggg".toCharArray(), diff --git a/test/jalview/analysis/DnaTest.java b/test/jalview/analysis/DnaTest.java index 55908dd..765ec2b 100644 --- a/test/jalview/analysis/DnaTest.java +++ b/test/jalview/analysis/DnaTest.java @@ -148,7 +148,7 @@ public class DnaTest } /** - * Test simple translation to Amino Acids (with STOP codons translated to X). + * Test simple translation to Amino Acids (with STOP codons translated to *). * * @throws IOException */ @@ -164,7 +164,7 @@ public class DnaTest AlignmentI translated = dna.translateCdna(); String aa = translated.getSequenceAt(0).getSequenceAsString(); assertEquals( - "AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYYXXX", + "AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYY***", aa); } -- 1.7.10.2