From d6cace53173ae859bfd93f5e8a13be427864afd1 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Fri, 11 Aug 2017 16:05:18 +0100 Subject: [PATCH] JAL-2599 HMMs can now be dropped onto the desktop --- src/jalview/api/AlignViewportI.java | 4 +++ src/jalview/datamodel/HiddenMarkovModel.java | 14 ++++------ src/jalview/gui/AlignFrame.java | 13 --------- src/jalview/io/FileLoader.java | 38 ++++++++++++++++++++++++++ src/jalview/io/HMMFile.java | 14 ++++++++++ 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index aed3089..471e136 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -517,4 +517,8 @@ public interface AlignViewportI extends ViewStyleI void setSequenceInformationHash(ProfilesI info, int index); + void initInformation(); + + void updateInformation(AlignmentViewPanel ap); + } diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index c96ad8b..e74d826 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -985,7 +985,7 @@ public class HiddenMarkovModel * The length of the longest sequence in the existing alignment. * @return */ - public Sequence getConsensusSequence(int length) + public Sequence getConsensusSequence() { int start; int end; @@ -993,8 +993,8 @@ public class HiddenMarkovModel start = getNodeAlignmentColumn(1); modelLength = getLength(); end = getNodeAlignmentColumn(modelLength); - char[] sequence = new char[length]; - for (int index = 0; index < length; index++) + char[] sequence = new char[end]; + for (int index = 0; index < end; index++) { Character character; @@ -1123,15 +1123,11 @@ public class HiddenMarkovModel } - public SequenceI initHMMSequence(AlignFrame af, int position) + public SequenceI initHMMSequence() { - AlignmentI alignment = af.getViewport().getAlignment(); - int length = alignment.getWidth(); - Sequence consensus = getConsensusSequence(length); + Sequence consensus = getConsensusSequence(); consensus.setIsHMMConsensusSequence(true); consensus.setHMM(this); - SequenceI[] consensusArr = new Sequence[] { consensus }; - alignment.getSequences().add(position, consensus); return consensus; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 39dad15..2694434 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -54,7 +54,6 @@ import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; -import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; @@ -75,7 +74,6 @@ import jalview.io.FileFormats; import jalview.io.FileLoader; import jalview.io.FileParse; import jalview.io.FormatAdapter; -import jalview.io.HMMFile; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.JPredFile; @@ -4732,17 +4730,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, "label.successfully_loaded_matrix", sm.getMatrixName())); } - else if (FileFormat.HMMER3.equals(format)) - { - HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType)); - HiddenMarkovModel hmm = hmmFile.getHMM(); - SequenceI hmmSeq = hmm.initHMMSequence(this, 0); - getViewport().initInformation(); - getViewport().updateInformation(alignPanel); - getViewport().alignmentChanged(alignPanel); - isAnnotation = true; - - } else if (FileFormat.Jnet.equals(format)) { JPredFile predictions = new JPredFile(file, sourceType); diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 9d5fd93..57fe83e 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -29,6 +29,7 @@ import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; @@ -392,6 +393,43 @@ public class FileLoader implements Runnable } // append to existing alignment viewport.addAlignment(al, title); + if (source instanceof HMMFile) + { + AlignmentI alignment = viewport.getAlignment(); + SequenceI seq = alignment + .getSequenceAt(alignment.getAbsoluteHeight() - 1); + alignment.deleteSequence(alignment.getAbsoluteHeight() - 1); + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg != null) + { + seq.insertCharAt(0, sg.getStartRes(), '-'); + seq.insertCharAt(sg.getEndRes(), alignment.getWidth(), '-'); + SequenceI topSeq = sg.getSequencesInOrder(alignment)[0]; + int topIndex = alignment.findIndex(topSeq); + alignment.getSequences().add(topIndex, seq); + sg.setSeqrep(seq); + viewport.getSelectionGroup().addSequence(seq, false); + } + else + { + for (int i = 0; i < alignment.getAbsoluteHeight(); i++) + { + if (!alignment.getSequenceAt(i).isHMMConsensusSequence()) + { + alignment.getSequences().add(i, seq); + break; + } + + } + } + viewport.setAlignment(alignment); + viewport.initInformation(); + viewport.updateInformation(viewport.getAlignPanel()); + viewport.getAlignPanel().adjustAnnotationHeight(); + viewport.updateSequenceIdColours(); + viewport.getAlignPanel().paintAlignment(true); + viewport.alignmentChanged(viewport.getAlignPanel()); + } } else { diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index 8870837..bf86c68 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -709,5 +709,19 @@ public class HMMFile extends AlignFile } + + @Override + public SequenceI[] getSeqsAsArray() + { + SequenceI hmmSeq = hmm.initHMMSequence(); + SequenceI[] seq = new SequenceI[1]; + seq[0] = hmmSeq; + // view.initInformation(); + // view.updateInformation(view.panel); + // getViewport().alignmentChanged(alignPanel); + return seq; + + } + } -- 1.7.10.2