JAL-2049 use HGVS notation for variant on protein residue
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 18 May 2016 12:09:50 +0000 (13:09 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 18 May 2016 12:09:50 +0000 (13:09 +0100)
src/jalview/analysis/AlignmentUtils.java
src/jalview/util/StringUtils.java
test/jalview/util/StringUtilsTest.java

index 42a1201..92753b9 100644 (file)
@@ -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,
index 1c9d7b7..ccc2012 100644 (file)
@@ -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();
+  }
 }
index d072cc6..4dc44d4 100644 (file)
@@ -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));
+  }
 }