From: TZVanaalten Date: Tue, 18 Jul 2017 10:01:18 +0000 (+0100) Subject: JAL-2599 modified state transition probability storage X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5c0ff498481786fc5fd2ecf359d6b65f82adaa3a;p=jalview.git JAL-2599 modified state transition probability storage --- diff --git a/src/jalview/datamodel/HMMNode.java b/src/jalview/datamodel/HMMNode.java index 30a6a8d..cf95a1b 100644 --- a/src/jalview/datamodel/HMMNode.java +++ b/src/jalview/datamodel/HMMNode.java @@ -42,14 +42,15 @@ public class HMMNode { this.insertEmissions = insertEmissionsL; } + public List getStateTransitions() { return stateTransitions; } - public void setStateTransitions(List stateTransitionsL) + public void setStateTransitions(List stateTransitionsM) { - this.stateTransitions = stateTransitionsL; + this.stateTransitions = stateTransitionsM; } public Integer getAlignmentColumn() diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index 4514a41..8df98e3 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -102,13 +102,19 @@ public class HiddenMarkovModel private final String MASKED_VALUE = "MM"; - final static String[] TRANSITION_TYPES = new String[] { "m->m", "m->i", - "m->d", "i->m", "i->i", "d->m", "d->d" }; + public static final int MATCHTOMATCH = 0; - public String getTransitionType(int index) - { - return TRANSITION_TYPES[index]; - } + public static final int MATCHTOINSERT = 1; + + public static final int MATCHTODELETE = 2; + + public static final int INSERTTOMATCH = 3; + + public static final int INSERTTOINSERT = 4; + + public static final int DELETETOMATCH = 5; + + public static final int DELETETODELETE = 6; public Map getNodeLookup() { @@ -120,11 +126,6 @@ public class HiddenMarkovModel this.nodeLookup = nodeLookup; } - public String[] getTransitionTypes() - { - return TRANSITION_TYPES; - } - public List getSymbols() { return symbols; @@ -357,17 +358,16 @@ public class HiddenMarkovModel * @return */ public Double getStateTransitionProbability(int alignColumn, - String transition) + int transition) { int transitionIndex; int nodeIndex; Double probability; - transitionIndex = getTransitionType(transition); if (nodeLookup.containsKey(alignColumn + 1)) { nodeIndex = nodeLookup.get(alignColumn + 1); probability = getNode(nodeIndex).getStateTransitions() - .get(transitionIndex); + .get(transition); return probability; } else @@ -703,44 +703,6 @@ public class HiddenMarkovModel } /** - * - * @param transition - * type of transition occuring - * @return index value representing position along stateTransition array. - */ - public Integer getTransitionType(String transition) - { - Integer index; - switch (transition) - { - case "mm": - index = 0; - break; - case "mi": - index = 1; - break; - case "md": - index = 2; - break; - case "im": - index = 3; - break; - case "ii": - index = 4; - break; - case "dm": - index = 5; - break; - case "dd": - index = 6; - break; - default: - index = null; - } - return index; - } - - /** * find the index of the node in a hidden Markov model based on the column in * the alignment * @@ -767,8 +729,6 @@ public class HiddenMarkovModel } /** - * creates the HMM annotation - * * @return */ public AlignmentAnnotation createAnnotation(int length) diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index 6945ea6..16a1222 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -47,6 +47,8 @@ public class HMMFile extends AlignFile private final String EMPTY = ""; + private static final String TRANSITIONTYPELINE = "m->m m->i m->d i->m i->i d->m d->d"; + public HMMFile(FileParse source) throws IOException { super(false, source); @@ -364,12 +366,7 @@ public class HMMFile extends AlignFile strSymbols = charListToStringList(charSymbols); symbolLine += addData(11, 9, strSymbols); file.append(symbolLine + NEW_LINE); - - String transitionTypeLine = ""; - List transitionTypes; - transitionTypes = stringArrayToStringList(hmm.getTransitionTypes()); - transitionTypeLine += addData(16, 9, transitionTypes); - file.append(transitionTypeLine + NEW_LINE); + file.append(TRANSITIONTYPELINE + NEW_LINE); int length = hmm.getLength(); diff --git a/test/jalview/io/HMMFileTest.java b/test/jalview/io/HMMFileTest.java index 36a2491..70bfc27 100644 --- a/test/jalview/io/HMMFileTest.java +++ b/test/jalview/io/HMMFileTest.java @@ -202,21 +202,6 @@ public class HMMFileTest { } @Test - public void testGetTransitionType() - { - HiddenMarkovModel hmm = fn3.getHMM(); - assertEquals(hmm.getTransitionType("mm").intValue(), 0); - assertEquals(hmm.getTransitionType("mi").intValue(), 1); - assertEquals(hmm.getTransitionType("md").intValue(), 2); - assertEquals(hmm.getTransitionType("im").intValue(), 3); - assertEquals(hmm.getTransitionType("ii").intValue(), 4); - assertEquals(hmm.getTransitionType("dm").intValue(), 5); - assertEquals(hmm.getTransitionType("dd").intValue(), 6); - assertNull(hmm.getTransitionType("df")); - - } - - @Test public void testFillList() { Scanner scanner1 = new Scanner("1.3 2.4 5.3 3.9 9.8 4.7 4.3 2.3 6.9");