basic implementation of profile display and todos
authorjprocter <Jim Procter>
Fri, 21 Aug 2009 11:00:33 +0000 (11:00 +0000)
committerjprocter <Jim Procter>
Fri, 21 Aug 2009 11:00:33 +0000 (11:00 +0000)
src/jalview/datamodel/SequenceGroup.java

index 9236712..db52a60 100755 (executable)
@@ -79,7 +79,23 @@ public class SequenceGroup
 
   public Color textColour2 = Color.white;
 
-  private boolean ignoreGapsInConsensusCalculation=true;
+  /**
+   * consensus calculation property
+   */
+  private boolean ignoreGapsInConsensus=true;
+  /**
+   * consensus calculation property
+   */
+  private boolean includeAllConsSymbols=false;
+
+  /**
+   * @return the includeAllConsSymbols
+   */
+  public boolean isIncludeAllConsSymbols()
+  {
+    return includeAllConsSymbols;
+  }
+
 
   /**
    * Creates a new SequenceGroup object.
@@ -151,7 +167,7 @@ public class SequenceGroup
       textColour2 = seqsel.textColour2;
       thresholdTextColour = seqsel.thresholdTextColour;
       width = seqsel.width;
-      ignoreGapsInConsensusCalculation = seqsel.ignoreGapsInConsensusCalculation;
+      ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
       if (seqsel.conserve!=null)
       {
         recalcConservation(); // safer than 
@@ -387,6 +403,7 @@ public class SequenceGroup
   public void setName(String name)
   {
     groupName = name;
+    // TODO: URGENT: update dependent objects (annotation row)
   }
 
   public void setDescription(String desc)
@@ -448,7 +465,7 @@ public class SequenceGroup
     
     try
     {
-      Hashtable cnsns[] = AAFrequency.calculate(sequences, startRes, endRes + 1);
+      Hashtable cnsns[] = AAFrequency.calculate(sequences, startRes, endRes + 1, includeAllConsSymbols);
       if (consensus != null)
       {
         _updateConsensusRow(cnsns);
@@ -500,30 +517,29 @@ public class SequenceGroup
     }
     // preserve width if already set
     int aWidth = (conservation.annotations!=null) ? (endRes<conservation.annotations.length ? conservation.annotations.length : endRes+1) : endRes+1;
-    c.completeAnnotations(conservation,null, aWidth);
+    conservation.annotations = null;
+    conservation.annotations = new Annotation[aWidth]; // should be alignment width
+    c.completeAnnotations(conservation,null, startRes, endRes+1);
   }
-
+  public Hashtable[] consensusData = null;
   private void _updateConsensusRow(Hashtable[] cnsns)
   {
     if (consensus==null)
     {
       getConsensus();
     }
+    consensusData = cnsns;
     // preserve width if already set
     int aWidth = (consensus.annotations!=null) ? (endRes<consensus.annotations.length ? consensus.annotations.length : endRes+1) : endRes+1;
     consensus.annotations = null;
     consensus.annotations = new Annotation[aWidth]; // should be alignment width
 
-    AAFrequency.completeConsensus(consensus,cnsns,startRes,endRes,ignoreGapsInConsensusCalculation); // TODO: setting container for ignoreGapsInConsensusCalculation);
+    AAFrequency.completeConsensus(consensus,cnsns,startRes,endRes+1,ignoreGapsInConsensus, includeAllConsSymbols); // TODO: setting container for ignoreGapsInConsensusCalculation);
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param s
-   *                DOCUMENT ME!
-   * @param recalc
-   *                DOCUMENT ME!
+   * @param s sequence to either add or remove from group
+   * @param recalc flag passed to delete/addSequence to indicate if group properties should be recalculated
    */
   public void addOrRemove(SequenceI s, boolean recalc)
   {
@@ -932,8 +948,8 @@ public class SequenceGroup
   public AlignmentAnnotation getConservationRow() {
     int ConsPercGaps = 25;
     if (conservation == null) {
-      conservation = new AlignmentAnnotation("Conservation",
-            "Conservation of total alignment less than " + ConsPercGaps
+      conservation = new AlignmentAnnotation("Conservation for "+getName(),
+            "Conservation for group "+getName()+" less than " + ConsPercGaps
                     + "% gaps", new Annotation[1], 0f, 11f,
             AlignmentAnnotation.BAR_GRAPH);
     conservation.hasText = true;
@@ -974,17 +990,32 @@ public class SequenceGroup
 
     SequenceI sq = new Sequence("Group"+getName()+" Consensus", seqs.toString());
     sq.setDescription("Percentage Identity Consensus "
-            + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+            + ((ignoreGapsInConsensus) ? " without gaps" : ""));
     return sq;    
   }
 
   public void setIgnoreGapsConsensus(boolean state)
   {
-    if (this.ignoreGapsInConsensusCalculation!=state && consensus!=null)
+    if (this.ignoreGapsInConsensus!=state && consensus!=null)
     {
-      ignoreGapsInConsensusCalculation = state;
+      ignoreGapsInConsensus = state;
+      recalcConservation();
+    }
+    ignoreGapsInConsensus = state;
+  }
+  public boolean getIgnoreGapsConsensus()
+  {
+    return ignoreGapsInConsensus;
+  }
+  /**
+   * @param includeAllConsSymbols the includeAllConsSymbols to set
+   */
+  public void setIncludeAllConsSymbols(boolean includeAllConsSymbols)
+  {
+    if (this.includeAllConsSymbols!=includeAllConsSymbols && consensus!=null) {
+      this.includeAllConsSymbols = includeAllConsSymbols;
       recalcConservation();
     }
-    ignoreGapsInConsensusCalculation = state;
+    this.includeAllConsSymbols = includeAllConsSymbols;
   }
 }