new methods for testing for/storing selection/group membership re JAL-716
authorjprocter <Jim Procter>
Thu, 9 Dec 2010 15:29:48 +0000 (15:29 +0000)
committerjprocter <Jim Procter>
Thu, 9 Dec 2010 15:29:48 +0000 (15:29 +0000)
src/jalview/datamodel/SeqCigar.java

index b2a1f66..b937118 100644 (file)
@@ -17,7 +17,9 @@
  */
 package jalview.datamodel;
 
+import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Vector;
 
 import jalview.analysis.*;
 import jalview.util.*;
@@ -429,12 +431,16 @@ public class SeqCigar extends CigarSimple
   }
 
   /**
-   * createAlignment
+   * create an alignment from the given array of cigar sequences and gap
+   * character, and marking the given segments as visible in the given
+   * columselection.
    * 
    * @param alseqs
-   *          SeqCigar[]
    * @param gapCharacter
-   *          char
+   * @param colsel
+   *          - columnSelection where hidden regions are marked
+   * @param segments
+   *          - visible regions of alignment
    * @return SequenceI[]
    */
   public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs,
@@ -688,4 +694,77 @@ public class SeqCigar extends CigarSimple
     // System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring());
   }
 
+  /**
+   * references to entities that this sequence cigar is associated with.
+   */
+  private Hashtable selGroups = null;
+
+  public void setGroupMembership(Object group)
+  {
+    if (selGroups == null)
+    {
+      selGroups = new Hashtable();
+    }
+    selGroups.put(group, new int[0]);
+  }
+
+  /**
+   * Test for and if present remove association to group.
+   * 
+   * @param group
+   * @return true if group was associated and it was removed
+   */
+  public boolean removeGroupMembership(Object group)
+  {
+    if (selGroups != null && selGroups.containsKey(group))
+    {
+      selGroups.remove(group);
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * forget all associations for this sequence.
+   */
+  public void clearMemberships()
+  {
+    if (selGroups != null)
+    {
+      selGroups.clear();
+    }
+    selGroups = null;
+  }
+
+  /**
+   * 
+   * @return null or array of all associated entities
+   */
+  public Object[] getAllMemberships()
+  {
+    if (selGroups == null)
+    {
+      return null;
+    }
+    Object[] mmbs = new Object[selGroups.size()];
+    Enumeration en = selGroups.keys();
+    for (int i = 0; en.hasMoreElements(); i++)
+    {
+      mmbs[i] = en.nextElement();
+    }
+    return mmbs;
+  }
+
+  /**
+   * Test for group membership
+   * 
+   * @param sgr
+   *          - a selection group or some other object that may be associated
+   *          with seqCigar
+   * @return true if sgr is associated with this seqCigar
+   */
+  public boolean isMemberOf(Object sgr)
+  {
+    return (selGroups != null) && selGroups.get(sgr) != null;
+  }
 }