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).
33 public final class AlignedCodon
35 // base 1 aligned sequence position (base 0)
36 public final int pos1;
38 // base 2 aligned sequence position (base 0)
39 public final int pos2;
41 // base 3 aligned sequence position (base 0)
42 public final int pos3;
44 // peptide aligned sequence position (base 0)
45 public final int peptideCol;
47 // peptide coded for by this codon
48 public final String product;
50 public AlignedCodon(int i, int j, int k)
52 this(i, j, k, null, 0);
55 public AlignedCodon(int i, int j, int k, String prod, int prodCol)
65 * Returns the column position for the given base (1, 2, 3).
69 * @throws IllegalArgumentException
70 * if an argument value other than 1, 2 or 3 is supplied
72 public int getBaseColumn(int base)
74 if (base < 1 || base > 3)
76 throw new IllegalArgumentException(Integer.toString(base));
78 return base == 1 ? pos1 : (base == 2 ? pos2 : pos3);
82 * Two aligned codons are equal if all their base positions are the same. We
83 * don't care about the protein product. This test is required for correct
84 * alignment of translated gapped dna alignments (the same codon positions in
85 * different sequences occupy the same column in the translated alignment).
88 public boolean equals(Object o)
91 * Equality with null value required for consistency with
98 if (!(o instanceof AlignedCodon))
102 AlignedCodon ac = (AlignedCodon) o;
103 return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3);
107 public String toString()
109 StringBuilder sb = new StringBuilder();
110 sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
111 .append(pos3).append("]");
112 return sb.toString();