JAL-3666 SequenceI.*HMM methods look to dataset sequence for HMM profile. Initial...
authorJim Procter <jprocter@issues.jalview.org>
Mon, 22 Jun 2020 10:53:33 +0000 (11:53 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 22 Jun 2020 10:53:33 +0000 (11:53 +0100)
src/jalview/datamodel/HiddenMarkovModel.java
src/jalview/datamodel/Sequence.java

index 6b8b095..cae502d 100644 (file)
@@ -77,6 +77,8 @@ public class HiddenMarkovModel
   // stores background frequencies of alignment from which this model came
   private Map<Character, Float> 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<int[]> 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('-');
   }
 
   /**
index 25e9611..d1f13c1 100755 (executable)
@@ -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());
   }
 }