make groups from selection
authorjprocter <Jim Procter>
Wed, 28 Apr 2010 10:17:09 +0000 (10:17 +0000)
committerjprocter <Jim Procter>
Wed, 28 Apr 2010 10:17:09 +0000 (10:17 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignViewport.java

index 1518bb0..74f12ef 100755 (executable)
@@ -651,6 +651,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       delete_actionPerformed();
     }
+    else if (source == grpsFromSelection)
+    {
+      makeGrpsFromSelection_actionPerformed();
+    }
     else if (source == deleteGroups)
     {
       deleteGroups_actionPerformed();
@@ -1595,7 +1599,36 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       this.setVisible(false);
     }
   }
-
+  protected void makeGrpsFromSelection_actionPerformed()
+  {
+    if (viewport.getSelectionGroup() != null)
+    {
+      SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
+              viewport.getSequenceSelection(), viewport.getAlignmentView(
+                      true).getSequenceStrings(viewport.getGapCharacter()),
+              viewport.alignment.getGroups());
+      viewport.alignment.deleteAllGroups();
+      viewport.sequenceColours = null;
+      viewport.setSelectionGroup(null);
+      // set view properties for each group
+      for (int g = 0; g < gps.length; g++)
+      {
+        // gps[g].setShowunconserved(viewport.getShowUnconserved());
+        gps[g].setIncludeAllConsSymbols(viewport.isIncludeAllConsensusSymbols());
+        viewport.alignment.addGroup(gps[g]);
+        Color col = new Color((int) (Math.random() * 255), (int) (Math
+                .random() * 255), (int) (Math.random() * 255));
+        col = col.brighter();
+        for (Enumeration sq = gps[g].getSequences(null).elements(); sq
+                .hasMoreElements(); viewport.setSequenceColour(
+                (SequenceI) sq.nextElement(), col))
+          ;
+      }
+      PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+      // alignPanel.updateAnnotation();
+      alignPanel.paintAlignment(true);
+    }
+  }
   protected void deleteGroups_actionPerformed()
   {
     viewport.alignment.deleteAllGroups();
@@ -2567,6 +2600,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   MenuItem deleteGroups = new MenuItem();
 
+  MenuItem grpsFromSelection= new MenuItem();
+
   MenuItem delete = new MenuItem();
 
   MenuItem copy = new MenuItem();
@@ -2745,6 +2780,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     nucleotideColour.addActionListener(this);
     deleteGroups.setLabel("Undefine Groups");
     deleteGroups.addActionListener(this);
+    grpsFromSelection.setLabel("Make Groups for selection");
+    grpsFromSelection.addActionListener(this);
     copy.setLabel("Copy");
     copy.addActionListener(this);
     cut.setLabel("Cut");
@@ -2934,7 +2971,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     selectMenu.add(deselectAllSequenceMenuItem);
     selectMenu.add(invertSequenceMenuItem);
     selectMenu.add(invertColSel);
+    selectMenu.add(grpsFromSelection);
     selectMenu.add(deleteGroups);
+    
   }
 
   MenuItem featureSettings = new MenuItem();
index 8e80376..1b3af30 100755 (executable)
@@ -1167,7 +1167,25 @@ public class AlignViewport
 
     return sequences;
   }
-
+  /**
+   * get the currently selected sequence objects or all the sequences in the
+   * alignment.
+   * 
+   * @return array of references to sequence objects
+   */
+  public SequenceI[] getSequenceSelection()
+  {
+    SequenceI[] sequences=null;
+    if (selectionGroup!=null)
+    {
+      sequences = selectionGroup.getSequencesInOrder(alignment);
+    }
+    if (sequences == null)
+    {
+      sequences = alignment.getSequencesArray();
+    }
+    return sequences;
+  }
   /**
    * This method returns the visible alignment as text, as seen on the GUI, ie
    * if columns are hidden they will not be returned in the result. Use this for