From: gmungoc Date: Mon, 16 Apr 2018 09:19:31 +0000 (+0100) Subject: JAL-2629 JAL-2937 remove redundant is/setHMMConsensusSequence X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=37f0332f53a8564ba7a9d55b993f8bfd2f368c80;p=jalview.git JAL-2629 JAL-2937 remove redundant is/setHMMConsensusSequence --- diff --git a/src/jalview/analysis/SeqsetUtils.java b/src/jalview/analysis/SeqsetUtils.java index 2c077b6..921ab2a 100755 --- a/src/jalview/analysis/SeqsetUtils.java +++ b/src/jalview/analysis/SeqsetUtils.java @@ -53,7 +53,7 @@ public class SeqsetUtils sqinfo.put("Description", seq.getDescription()); } - Vector sfeat = new Vector(); + Vector sfeat = new Vector<>(); List 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; } diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index dd27fa6..3c2c437 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -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; + } } diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 755abbb..9464c74 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -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; + } } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index aebcbb3..2cf673c 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -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()); diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 5b3d782..6d34d07 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -499,10 +499,6 @@ public interface SequenceI extends ASequenceI */ public List 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 it); + String getSequenceStringFromIterator(Iterator 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 it); + int firstResidueOutsideIterator(Iterator it); + + /** + * Answers true if this sequence has an associated Hidden Markov Model + * + * @return + */ + boolean hasHMMProfile(); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 009d946..a317106 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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(); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index e3becf6..e62853d 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -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); } diff --git a/src/jalview/hmmer/HMMAlign.java b/src/jalview/hmmer/HMMAlign.java index befdc55..163e85b 100644 --- a/src/jalview/hmmer/HMMAlign.java +++ b/src/jalview/hmmer/HMMAlign.java @@ -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)); } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 2d753c1..720abc9 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -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 diff --git a/src/jalview/schemes/HmmerLocalBackground.java b/src/jalview/schemes/HmmerLocalBackground.java index d7a5e65..19cf080 100644 --- a/src/jalview/schemes/HmmerLocalBackground.java +++ b/src/jalview/schemes/HmmerLocalBackground.java @@ -62,7 +62,7 @@ public class HmmerLocalBackground extends HmmerColourScheme List seqs = sg.getSequences(); for (SequenceI seq : seqs) { - if (!seq.isHMMConsensusSequence()) + if (!seq.hasHMMProfile()) { for (char c : seq.getSequence()) {