JAL-1681 show cDNA consensus on protein alignment - first version
[jalview.git] / src / jalview / workers / ComplementConsensusThread.java
1 package jalview.workers;
2
3 import jalview.analysis.AAFrequency;
4 import jalview.api.AlignViewportI;
5 import jalview.api.AlignmentViewPanel;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.SequenceI;
9
10 import java.util.Hashtable;
11
12 /**
13  * A thread to recompute the consensus of the cDNA complement for a linked
14  * protein alignment.
15  * 
16  * @author gmcarstairs
17  *
18  */
19 public class ComplementConsensusThread extends ConsensusThread
20 {
21
22   public ComplementConsensusThread(AlignViewportI alignViewport,
23           AlignmentViewPanel alignPanel)
24   {
25     super(alignViewport, alignPanel);
26   }
27
28   @Override
29   protected AlignmentAnnotation getConsensusAnnotation()
30   {
31     return alignViewport.getComplementConsensusAnnotation();
32   }
33
34   @Override
35   protected Hashtable[] getViewportConsensus()
36   {
37     return alignViewport.getComplementConsensusHash();
38   }
39
40   @Override
41   protected void computeConsensus(AlignmentI alignment)
42   {
43     Hashtable[] hconsensus = new Hashtable[alignment.getWidth()];
44
45     SequenceI[] aseqs = getSequences();
46     AAFrequency.calculateCdna(alignment, hconsensus);
47
48     alignViewport.setComplementConsensusHash(hconsensus);
49   }
50
51   /**
52    * Convert the computed consensus data into the desired annotation for
53    * display.
54    * 
55    * @param consensusAnnotation
56    *          the annotation to be populated
57    * @param consensusData
58    *          the computed consensus data
59    */
60   @Override
61   protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,
62           Hashtable[] consensusData)
63   {
64     AAFrequency.completeCdnaConsensus(consensusAnnotation, consensusData,
65             alignViewport.isShowSequenceLogo(), getSequences().length);
66   }
67
68 }