JAL-2599 HMMs can now be dropped onto the desktop
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Fri, 11 Aug 2017 15:05:18 +0000 (16:05 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Fri, 11 Aug 2017 15:12:07 +0000 (16:12 +0100)
src/jalview/api/AlignViewportI.java
src/jalview/datamodel/HiddenMarkovModel.java
src/jalview/gui/AlignFrame.java
src/jalview/io/FileLoader.java
src/jalview/io/HMMFile.java

index aed3089..471e136 100644 (file)
@@ -517,4 +517,8 @@ public interface AlignViewportI extends ViewStyleI
 
   void setSequenceInformationHash(ProfilesI info, int index);
 
+  void initInformation();
+
+  void updateInformation(AlignmentViewPanel ap);
+
 }
index c96ad8b..e74d826 100644 (file)
@@ -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;
   }
 
index 39dad15..2694434 100644 (file)
@@ -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);
index 9d5fd93..57fe83e 100755 (executable)
@@ -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
           {
index 8870837..bf86c68 100644 (file)
@@ -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;
+
+  }
+
 }