Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.datamodel

File AlignedCodon.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
29% of files have more coverage

Code metrics

10
18
5
1
114
51
11
0.61
3.6
5
2.2

Classes

Class Line # Actions
AlignedCodon 33 18 11
0.696969769.7%
 

Contributing tests

This file is covered by 21 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
23    /**
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
26    * once created.
27    *
28    * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8).
29    *
30    * @author gmcarstairs
31    *
32    */
 
33    public final class AlignedCodon
34    {
35    // base 1 aligned sequence position (base 0)
36    public final int pos1;
37   
38    // base 2 aligned sequence position (base 0)
39    public final int pos2;
40   
41    // base 3 aligned sequence position (base 0)
42    public final int pos3;
43   
44    // peptide aligned sequence position (base 0)
45    public final int peptideCol;
46   
47    // peptide coded for by this codon
48    public final String product;
49   
 
50  2063 toggle public AlignedCodon(int i, int j, int k)
51    {
52  2063 this(i, j, k, null, 0);
53    }
54   
 
55  12767 toggle public AlignedCodon(int i, int j, int k, String prod, int prodCol)
56    {
57  12767 pos1 = i;
58  12767 pos2 = j;
59  12767 pos3 = k;
60  12767 product = prod;
61  12767 peptideCol = prodCol;
62    }
63   
64    /**
65    * Returns the column position for the given base (1, 2, 3).
66    *
67    * @param base
68    * @return
69    * @throws IllegalArgumentException
70    * if an argument value other than 1, 2 or 3 is supplied
71    */
 
72  0 toggle public int getBaseColumn(int base)
73    {
74  0 if (base < 1 || base > 3)
75    {
76  0 throw new IllegalArgumentException(Integer.toString(base));
77    }
78  0 return base == 1 ? pos1 : (base == 2 ? pos2 : pos3);
79    }
80   
81    /**
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).
86    */
 
87  151769 toggle @Override
88    public boolean equals(Object o)
89    {
90    /*
91    * Equality with null value required for consistency with
92    * Dna.compareCodonPos
93    */
94  151769 if (o == null)
95    {
96  1 return true;
97    }
98  151768 if (!(o instanceof AlignedCodon))
99    {
100  1 return false;
101    }
102  151767 AlignedCodon ac = (AlignedCodon) o;
103  151767 return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3);
104    }
105   
 
106  184 toggle @Override
107    public String toString()
108    {
109  184 StringBuilder sb = new StringBuilder();
110  184 sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
111    .append(pos3).append("]");
112  184 return sb.toString();
113    }
114    }