From e5cba1e6a138feeeb8cf5b5823b3cafc89e71b9f Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Thu, 27 Jul 2017 12:06:02 +0100 Subject: [PATCH] JAL-2629 moved HMM storage location to placeholder sequence --- src/jalview/analysis/AAFrequency.java | 4 +--- src/jalview/datamodel/AlignmentAnnotation.java | 22 +++++------------- src/jalview/datamodel/HiddenMarkovModel.java | 2 +- src/jalview/datamodel/Sequence.java | 24 ++++++++++++++++---- src/jalview/datamodel/SequenceI.java | 4 ++++ src/jalview/gui/AlignFrame.java | 20 +++++++++++++++- src/jalview/io/AlignFile.java | 22 ++++++++++++++---- src/jalview/renderer/AnnotationRenderer.java | 4 +++- src/jalview/schemes/HMMERColourScheme.java | 29 +++++------------------- test/jalview/analysis/AAFrequencyTest.java | 7 ++---- 10 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 573e607..900209d 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -741,12 +741,10 @@ public class AAFrequency * less than their background frequencies. * @return */ - public static int[] getHMMProfileFor(AlignmentAnnotation aa, int column, + public static int[] getHMMProfileFor(HiddenMarkovModel hmm, int column, boolean removeBelowBackground) { - HiddenMarkovModel hmm; - hmm = aa.getHMM(); if (hmm != null) { String alph = hmm.getAlphabetType(); diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 31aeecc..e8e8d01 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -51,9 +51,9 @@ public class AlignmentAnnotation public static final int CDNA_PROFILE = 2; - private static long counter = 0; + HiddenMarkovModel hmm; - private HiddenMarkovModel hmm; + private static long counter = 0; /** * If true, this annotations is calculated every edit, eg consensus, quality @@ -1506,23 +1506,13 @@ public class AlignmentAnnotation return graphMin < graphMax; } - /** - * Returns the HMM associated with this annotation. - * - * @return - */ - public HiddenMarkovModel getHMM() + public void setHMM(HiddenMarkovModel markov) { - return hmm; + hmm = markov; } - /** - * Sets the HMM associated with this annotation. - * - * @param hmm - */ - public void setHMM(HiddenMarkovModel hmm) + public HiddenMarkovModel getHMM() { - this.hmm = hmm; + return hmm; } } diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index 40f106e..96a5a6f 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -1069,7 +1069,7 @@ public class HiddenMarkovModel if ("x".equals(character) || "X".equals(character)) { nodeIndex++; - if (nodeIndex <= nodes.size()) + if (nodeIndex < nodes.size()) { nodes.get(nodeIndex).setAlignmentColumn(col + 1); nodeLookup.put(col + 1, nodeIndex); diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index b0faf21..56a89a1 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -57,6 +57,8 @@ public class Sequence extends ASequence implements SequenceI int end; + HiddenMarkovModel hmm; + Vector pdbIds; String vamsasId; @@ -416,7 +418,7 @@ public class Sequence extends ASequence implements SequenceI { if (pdbIds == null) { - pdbIds = new Vector(); + pdbIds = new Vector<>(); pdbIds.add(entry); return true; } @@ -787,7 +789,7 @@ public class Sequence extends ASequence implements SequenceI @Override public List getInsertions() { - ArrayList map = new ArrayList(); + ArrayList map = new ArrayList<>(); int lastj = -1, j = 0; int pos = start; int seqlen = sequence.length; @@ -1048,7 +1050,7 @@ public class Sequence extends ASequence implements SequenceI { if (this.annotation == null) { - this.annotation = new Vector(); + this.annotation = new Vector<>(); } if (!this.annotation.contains(annotation)) { @@ -1372,7 +1374,7 @@ public class Sequence extends ASequence implements SequenceI public List getAlignmentAnnotations(String calcId, String label) { - List result = new ArrayList(); + List result = new ArrayList<>(); if (this.annotation != null) { for (AlignmentAnnotation ann : annotation) @@ -1428,7 +1430,7 @@ public class Sequence extends ASequence implements SequenceI } synchronized (dbrefs) { - List primaries = new ArrayList(); + List primaries = new ArrayList<>(); DBRefEntry[] tmp = new DBRefEntry[1]; for (DBRefEntry ref : dbrefs) { @@ -1475,4 +1477,16 @@ public class Sequence extends ASequence implements SequenceI } } + @Override + public HiddenMarkovModel getHMM() + { + return hmm; + } + + @Override + public void setHMM(HiddenMarkovModel hmm) + { + this.hmm = hmm; + } + } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index e81553b..3298829 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -41,6 +41,10 @@ public interface SequenceI extends ASequenceI */ public void setName(String name); + public HiddenMarkovModel getHMM(); + + public void setHMM(HiddenMarkovModel hmm); + /** * Get the display name */ diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b14423c..0c951fa 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4683,12 +4683,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // pipeline hmmFile.parse(); HiddenMarkovModel hmm = hmmFile.getHMM(); + AlignmentAnnotation annotArray[] = getViewport().getAlignment() + .getAlignmentAnnotation(); + + AlignmentAnnotation reference = null; + for (AlignmentAnnotation annot : annotArray) + { + if (annot.label.contains("Reference")) + { + reference = annot; + } + } + + if (reference != null) + { + hmm.mapToReferenceAnnotation(reference); + } + AlignmentAnnotation annotation = hmm.createAnnotation( getViewport().getAlignment().getWidth()); getViewport().getAlignment().addAnnotation(annotation); - annotation.setHMM(hmm); int length = getViewport().getAlignment().getWidth(); Sequence consensus = hmm.getConsensusSequence(length); + consensus.setHMM(hmm); + annotation.setHMM(hmm); SequenceI[] consensusArr = new Sequence[] { consensus }; AlignmentI newAlignment = new Alignment(consensusArr); newAlignment.append(getViewport().getAlignment()); diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 7333075..745fb93 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -311,9 +311,9 @@ public abstract class AlignFile extends FileParse implements */ protected void initData() { - seqs = new Vector(); - annotations = new Vector(); - seqGroups = new ArrayList(); + seqs = new Vector<>(); + annotations = new Vector<>(); + seqGroups = new ArrayList<>(); parseCalled = false; } @@ -326,7 +326,7 @@ public abstract class AlignFile extends FileParse implements @Override public void setSeqs(SequenceI[] s) { - seqs = new Vector(); + seqs = new Vector<>(); for (int i = 0; i < s.length; i++) { @@ -397,7 +397,7 @@ public abstract class AlignFile extends FileParse implements { if (newickStrings == null) { - newickStrings = new Vector(); + newickStrings = new Vector<>(); } newickStrings.addElement(new String[] { treeName, newickString }); } @@ -421,4 +421,16 @@ public abstract class AlignFile extends FileParse implements { seqs.add(seq); } + + /** + * Used only for hmmer statistics, so should probably be removed at some + * point. TODO remove this + * + * @return + */ + public Vector getAnnotations() + { + return annotations; + } + } diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 1f3d5a9..78b3a88 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -29,6 +29,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.ProfilesI; import jalview.schemes.ColourSchemeI; import jalview.schemes.NucleotideColourScheme; @@ -359,7 +360,8 @@ public class AnnotationRenderer // if (aa.label.startsWith("Information")) { - return AAFrequency.getHMMProfileFor(aa, column, + HiddenMarkovModel hmm = aa.getHMM(); + return AAFrequency.getHMMProfileFor(hmm, column, av_ignoreBelowBackground); // TODO check if this follows standard // pipeline } diff --git a/src/jalview/schemes/HMMERColourScheme.java b/src/jalview/schemes/HMMERColourScheme.java index 09092a6..c9e081f 100644 --- a/src/jalview/schemes/HMMERColourScheme.java +++ b/src/jalview/schemes/HMMERColourScheme.java @@ -1,6 +1,5 @@ package jalview.schemes; -import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceCollectionI; @@ -106,35 +105,19 @@ public class HMMERColourScheme extends ResidueColourScheme public void alignmentChanged(AnnotatedCollectionI collection, Map hiddenReps) { - AlignmentAnnotation[] annArr = collection.getAlignmentAnnotation(); - for (AlignmentAnnotation ann : annArr) - { - if (ann.label.indexOf("Information Content") > -1) - { - hmm = ann.getHMM(); - } - } - + SequenceI seq = collection.getSequences().get(0); + hmm = seq.getHMM(); } + + @Override public ColourSchemeI getInstance(AnnotatedCollectionI sg, Map hiddenRepSequences) { HiddenMarkovModel markov = null; - AlignmentAnnotation[] annArr = sg.getAlignmentAnnotation(); - for (AlignmentAnnotation ann : annArr) - { - if (ann.label.indexOf("Information Content") > -1) - { - markov = ann.getHMM(); - } - } - - - - - + SequenceI seq = sg.getSequences().get(0); + markov = seq.getHMM(); HMMERColourScheme colour = new HMMERColourScheme(markov); return colour; diff --git a/test/jalview/analysis/AAFrequencyTest.java b/test/jalview/analysis/AAFrequencyTest.java index 646412f..4755bf6 100644 --- a/test/jalview/analysis/AAFrequencyTest.java +++ b/test/jalview/analysis/AAFrequencyTest.java @@ -249,11 +249,8 @@ public class AAFrequencyTest "test/jalview/io/test_MADE1_hmm.txt", DataSourceType.FILE)); hmmFile.parse(); HiddenMarkovModel hmm = hmmFile.getHMM(); - AlignmentAnnotation aa = hmm.createAnnotation(80); - aa.setHMM(hmm); - int[] expected = { 0, 4, 100, 'T', 71, 'C', 12, 'G', 9, 'A', 9 }; - int[] actual = AAFrequency.getHMMProfileFor(aa, 17, false); + int[] actual = AAFrequency.getHMMProfileFor(hmm, 17, false); for (int i = 0; i < actual.length; i++) { if (i == 2) @@ -267,7 +264,7 @@ public class AAFrequencyTest } int[] expected2 = { 0, 4, 85, 'A', 85, 'C', 0, 'G', 0, 'T', 0 }; - int[] actual2 = AAFrequency.getHMMProfileFor(aa, 2, true); + int[] actual2 = AAFrequency.getHMMProfileFor(hmm, 2, true); for (int i = 0; i < actual.length; i++) { if (i == 2) -- 1.7.10.2