package jalview.datamodel; /** * Holds the aligned column positions (base 0) for one codon in a nucleotide * sequence, and (optionally) its peptide translation. The object is immutable * once created. * * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8). * * JBPComment: Is this useful anywhere other than jalview.analysis.Dna ? * * @author gmcarstairs * */ public final class AlignedCodon { public final int pos1; public final int pos2; public final int pos3; public final String product; public AlignedCodon(int i, int j, int k) { this(i, j, k, null); } public AlignedCodon(int i, int j, int k, String prod) { pos1 = i; pos2 = j; pos3 = k; product = prod; } /** * Returns the column position for the given base (1, 2, 3). * * @param base * @return * @throws IllegalArgumentException * if an argument value other than 1, 2 or 3 is supplied */ public int getBaseColumn(int base) { if (base < 1 || base > 3) { throw new IllegalArgumentException(Integer.toString(base)); } return base == 1 ? pos1 : (base == 2 ? pos2 : pos3); } /** * Two aligned codons are equal if all their base positions are the same. We * don't care about the protein product. This test is required for correct * alignment of translated gapped dna alignments (the same codon positions in * different sequences occupy the same column in the translated alignment). */ @Override public boolean equals(Object o) { /* * Equality with null value required for consistency with * Dna.compareCodonPos */ if (o == null) { return true; } if (!(o instanceof AlignedCodon)) { return false; } AlignedCodon ac = (AlignedCodon) o; return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[").append(pos1).append(", ").append(pos2).append(", ") .append(pos3).append("]"); return sb.toString(); } }