From d70c093b72754e026fc6df06e3e13464d6330408 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Fri, 23 Jun 2017 12:52:54 +0100 Subject: [PATCH] add HMMER colour scheme --- src/jalview/datamodel/Alignment.java | 17 ++++++++ src/jalview/datamodel/AlignmentI.java | 2 + src/jalview/datamodel/AnnotatedCollectionI.java | 4 ++ src/jalview/datamodel/HiddenMarkovModel.java | 51 +++++++++++++++++++---- src/jalview/datamodel/SequenceGroup.java | 16 +++++++ src/jalview/gui/AlignFrame.java | 8 +++- src/jalview/schemes/JalviewColourScheme.java | 3 +- 7 files changed, 90 insertions(+), 11 deletions(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 5d91b36..a88995d 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -68,6 +68,8 @@ public class Alignment implements AlignmentI private List codonFrameList; + HiddenMarkovModel hmm; + private void initAlignment(SequenceI[] seqs) { groups = Collections.synchronizedList(new ArrayList()); @@ -1959,4 +1961,19 @@ public class Alignment implements AlignmentI { hiddenCols = cols; } + + @Override + public HiddenMarkovModel getHMM() + { + + return hmm; + } + + @Override + public void setHMM(HiddenMarkovModel markov) + { + + hmm = markov; + } + } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 2e61f9d..948fd1b 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -591,4 +591,6 @@ public interface AlignmentI extends AnnotatedCollectionI public void setHiddenColumns(HiddenColumns cols); + + } diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index 2963fd5..45a3787 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -61,4 +61,8 @@ public interface AnnotatedCollectionI extends SequenceCollectionI * alignment, parent group). */ AnnotatedCollectionI getContext(); + + public HiddenMarkovModel getHMM(); + + public void setHMM(HiddenMarkovModel hmm); } diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index f614013..e214373 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -290,10 +290,22 @@ public class HiddenMarkovModel int symbolIndex; int nodeIndex; Double probability; + if (symbol == '-') + { + return 0d; + } symbolIndex = symbolIndexLookup.get(symbol); - nodeIndex = nodeLookup.get(alignColumn); - probability = getNode(nodeIndex).getMatchEmissions().get(symbolIndex); - return probability; + if (nodeLookup.containsKey(alignColumn + 1)) + { + nodeIndex = nodeLookup.get(alignColumn + 1); + probability = getNode(nodeIndex).getMatchEmissions().get(symbolIndex); + probability = Math.pow(Math.E, -probability); + return probability; + } + else + { + return 0d; + } } @@ -310,10 +322,23 @@ public class HiddenMarkovModel int symbolIndex; int nodeIndex; Double probability; + if (symbol == '-') + { + return 0d; + } symbolIndex = symbolIndexLookup.get(symbol); - nodeIndex = nodeLookup.get(alignColumn); - probability = getNode(nodeIndex).getInsertEmissions().get(symbolIndex); - return probability; + if (nodeLookup.containsKey(alignColumn + 1)) + { + nodeIndex = nodeLookup.get(alignColumn + 1); + probability = getNode(nodeIndex).getInsertEmissions() + .get(symbolIndex); + probability = Math.pow(Math.E, -probability); + return probability; + } + else + { + return 0d; + } } @@ -332,10 +357,18 @@ public class HiddenMarkovModel int nodeIndex; Double probability; transitionIndex = getTransitionType(transition); - nodeIndex = nodeLookup.get(alignColumn); - probability = getNode(nodeIndex).getStateTransitions() + if (nodeLookup.containsKey(alignColumn + 1)) + { + nodeIndex = nodeLookup.get(alignColumn + 1); + probability = getNode(nodeIndex).getStateTransitions() .get(transitionIndex); - return probability; + probability = Math.pow(Math.E, -probability); + return probability; + } + else + { + return 0d; + } } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 463b909..a1a655e 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -51,6 +51,8 @@ public class SequenceGroup implements AnnotatedCollectionI boolean colourText = false; + HiddenMarkovModel hmm; + /** * True if the group is defined as a group on the alignment, false if it is * just a selection. @@ -1457,4 +1459,18 @@ public class SequenceGroup implements AnnotatedCollectionI { return (startRes <= apos && endRes >= apos) && sequences.contains(seq); } + + @Override + public HiddenMarkovModel getHMM() + { + // TODO Auto-generated method stub + return hmm; + } + + @Override + public void setHMM(HiddenMarkovModel markov) + { + hmm = markov; + + } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2140ed9..080e260 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4654,7 +4654,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { HMMFile hmm = new HMMFile(new FileParse(file, sourceType)); hmm.parse(); - System.out.println("successful"); + + getViewport().getAlignment().setHMM(hmm.getHMM()); + + + + + } else if (FileFormat.Jnet.equals(format)) { diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java index 185d2b4..c3a3873 100644 --- a/src/jalview/schemes/JalviewColourScheme.java +++ b/src/jalview/schemes/JalviewColourScheme.java @@ -22,7 +22,8 @@ public enum JalviewColourScheme NucleotideColourScheme.class), PurinePyrimidine( "Purine/Pyrimidine", PurinePyrimidineColourScheme.class), RNAHelices("RNA Helices", RNAHelicesColour.class), TCoffee( - "T-Coffee Scores", TCoffeeColourScheme.class); + "T-Coffee Scores", TCoffeeColourScheme.class), + HMMER("HMMER", HMMERColourScheme.class); // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class) private String name; -- 1.7.10.2