From: gmungoc Date: Wed, 18 May 2016 12:09:50 +0000 (+0100) Subject: JAL-2049 use HGVS notation for variant on protein residue X-Git-Tag: Release_2_10_0~220^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=13e9dc5c4c6b9b343c5bc2bcef49d54a296f03f5;p=jalview.git JAL-2049 use HGVS notation for variant on protein residue --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 42a1201..92753b9 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -40,6 +40,7 @@ import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MapList; import jalview.util.MappingUtils; +import jalview.util.StringUtils; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -1927,7 +1928,11 @@ public class AlignmentUtils .codonTranslate(codon)); if (trans != null && !trans.equals(residue)) { - String desc = residue + "->" + trans; + String residue3Char = StringUtils + .toSentenceCase(ResidueProperties.aa2Triplet.get(residue)); + String trans3Char = StringUtils + .toSentenceCase(ResidueProperties.aa2Triplet.get(trans)); + String desc = "p." + residue3Char + peptidePos + trans3Char; // set score to 0f so 'graduated colour' option is offered! JAL-2060 SequenceFeature sf = new SequenceFeature( SequenceOntologyI.SEQUENCE_VARIANT, desc, peptidePos, diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java index 1c9d7b7..ccc2012 100644 --- a/src/jalview/util/StringUtils.java +++ b/src/jalview/util/StringUtils.java @@ -383,4 +383,24 @@ public class StringUtils */ return 0; } + + /** + * Converts the string to all lower-case except the first character which is + * upper-cased + * + * @param s + * @return + */ + public static String toSentenceCase(String s) + { + if (s == null) + { + return s; + } + if (s.length() <= 1) + { + return s.toUpperCase(); + } + return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); + } } diff --git a/test/jalview/util/StringUtilsTest.java b/test/jalview/util/StringUtilsTest.java index d072cc6..4dc44d4 100644 --- a/test/jalview/util/StringUtilsTest.java +++ b/test/jalview/util/StringUtilsTest.java @@ -206,4 +206,16 @@ public class StringUtilsTest assertEquals(1, StringUtils.compareVersions("12", "2")); assertEquals(1, StringUtils.compareVersions("3.12.11", "3.2.4")); } + + @Test(groups = { "Functional" }) + public void testToSentenceCase() + { + assertEquals("John", StringUtils.toSentenceCase("john")); + assertEquals("John", StringUtils.toSentenceCase("JOHN")); + assertEquals("John and james", + StringUtils.toSentenceCase("JOHN and JAMES")); + assertEquals("J", StringUtils.toSentenceCase("j")); + assertEquals("", StringUtils.toSentenceCase("")); + assertNull(StringUtils.toSentenceCase(null)); + } }