From c4b121daf820c1912737866f000586ee36e47cf5 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 22 Jun 2020 11:53:33 +0100 Subject: [PATCH] =?utf8?q?JAL-3666=20SequenceI.*HMM=20methods=20look=20to=20?= =?utf8?q?dataset=20sequence=20for=20HMM=20profile.=20Initial=20=E2=80=98HMM?= =?utf8?q?Sequence=E2=80=99=20representing=20consensus=20from=20profile=20is?= =?utf8?q?=20stored=20as=20SeqCigar=20and=20materialised=20when=20required.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/datamodel/HiddenMarkovModel.java | 11 ++++++++--- src/jalview/datamodel/Sequence.java | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index 6b8b095..cae502d 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -77,6 +77,8 @@ public class HiddenMarkovModel // stores background frequencies of alignment from which this model came private Map backgroundFrequencies; + private SeqCigar hmmCigar; + /** * Constructor */ @@ -570,12 +572,14 @@ public class HiddenMarkovModel lastResNo = resNo; } + // TODO: check that gap accounting is correct here Sequence seq = new Sequence(getName(), sequence, start, lastResNo - gapCount); seq.createDatasetSequence(); seq.setHMM(this); - this.hmmSeq = seq; - + + this.hmmSeq = seq.getDatasetSequence(); + this.hmmCigar = new SeqCigar(seq); /* * construct and store Mapping of nodes to residues * note as constructed this is just an identity mapping, @@ -584,6 +588,7 @@ public class HiddenMarkovModel List fromNodes = new ArrayList<>(); fromNodes.add(new int[] { 1, getLength() }); toResidues.add(new int[] { seq.getStart(), seq.getEnd() }); + MapList mapList = new MapList(fromNodes, toResidues, 1, 1); mapToHmmConsensus = new Mapping(seq.getDatasetSequence(), mapList); } @@ -597,7 +602,7 @@ public class HiddenMarkovModel */ public SequenceI getConsensusSequence() { - return hmmSeq; + return hmmCigar.getSeq('-'); } /** diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 25e9611..d1f13c1 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1609,6 +1609,8 @@ public class Sequence extends ASequence implements SequenceI datasetSequence.addAlignmentAnnotation(_aa); } } + datasetSequence.setHMM(hmm); + hmm=null; } return datasetSequence; } @@ -1888,13 +1890,23 @@ public class Sequence extends ASequence implements SequenceI @Override public HiddenMarkovModel getHMM() { + if (datasetSequence!=null) + { + return datasetSequence.getHMM(); + } return hmm; } @Override public void setHMM(HiddenMarkovModel hmm) { - this.hmm = hmm; + if (datasetSequence!=null) + { + datasetSequence.setHMM(hmm); + } else { + this.hmm=hmm; + } + } @Override @@ -2081,6 +2093,6 @@ public class Sequence extends ASequence implements SequenceI @Override public boolean hasHMMProfile() { - return hmm != null; + return hmm != null || (datasetSequence!=null && datasetSequence.hasHMMProfile()); } } -- 1.7.10.2