JAL-2629 moved HMM storage location to placeholder sequence
[jalview.git] / src / jalview / gui / AlignFrame.java
index 080e260..0c951fa 100644 (file)
@@ -54,6 +54,7 @@ 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;
@@ -130,8 +131,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Deque;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -153,6 +156,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
 {
 
+  Map<String, Float> distribution = new HashMap<>(); // temporary
+
   public static final int DEFAULT_WIDTH = 700;
 
   public static final int DEFAULT_HEIGHT = 500;
@@ -180,6 +185,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   String fileName = null;
 
+
   /**
    * Creates a new AlignFrame object with specific width and height.
    * 
@@ -377,6 +383,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     });
     buildColourMenu();
+    buildHMMERMenu();
 
     if (Desktop.desktop != null)
     {
@@ -483,6 +490,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   }
 
+  private void buildHMMERMenu()
+  {
+    hmmerMenu.removeAll();
+
+    hmmerMenu.add(autoAlignSeqs);
+    hmmerMenu.addSeparator();
+
+    hmmerMenu.add(hmmAlign);
+    hmmerMenu.add(hmmBuild);
+    hmmerMenu.add(hmmSearch);
+    
+  }
+
   /**
    * Change the filename and format for the alignment, and enable the 'reload'
    * button functionality.
@@ -919,6 +939,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
     showSequenceLogo.setSelected(av.isShowSequenceLogo());
     normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
+    showInformationHistogram.setSelected(av.isShowInformationHistogram());
+    showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
+    normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
 
     ColourMenuHelper.setColourSelected(colourMenu,
             av.getGlobalColourScheme());
@@ -4652,14 +4675,44 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else if (FileFormat.HMMER3.equals(format))
           {
-            HMMFile hmm = new HMMFile(new FileParse(file, sourceType));
-            hmm.parse();
-
-            getViewport().getAlignment().setHMM(hmm.getHMM());
-
-
+            HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType)); // TODO
+                                                                            // need
+                                                                            // to
+                                                                            // follow
+                                                                            // standard
+                                                                            // pipeline
+            hmmFile.parse();
+            HiddenMarkovModel hmm = hmmFile.getHMM();
+            AlignmentAnnotation annotArray[] = getViewport().getAlignment()
+                    .getAlignmentAnnotation();
+
+            AlignmentAnnotation reference = null;
+            for (AlignmentAnnotation annot : annotArray)
+            {
+              if (annot.label.contains("Reference"))
+              {
+                reference = annot;
+              }
+            }
 
+            if (reference != null)
+            {
+              hmm.mapToReferenceAnnotation(reference);
+            }
 
+            AlignmentAnnotation annotation = hmm.createAnnotation(
+                    getViewport().getAlignment().getWidth());
+            getViewport().getAlignment().addAnnotation(annotation);
+            int length = getViewport().getAlignment().getWidth();
+            Sequence consensus = hmm.getConsensusSequence(length);
+            consensus.setHMM(hmm);
+            annotation.setHMM(hmm);
+            SequenceI[] consensusArr = new Sequence[] { consensus };
+            AlignmentI newAlignment = new Alignment(consensusArr);
+            newAlignment.append(getViewport().getAlignment());
+            getViewport().setAlignment(newAlignment);
+            isAnnotation = true;
+            alignPanel.repaint();
 
           }
           else if (FileFormat.Jnet.equals(format))
@@ -5280,6 +5333,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
+  protected void showInformationHistogram_actionPerformed(ActionEvent e)
+  {
+    viewport.setShowInformationHistogram(
+            showInformationHistogram.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
+  @Override
+  protected void showHMMSequenceLogo_actionPerformed(ActionEvent e)
+  {
+    viewport.setShowHMMSequenceLogo(showHMMSequenceLogo.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
+  @Override
+  protected void normaliseHMMSequenceLogo_actionPerformed(ActionEvent e)
+  {
+    showHMMSequenceLogo.setState(true);
+    viewport.setShowHMMSequenceLogo(true);
+    viewport.setNormaliseHMMSequenceLogo(normaliseSequenceLogo.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
+  @Override
   protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
   {
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());