1 package jalview.datamodel;
4 * Holds the aligned column positions (base 0) for one codon in a nucleotide
5 * sequence, and (optionally) its peptide translation. The object is immutable
8 * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8).
13 public final class AlignedCodon
15 public final int pos1;
17 public final int pos2;
19 public final int pos3;
21 public final String product;
23 public AlignedCodon(int i, int j, int k)
28 public AlignedCodon(int i, int j, int k, String prod)
37 * Returns the column position for the given base (1, 2, 3).
41 * @throws IllegalArgumentException
42 * if an argument value other than 1, 2 or 3 is supplied
44 public int getBaseColumn(int base)
46 if (base < 1 || base > 3)
48 throw new IllegalArgumentException(Integer.toString(base));
50 return base == 1 ? pos1 : (base == 2 ? pos2 : pos3);
54 * Two aligned codons are equal if all their base positions are the same. We
55 * don't care about the protein product. This test is required for correct
56 * alignment of translated gapped dna alignments (the same codon positions in
57 * different sequences occupy the same column in the translated alignment).
60 public boolean equals(Object o)
63 * Equality with null value required for consistency with
70 if (!(o instanceof AlignedCodon))
74 AlignedCodon ac = (AlignedCodon) o;
75 return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3);
79 public String toString()
81 StringBuilder sb = new StringBuilder();
82 sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
83 .append(pos3).append("]");