Merge commit
[jalview.git] / src / jalview / workers / ComplementConsensusThread.java
diff --git a/src/jalview/workers/ComplementConsensusThread.java b/src/jalview/workers/ComplementConsensusThread.java
new file mode 100644 (file)
index 0000000..2e4424e
--- /dev/null
@@ -0,0 +1,68 @@
+package jalview.workers;
+
+import java.util.Hashtable;
+
+import jalview.analysis.AAFrequency;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+
+/**
+ * A thread to recompute the consensus of the cDNA complement for a linked
+ * protein alignment.
+ * 
+ * @author gmcarstairs
+ *
+ */
+public class ComplementConsensusThread extends ConsensusThread
+{
+
+  public ComplementConsensusThread(AlignViewportI alignViewport,
+          AlignmentViewPanel alignPanel)
+  {
+    super(alignViewport, alignPanel);
+  }
+
+  @Override
+  protected AlignmentAnnotation getConsensusAnnotation()
+  {
+    return alignViewport.getComplementConsensusAnnotation();
+  }
+
+  @Override
+  protected Hashtable[] getViewportConsensus()
+  {
+    return alignViewport.getComplementConsensusHash();
+  }
+
+  @Override
+  protected void computeConsensus(AlignmentI alignment)
+  {
+    Hashtable[] hconsensus = new Hashtable[alignment.getWidth()];
+
+    SequenceI[] aseqs = getSequences();
+    AAFrequency.calculateCdna(alignment, hconsensus);
+
+    alignViewport.setComplementConsensusHash(hconsensus);
+  }
+
+  /**
+   * Convert the computed consensus data into the desired annotation for
+   * display.
+   * 
+   * @param consensusAnnotation
+   *          the annotation to be populated
+   * @param consensusData
+   *          the computed consensus data
+   */
+  @Override
+  protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,
+          Hashtable[] consensusData)
+  {
+    AAFrequency.completeCdnaConsensus(consensusAnnotation, consensusData,
+            alignViewport.isShowSequenceLogo(), getSequences().length);
+  }
+
+}