JAL-2629 JAL-2937 remove redundant is/setHMMConsensusSequence
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Apr 2018 09:19:31 +0000 (10:19 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Apr 2018 09:19:31 +0000 (10:19 +0100)
src/jalview/analysis/SeqsetUtils.java
src/jalview/datamodel/HiddenMarkovModel.java
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/datamodel/SequenceI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/PopupMenu.java
src/jalview/hmmer/HMMAlign.java
src/jalview/io/FileLoader.java
src/jalview/schemes/HmmerLocalBackground.java

index 2c077b6..921ab2a 100755 (executable)
@@ -53,7 +53,7 @@ public class SeqsetUtils
       sqinfo.put("Description", seq.getDescription());
     }
 
-    Vector<SequenceFeature> sfeat = new Vector<SequenceFeature>();
+    Vector<SequenceFeature> sfeat = new Vector<>();
     List<SequenceFeature> sfs = seq.getFeatures().getAllFeatures();
     sfeat.addAll(sfs);
 
@@ -70,7 +70,7 @@ public class SeqsetUtils
               (seq.getDatasetSequence() != null) ? seq.getDatasetSequence()
                       : new Sequence("THISISAPLACEHOLDER", ""));
     }
-    if (seq.isHMMConsensusSequence())
+    if (seq.hasHMMProfile())
     {
       sqinfo.put("HMM", seq.getHMM());
     }
@@ -143,8 +143,7 @@ public class SeqsetUtils
 
     if (hmm != null)
     {
-      sq.setHMM(new HiddenMarkovModel(hmm));
-      sq.setIsHMMConsensusSequence(true);
+      sq.setHMM(new HiddenMarkovModel(hmm, sq));
     }
     return namePresent;
   }
index dd27fa6..3c2c437 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.datamodel;
 
+import jalview.bin.Cache;
 import jalview.io.HMMFile;
 import jalview.schemes.ResidueProperties;
 import jalview.util.Comparison;
@@ -82,11 +83,13 @@ public class HiddenMarkovModel
   }
 
   /**
-   * Copy constructor
+   * Copy constructor given a new aligned sequence with which to associate the
+   * HMM profile
    * 
    * @param hmm
+   * @param sq
    */
-  public HiddenMarkovModel(HiddenMarkovModel hmm)
+  public HiddenMarkovModel(HiddenMarkovModel hmm, SequenceI sq)
   {
     super();
     this.fileProperties = new HashMap<>(hmm.fileProperties);
@@ -94,6 +97,15 @@ public class HiddenMarkovModel
     this.nodes = new ArrayList<>(hmm.nodes);
     this.symbolIndexLookup = hmm.symbolIndexLookup;
     this.fileHeader = new String(hmm.fileHeader);
+    this.hmmSeq = sq;
+    if (sq.getDatasetSequence() == hmm.mapToHmmConsensus.getTo())
+    {
+      this.mapToHmmConsensus = hmm.mapToHmmConsensus;
+    }
+    else
+    {
+      Cache.log.error("Error: HMM copied with change of mapped sequence");
+    }
   }
 
   /**
@@ -549,8 +561,6 @@ public class HiddenMarkovModel
             lastResNo - gapCount);
     seq.createDatasetSequence();
     seq.setHMM(this);
-    seq.setIsHMMConsensusSequence(true);
-
     this.hmmSeq = seq;
 
     /*
@@ -611,5 +621,15 @@ public class HiddenMarkovModel
       buildConsensusSequence();
     }
   }
+
+  /**
+   * Sets the aligned consensus sequence this HMM is the model for
+   * 
+   * @param hmmSeq
+   */
+  public void setHmmSeq(SequenceI hmmSeq)
+  {
+    this.hmmSeq = hmmSeq;
+  }
 }
 
index 755abbb..9464c74 100755 (executable)
@@ -343,13 +343,9 @@ public class Sequence extends ASequence implements SequenceI
         this.addPDBId(new PDBEntry(pdb));
       }
     }
-    if (seq.isHMMConsensusSequence())
-    {
-      this.isHMMConsensusSequence = true;
-    }
     if (seq.getHMM() != null)
     {
-      this.hmm = new HiddenMarkovModel(seq.getHMM());
+      this.hmm = new HiddenMarkovModel(seq.getHMM(), this);
     }
 
   }
@@ -1916,18 +1912,6 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   @Override
-  public boolean isHMMConsensusSequence()
-  {
-    return isHMMConsensusSequence;
-  }
-
-  @Override
-  public void setIsHMMConsensusSequence(boolean value)
-  {
-    this.isHMMConsensusSequence = value;
-  }
-
-  @Override
   public boolean hasHMMAnnotation()
   {
     if (this.annotation == null) {
@@ -2107,4 +2091,10 @@ public class Sequence extends ASequence implements SequenceI
     // otherwise, sequence was completely hidden
     return 0;
   }
+
+  @Override
+  public boolean hasHMMProfile()
+  {
+    return hmm != null;
+  }
 }
index aebcbb3..2cf673c 100755 (executable)
@@ -283,7 +283,6 @@ public class SequenceGroup implements AnnotatedCollectionI
         seqs[ipos].setDescription(seq.getDescription());
         seqs[ipos].setDBRefs(seq.getDBRefs());
         seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
-        seqs[ipos].setIsHMMConsensusSequence(seq.isHMMConsensusSequence());
         if (seq.getDatasetSequence() != null)
         {
           seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
index 5b3d782..6d34d07 100755 (executable)
@@ -499,10 +499,6 @@ public interface SequenceI extends ASequenceI
    */
   public List<DBRefEntry> getPrimaryDBRefs();
 
-  boolean isHMMConsensusSequence();
-
-  void setIsHMMConsensusSequence(boolean isHMMConsensusSequence);
-
   /**
    * Answers true if the sequence has annotation for Hidden Markov Model
    * information content, else false
@@ -576,7 +572,7 @@ public interface SequenceI extends ASequenceI
    *          the iterator to use
    * @return a String corresponding to the sequence
    */
-  public String getSequenceStringFromIterator(Iterator<int[]> it);
+  String getSequenceStringFromIterator(Iterator<int[]> it);
 
   /**
    * Locate the first position in this sequence which is not contained in an
@@ -586,5 +582,12 @@ public interface SequenceI extends ASequenceI
    *          iterator over regions
    * @return first residue not contained in regions
    */
-  public int firstResidueOutsideIterator(Iterator<int[]> it);
+  int firstResidueOutsideIterator(Iterator<int[]> it);
+
+  /**
+   * Answers true if this sequence has an associated Hidden Markov Model
+   * 
+   * @return
+   */
+  boolean hasHMMProfile();
 }
index 009d946..a317106 100644 (file)
@@ -153,7 +153,6 @@ import java.util.Vector;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JEditorPane;
 import javax.swing.JFileChooser;
-import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
@@ -1043,9 +1042,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     else
     {
       WsParamSetI set = new HMMERPreset();
-      ParamDatastoreI store = HMMERParamStore.forBuild();
-      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-              args);
+      ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
+      WsJobParameters params = new WsJobParameters(store, set, args);
       if (params.showRunDialog())
       {
         args = params.getJobParams();
@@ -1069,9 +1067,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (!withDefaults)
     {
       WsParamSetI set = new HMMERPreset();
-      ParamDatastoreI store = HMMERParamStore.forAlign();
-      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-              args);
+      ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
+      WsJobParameters params = new WsJobParameters(store, set, args);
       if (params.showRunDialog())
       {
         args = params.getJobParams();
@@ -1095,9 +1092,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (!withDefaults)
     {
       WsParamSetI set = new HMMERPreset();
-      ParamDatastoreI store = HMMERParamStore.forSearch();
-      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-              args);
+      ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
+      WsJobParameters params = new WsJobParameters(store, set, args);
       if (params.showRunDialog())
       {
         args = params.getJobParams();
index e3becf6..e62853d 100644 (file)
@@ -360,7 +360,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
       });
       add(menuItem);
 
-      if (sequence.isHMMConsensusSequence())
+      if (sequence.hasHMMProfile())
       {
         JMenuItem selectHMM = new JCheckBoxMenuItem();
         selectHMM.setText(MessageManager.getString("label.select_hmm"));
@@ -1371,7 +1371,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
   protected void selectHMM_actionPerformed(SequenceI seq)
   {
     // TODO move this to Viewport
-    if (seq.isHMMConsensusSequence())
+    if (seq.hasHMMProfile())
     {
       ap.alignFrame.setSelectedHMMSequence(seq);
     }
index befdc55..163e85b 100644 (file)
@@ -215,7 +215,7 @@ public class HMMAlign extends HmmerCommand
     /*
      * hack to ensure hmm set on alignment
      */
-    if (al.getSequenceAt(0).isHMMConsensusSequence())
+    if (al.getSequenceAt(0).hasHMMProfile())
     {
       al.setHmmConsensus(al.getSequenceAt(0));
     }
index 2d753c1..720abc9 100755 (executable)
@@ -425,7 +425,7 @@ public class FileLoader implements Runnable
               AlignmentI alignment = viewport.getAlignment();
               SequenceI seq = alignment
                       .getSequenceAt(alignment.getAbsoluteHeight() - 1);
-              if (seq.isHMMConsensusSequence())
+              if (seq.hasHMMProfile())
               {
                 /* 
                  * fudge: move HMM consensus sequence from last to first
index d7a5e65..19cf080 100644 (file)
@@ -62,7 +62,7 @@ public class HmmerLocalBackground extends HmmerColourScheme
     List<SequenceI> seqs = sg.getSequences();
     for (SequenceI seq : seqs)
     {
-      if (!seq.isHMMConsensusSequence())
+      if (!seq.hasHMMProfile())
       {
         for (char c : seq.getSequence())
         {