1 /* 2 * Jalview - A Sequence Alignment Editor and Viewer (2.11.1.4) 3 * Copyright (C) 2021 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 * A profile for one column of an alignment 25 * 26 * @author gmcarstairs 27 * 28 */ 29 public class Profile implements ProfileI 30 { 31 /* 32 * an object holding counts of symbols in the profile 33 */ 34 private ResidueCount counts; 35 36 /* 37 * the number of sequences (gapped or not) in the profile 38 */ 39 private int height; 40 41 /* 42 * the number of non-gapped sequences in the profile 43 */ 44 private int gapped; 45 46 /* 47 * the highest count for any residue in the profile 48 */ 49 private int maxCount; 50 51 /* 52 * the residue (e.g. K) or residues (e.g. KQW) with the 53 * highest count in the profile 54 */ 55 private String modalResidue; 56 57 /** 58 * Constructor which allows derived data to be stored without having to store 59 * the full profile 60 * 61 * @param seqCount 62 * the number of sequences in the profile 63 * @param gaps 64 * the number of gapped sequences 65 * @param max 66 * the highest count for any residue 67 * @param modalres 68 * the residue (or concatenated residues) with the highest count 69 */ Profile(int seqCount, int gaps, int max, String modalRes)70 public Profile(int seqCount, int gaps, int max, String modalRes) 71 { 72 this.height = seqCount; 73 this.gapped = gaps; 74 this.maxCount = max; 75 this.modalResidue = modalRes; 76 } 77 78 /* (non-Javadoc) 79 * @see jalview.datamodel.ProfileI#setCounts(jalview.datamodel.ResidueCount) 80 */ 81 @Override setCounts(ResidueCount residueCounts)82 public void setCounts(ResidueCount residueCounts) 83 { 84 this.counts = residueCounts; 85 } 86 87 /* (non-Javadoc) 88 * @see jalview.datamodel.ProfileI#getPercentageIdentity(boolean) 89 */ 90 @Override getPercentageIdentity(boolean ignoreGaps)91 public float getPercentageIdentity(boolean ignoreGaps) 92 { 93 if (height == 0) 94 { 95 return 0f; 96 } 97 float pid = 0f; 98 if (ignoreGaps && gapped < height) 99 { 100 pid = (maxCount * 100f) / (height - gapped); 101 } 102 else 103 { 104 pid = (maxCount * 100f) / height; 105 } 106 return pid; 107 } 108 109 /* (non-Javadoc) 110 * @see jalview.datamodel.ProfileI#getCounts() 111 */ 112 @Override getCounts()113 public ResidueCount getCounts() 114 { 115 return counts; 116 } 117 118 /* (non-Javadoc) 119 * @see jalview.datamodel.ProfileI#getHeight() 120 */ 121 @Override getHeight()122 public int getHeight() 123 { 124 return height; 125 } 126 127 /* (non-Javadoc) 128 * @see jalview.datamodel.ProfileI#getGapped() 129 */ 130 @Override getGapped()131 public int getGapped() 132 { 133 return gapped; 134 } 135 136 /* (non-Javadoc) 137 * @see jalview.datamodel.ProfileI#getMaxCount() 138 */ 139 @Override getMaxCount()140 public int getMaxCount() 141 { 142 return maxCount; 143 } 144 145 /* (non-Javadoc) 146 * @see jalview.datamodel.ProfileI#getModalResidue() 147 */ 148 @Override getModalResidue()149 public String getModalResidue() 150 { 151 return modalResidue; 152 } 153 154 /* (non-Javadoc) 155 * @see jalview.datamodel.ProfileI#getNonGapped() 156 */ 157 @Override getNonGapped()158 public int getNonGapped() 159 { 160 return height - gapped; 161 } 162 } 163