~ubuntu-branches/ubuntu/utopic/figtree/utopic

« back to all changes in this revision

Viewing changes to src/figtree/treeviewer/decorators/ParsimonyBranchDecorator.java

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-02-21 08:17:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110221081738-80pe2ulo8rg7up10
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package figtree.treeviewer.decorators;
 
2
 
 
3
import jebl.evolution.trees.Tree;
 
4
import jebl.evolution.graphs.Node;
 
5
import jebl.evolution.alignments.Pattern;
 
6
import jebl.evolution.parsimony.ParsimonyCriterion;
 
7
import jebl.evolution.parsimony.FitchParsimony;
 
8
import jebl.evolution.sequences.State;
 
9
import jebl.evolution.sequences.Nucleotides;
 
10
import jebl.evolution.sequences.SequenceType;
 
11
import jebl.evolution.sequences.AminoAcids;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.List;
 
15
import java.awt.*;
 
16
 
 
17
/**
 
18
 * @author Andrew Rambaut
 
19
 * @author Alexei Drummond
 
20
 * @version $Id: ParsimonyBranchDecorator.java,v 1.4 2006/08/27 15:17:36 rambaut Exp $
 
21
 */
 
22
public class ParsimonyBranchDecorator {
 
23
 
 
24
    public ParsimonyBranchDecorator(Pattern pattern) {
 
25
        List<Pattern> patterns = new ArrayList<Pattern>();
 
26
        patterns.add(pattern);
 
27
        parsimony = new FitchParsimony(patterns, true);
 
28
 
 
29
        if (pattern.getSequenceType() == SequenceType.NUCLEOTIDE) {
 
30
            paints = new Paint[Nucleotides.getStateCount()];
 
31
            paints[Nucleotides.A_STATE.getIndex()] = Color.RED;
 
32
            paints[Nucleotides.C_STATE.getIndex()] = Color.BLUE;
 
33
            paints[Nucleotides.G_STATE.getIndex()] = Color.BLACK;
 
34
            paints[Nucleotides.T_STATE.getIndex()] = Color.GREEN;
 
35
            paints[Nucleotides.R_STATE.getIndex()] = Color.MAGENTA;
 
36
            paints[Nucleotides.Y_STATE.getIndex()] = Color.DARK_GRAY;
 
37
            paints[Nucleotides.M_STATE.getIndex()] = Color.DARK_GRAY;
 
38
            paints[Nucleotides.W_STATE.getIndex()] = Color.DARK_GRAY;
 
39
            paints[Nucleotides.S_STATE.getIndex()] = Color.DARK_GRAY;
 
40
            paints[Nucleotides.K_STATE.getIndex()] = Color.DARK_GRAY;
 
41
            paints[Nucleotides.B_STATE.getIndex()] = Color.DARK_GRAY;
 
42
            paints[Nucleotides.D_STATE.getIndex()] = Color.DARK_GRAY;
 
43
            paints[Nucleotides.H_STATE.getIndex()] = Color.DARK_GRAY;
 
44
            paints[Nucleotides.V_STATE.getIndex()] = Color.DARK_GRAY;
 
45
            paints[Nucleotides.N_STATE.getIndex()] = Color.GRAY;
 
46
            paints[Nucleotides.UNKNOWN_STATE.getIndex()] = Color.GRAY;
 
47
            paints[Nucleotides.GAP_STATE.getIndex()] = Color.GRAY;
 
48
        } else if (pattern.getSequenceType() == SequenceType.AMINO_ACID) {
 
49
            paints = new Paint[AminoAcids.getStateCount()];
 
50
            paints[AminoAcids.A_STATE.getIndex()] = new Color(204, 255, 255);
 
51
            paints[AminoAcids.C_STATE.getIndex()] = new Color(0, 255, 255);
 
52
            paints[AminoAcids.D_STATE.getIndex()] = new Color(255, 204, 153);
 
53
            paints[AminoAcids.E_STATE.getIndex()] = new Color(255, 204, 0);
 
54
            paints[AminoAcids.F_STATE.getIndex()] = new Color(0, 204, 255);
 
55
            paints[AminoAcids.G_STATE.getIndex()] = new Color(0, 255, 0);
 
56
            paints[AminoAcids.H_STATE.getIndex()] = new Color(255, 255, 153);
 
57
            paints[AminoAcids.I_STATE.getIndex()] = new Color(0, 0, 128);
 
58
            paints[AminoAcids.K_STATE.getIndex()] = new Color(198, 66, 0);
 
59
            paints[AminoAcids.L_STATE.getIndex()] = new Color(51, 102, 255);
 
60
            paints[AminoAcids.M_STATE.getIndex()] = new Color(153, 204, 255);
 
61
            paints[AminoAcids.N_STATE.getIndex()] = new Color(255, 153, 0);
 
62
            paints[AminoAcids.P_STATE.getIndex()] = new Color(255, 255, 0);
 
63
            paints[AminoAcids.Q_STATE.getIndex()] = new Color(255, 102, 0);
 
64
            paints[AminoAcids.R_STATE.getIndex()] = new Color(230, 6, 6);
 
65
            paints[AminoAcids.S_STATE.getIndex()] = new Color(204, 255, 153);
 
66
            paints[AminoAcids.T_STATE.getIndex()] = new Color(0, 255, 153);
 
67
            paints[AminoAcids.V_STATE.getIndex()] = new Color(0, 0, 255);
 
68
            paints[AminoAcids.W_STATE.getIndex()] = new Color(204, 153, 255);
 
69
            paints[AminoAcids.Y_STATE.getIndex()] = new Color(204, 255, 204);
 
70
            paints[AminoAcids.B_STATE.getIndex()] = Color.DARK_GRAY;
 
71
            paints[AminoAcids.Z_STATE.getIndex()] = Color.DARK_GRAY;
 
72
            paints[AminoAcids.X_STATE.getIndex()] = Color.GRAY;
 
73
            paints[AminoAcids.UNKNOWN_STATE.getIndex()] = Color.GRAY;
 
74
            paints[AminoAcids.STOP_STATE.getIndex()] = Color.GRAY;
 
75
            paints[AminoAcids.GAP_STATE.getIndex()] = Color.GRAY;
 
76
        } else {
 
77
            throw new IllegalArgumentException("Unsupported sequence type");
 
78
        }
 
79
    }
 
80
 
 
81
    public Paint getBranchPaint(Tree tree, Node node) {
 
82
        State[] states = parsimony.getStates(tree, node);
 
83
 
 
84
        return paints[states[0].getIndex()];
 
85
    }
 
86
 
 
87
    private final ParsimonyCriterion parsimony;
 
88
    private final Paint[] paints;
 
89
}
 
 
b'\\ No newline at end of file'