From: Jim Procter Date: Mon, 22 Jun 2020 10:53:33 +0000 (+0100) Subject: JAL-3666 SequenceI.*HMM methods look to dataset sequence for HMM profile. Initial... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c4b121daf820c1912737866f000586ee36e47cf5;p=jalview.git JAL-3666 SequenceI.*HMM methods look to dataset sequence for HMM profile. Initial ‘HMMSequence’ representing consensus from profile is stored as SeqCigar and materialised when required. --- 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()); } }