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).
10 * JBPComment: Is this useful anywhere other than jalview.analysis.Dna ?
15 public final class AlignedCodon
17 public final int pos1;
19 public final int pos2;
21 public final int pos3;
23 public final String product;
25 public AlignedCodon(int i, int j, int k)
30 public AlignedCodon(int i, int j, int k, String prod)
39 * Returns the column position for the given base (1, 2, 3).
43 * @throws IllegalArgumentException
44 * if an argument value other than 1, 2 or 3 is supplied
46 public int getBaseColumn(int base)
48 if (base < 1 || base > 3)
50 throw new IllegalArgumentException(Integer.toString(base));
52 return base == 1 ? pos1 : (base == 2 ? pos2 : pos3);
56 * Two aligned codons are equal if all their base positions are the same. We
57 * don't care about the protein product. This test is required for correct
58 * alignment of translated gapped dna alignments (the same codon positions in
59 * different sequences occupy the same column in the translated alignment).
62 public boolean equals(Object o)
65 * Equality with null value required for consistency with
72 if (!(o instanceof AlignedCodon))
76 AlignedCodon ac = (AlignedCodon) o;
77 return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3);
81 public String toString()
83 StringBuilder sb = new StringBuilder();
84 sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
85 .append(pos3).append("]");