1 package jalview.workers;
3 import java.util.ConcurrentModificationException;
4 import java.util.Hashtable;
7 import jalview.analysis.AAFrequency;
8 import jalview.api.AlignCalcWorkerI;
9 import jalview.api.AlignViewportI;
10 import jalview.api.AlignmentViewPanel;
11 import jalview.datamodel.AlignedCodonFrame;
12 import jalview.datamodel.AlignmentAnnotation;
15 * A thread to recompute the consensus of the cDNA complement for a linked
21 public class ComplementConsensusThread extends ConsensusThread
24 private Set<AlignedCodonFrame> mappings;
28 public AlignCalcWorkerI getNewWorker() {
29 return new ComplementConsensusThread(alignViewport, ap);
32 public ComplementConsensusThread(AlignViewportI alignViewport,
33 AlignmentViewPanel alignPanel)
35 super(alignViewport, alignPanel);
39 protected AlignmentAnnotation getConsensusAnnotation()
41 return alignViewport.getComplementConsensusAnnotation();
45 protected Hashtable[] getViewportConsensus()
47 return alignViewport.getComplementConsensusHash();
51 protected boolean initializeCalc() {
52 mappings = alignment.getCodonFrames();
53 return (mappings != null && !mappings.isEmpty() && super.initializeCalc());
57 * Calculate the cDNA consensus and store it on the Viewport
60 protected void computeConsensus()
63 * Allow 3 tries at this, since this thread can start up while we are still
64 * modifying protein-codon mappings on the alignment
66 for (int i = 0; i < 3; i++)
70 AAFrequency.calculateCdna(alignment, mappings, hconsensus, iFirst, iLast);
72 } catch (ConcurrentModificationException e)
80 protected void finalizeCalc() {
81 alignViewport.setComplementConsensusHash(hconsensus);
86 * Convert the computed consensus data into the desired annotation for
89 * @param consensusAnnotation
90 * the annotation to be populated
91 * @param consensusData
92 * the computed consensus data
95 protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,
96 Hashtable[] consensusData)
98 AAFrequency.completeCdnaConsensus(consensusAnnotation, consensusData,
99 alignViewport.isShowSequenceLogo(), getSequences().length);