2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
24 * Holds the aligned column positions (base 0) for one codon in a nucleotide
25 * sequence, and (optionally) its peptide translation. The object is immutable
28 * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8).
30 * JBPComment: Is this useful anywhere other than jalview.analysis.Dna ?
35 public final class AlignedCodon
37 public final int pos1;
39 public final int pos2;
41 public final int pos3;
43 public final String product;
45 public AlignedCodon(int i, int j, int k)
50 public AlignedCodon(int i, int j, int k, String prod)
59 * Returns the column position for the given base (1, 2, 3).
63 * @throws IllegalArgumentException
64 * if an argument value other than 1, 2 or 3 is supplied
66 public int getBaseColumn(int base)
68 if (base < 1 || base > 3)
70 throw new IllegalArgumentException(Integer.toString(base));
72 return base == 1 ? pos1 : (base == 2 ? pos2 : pos3);
76 * Two aligned codons are equal if all their base positions are the same. We
77 * don't care about the protein product. This test is required for correct
78 * alignment of translated gapped dna alignments (the same codon positions in
79 * different sequences occupy the same column in the translated alignment).
82 public boolean equals(Object o)
85 * Equality with null value required for consistency with
92 if (!(o instanceof AlignedCodon))
96 AlignedCodon ac = (AlignedCodon) o;
97 return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3);
101 public String toString()
103 StringBuilder sb = new StringBuilder();
104 sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
105 .append(pos3).append("]");
106 return sb.toString();