From b53d11f22f9c5db694835ba27490e7c19671872d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 25 Feb 2019 13:46:27 +0000 Subject: [PATCH] JAL-3200 fast lookup of DSSP3 notation --- src/jalview/schemes/ResidueProperties.java | 48 ++++++++++++----------- test/jalview/schemes/ResiduePropertiesTest.java | 10 +++++ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index a4e6480..18b11c1 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -1156,47 +1156,51 @@ public class ResidueProperties return cdn; } - public static Hashtable toDssp3State; + /* + * lookup of (A-Z) alternative secondary structure symbols' + * equivalents in DSSP3 notation + */ + private static char[] toDssp3State; static { - toDssp3State = new Hashtable<>(); - toDssp3State.put("H", "H"); - toDssp3State.put("E", "E"); - toDssp3State.put("C", " "); - toDssp3State.put(" ", " "); - toDssp3State.put("T", " "); - toDssp3State.put("B", "E"); - toDssp3State.put("G", "H"); - toDssp3State.put("I", "H"); - toDssp3State.put("X", " "); + toDssp3State = new char[9]; // for 'A'-'I'; extend if needed + Arrays.fill(toDssp3State, ' '); + toDssp3State['B' - 'A'] = 'E'; + toDssp3State['E' - 'A'] = 'E'; + toDssp3State['G' - 'A'] = 'H'; + toDssp3State['H' - 'A'] = 'H'; + toDssp3State['I' - 'A'] = 'H'; } /** * translate from other dssp secondary structure alphabets to 3-state * - * @param ssstring - * @return ssstring as a three-state secondary structure assignment. + * @param ssString + * @return ssstring */ - public static String getDssp3state(String ssstring) + public static String getDssp3state(String ssString) { - if (ssstring == null) + if (ssString == null) { return null; } - StringBuffer ss = new StringBuffer(); - for (int i = 0; i < ssstring.length(); i++) + int lookupSize = toDssp3State.length; + int len = ssString.length(); + char[] trans = new char[len]; + for (int i = 0; i < len; i++) { - String ssc = ssstring.substring(i, i + 1); - if (toDssp3State.containsKey(ssc)) + char c = ssString.charAt(i); + int index = c - 'A'; + if (index < 0 || index >= lookupSize) { - ss.append(toDssp3State.get(ssc)); + trans[i] = ' '; } else { - ss.append(" "); + trans[i] = toDssp3State[index]; } } - return ss.toString(); + return new String(trans); } static diff --git a/test/jalview/schemes/ResiduePropertiesTest.java b/test/jalview/schemes/ResiduePropertiesTest.java index 7fbad50..180deaf 100644 --- a/test/jalview/schemes/ResiduePropertiesTest.java +++ b/test/jalview/schemes/ResiduePropertiesTest.java @@ -1569,6 +1569,16 @@ public class ResiduePropertiesTest } @Test(groups = { "Functional" }) + public void testGetDssp3State() + { + assertNull(ResidueProperties.getDssp3state(null)); + assertEquals("", ResidueProperties.getDssp3state("")); + String foo = "0123 []<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String bar = " E E HHH "; + assertEquals(bar, ResidueProperties.getDssp3state(foo)); + } + + @Test(groups = { "Functional" }) public void testPhysicoChemicalProperties() { checkProperty("aromatic", "FYWH-*"); -- 1.7.10.2