JAL-4392 Merging consensus secondary structure
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index 7e53c46..b5048a0 100755 (executable)
@@ -132,6 +132,9 @@ public class SequenceGroup implements AnnotatedCollectionI
    * consensus calculation property
    */
   private boolean showSequenceLogo = false;
+  
+
+  private boolean showSequenceSSLogo = false;
 
   /**
    * flag indicating if logo should be rendered normalised
@@ -149,10 +152,15 @@ public class SequenceGroup implements AnnotatedCollectionI
   private boolean hidecols = false;
 
   AlignmentAnnotation consensus = null;
+  
+
+  AlignmentAnnotation ssConsensus = null;
 
   AlignmentAnnotation conservation = null;
 
   private boolean showConsensusHistogram;
+  
+  private boolean showSSConsensusHistogram;
 
   private AnnotatedCollectionI context;
 
@@ -229,6 +237,7 @@ public class SequenceGroup implements AnnotatedCollectionI
       showSequenceLogo = seqsel.showSequenceLogo;
       normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
       showConsensusHistogram = seqsel.showConsensusHistogram;
+      showSSConsensusHistogram = seqsel.showSSConsensusHistogram;
       idColour = seqsel.idColour;
       outlineColour = seqsel.outlineColour;
       seqrep = seqsel.seqrep;
@@ -610,6 +619,21 @@ public class SequenceGroup implements AnnotatedCollectionI
         cs.setConsensus(cnsns);
         upd = true;
       }
+      
+      
+      ProfilesI ssCnsns = AAFrequency.calculateSS(sequences, startRes,
+              endRes + 1, showSequenceLogo);
+      if (ssConsensus != null)
+      {
+        _updateSSConsensusRow(ssCnsns, sequences.size());
+        upd = true;
+      }
+      if (cs != null)
+      {
+        cs.setSsConsensus(ssCnsns);
+        upd = true;
+      }
+      
 
       if ((conservation != null)
               || (cs != null && cs.conservationApplied()))
@@ -699,6 +723,33 @@ public class SequenceGroup implements AnnotatedCollectionI
     // for
     // ignoreGapsInConsensusCalculation);
   }
+  
+  public ProfilesI ssConsensusData = null;
+  
+  private void _updateSSConsensusRow(ProfilesI ssCnsns, long nseq)
+  {
+    if (ssConsensus == null)
+    {
+      getSSConsensus();
+    }
+    ssConsensus.label = "Sec Str Consensus for " + getName();
+    ssConsensus.description = "Percent Identity";
+    ssConsensusData = ssCnsns;
+    // preserve width if already set
+    int aWidth = (ssConsensus.annotations != null)
+            ? (endRes < ssConsensus.annotations.length
+                    ? ssConsensus.annotations.length
+                    : endRes + 1)
+            : endRes + 1;
+    ssConsensus.annotations = null;
+    ssConsensus.annotations = new Annotation[aWidth]; // should be alignment width
+
+    AAFrequency.completeSSConsensus(ssConsensus, ssCnsns, startRes, endRes + 1,
+            ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
+                                                            // container
+    // for
+    // ignoreGapsInConsensusCalculation);
+  }
 
   /**
    * @param s
@@ -1154,6 +1205,30 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
     return consensus;
   }
+  
+  public AlignmentAnnotation getSSConsensus()
+  {
+    // TODO get or calculate and get consensus annotation row for this group
+    int aWidth = this.getWidth();
+    // pointer
+    // possibility
+    // here.
+    if (aWidth < 0)
+    {
+      return null;
+    }
+    if (ssConsensus == null)
+    {
+      ssConsensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
+              100f, AlignmentAnnotation.BAR_GRAPH);
+      ssConsensus.hasText = true;
+      ssConsensus.autoCalculated = true;
+      ssConsensus.groupRef = this;
+      ssConsensus.label = "Sec Str Consensus for " + getName();
+      ssConsensus.description = "Percent Identity";
+    }
+    return ssConsensus;
+  }
 
   /**
    * set this alignmentAnnotation object as the one used to render consensus
@@ -1256,6 +1331,18 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
     this.showSequenceLogo = showSequenceLogo;
   }
+  
+  
+  public void setshowSequenceSSLogo(boolean showSequenceSSLogo)
+  {
+    // TODO: decouple calculation from settings update
+    if (this.showSequenceSSLogo != showSequenceSSLogo && ssConsensus != null)
+    {
+      this.showSequenceSSLogo = showSequenceSSLogo;
+      recalcConservation();
+    }
+    this.showSequenceSSLogo = showSequenceSSLogo;
+  }
 
   /**
    * 
@@ -1273,6 +1360,17 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
     this.showConsensusHistogram = showConsHist;
   }
+  
+  public void setShowSSConsensusHistogram(boolean showSSConsHist)
+  {
+
+    if (showSSConsensusHistogram != showSSConsHist && consensus != null)
+    {
+      this.showSSConsensusHistogram = showSSConsHist;
+      recalcConservation();
+    }
+    this.showSSConsensusHistogram = showSSConsHist;
+  }
 
   /**
    * @return the showConsensusHistogram