| 1 |
|
package jalview.workers; |
| 2 |
|
|
| 3 |
|
import jalview.analysis.AAFrequency; |
| 4 |
|
import jalview.api.AlignViewportI; |
| 5 |
|
import jalview.api.AlignmentViewPanel; |
| 6 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 7 |
|
import jalview.datamodel.AlignmentI; |
| 8 |
|
import jalview.datamodel.Annotation; |
| 9 |
|
import jalview.datamodel.HiddenMarkovModel; |
| 10 |
|
import jalview.datamodel.ProfilesI; |
| 11 |
|
import jalview.datamodel.SequenceGroup; |
| 12 |
|
import jalview.datamodel.SequenceI; |
| 13 |
|
import jalview.util.MessageManager; |
| 14 |
|
|
| 15 |
|
import java.util.ArrayList; |
| 16 |
|
import java.util.List; |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| |
|
| 0% |
Uncovered Elements: 108 (108) |
Complexity: 23 |
Complexity Density: 0.31 |
|
| 24 |
|
public class InformationThread extends AlignCalcWorker |
| 25 |
|
{ |
| 26 |
|
public static final String HMM_CALC_ID = "HMM"; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@param |
| 32 |
|
@param |
| 33 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 34 |
0 |
public InformationThread(AlignViewportI alignViewport,... |
| 35 |
|
AlignmentViewPanel alignPanel) |
| 36 |
|
{ |
| 37 |
0 |
super(alignViewport, alignPanel); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| |
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
| 44 |
0 |
@Override... |
| 45 |
|
public void run() |
| 46 |
|
{ |
| 47 |
0 |
if (alignViewport.getAlignment().getHmmSequences().isEmpty()) |
| 48 |
|
{ |
| 49 |
0 |
return; |
| 50 |
|
} |
| 51 |
0 |
if (alignViewport.isClosed()) |
| 52 |
|
{ |
| 53 |
0 |
abortAndDestroy(); |
| 54 |
0 |
return; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
| 58 |
0 |
int aWidth = alignment == null ? -1 : alignment.getWidth(); |
| 59 |
0 |
if (aWidth < 0) |
| 60 |
|
{ |
| 61 |
0 |
return; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
0 |
computeProfiles(alignment); |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
0 |
updateAnnotation(); |
| 74 |
|
|
| 75 |
0 |
if (ap != null) |
| 76 |
|
{ |
| 77 |
0 |
ap.adjustAnnotationHeight(); |
| 78 |
0 |
ap.paintAlignment(true, true); |
| 79 |
|
} |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@param |
| 88 |
|
@see |
| 89 |
|
|
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 90 |
0 |
protected void computeProfiles(AlignmentI alignment)... |
| 91 |
|
{ |
| 92 |
0 |
int width = alignment.getWidth(); |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
0 |
List<SequenceI> seqs = alignment.getHmmSequences(); |
| 98 |
0 |
if (!seqs.isEmpty()) |
| 99 |
|
{ |
| 100 |
0 |
HiddenMarkovModel hmm = seqs.get(0).getHMM(); |
| 101 |
0 |
ProfilesI hmmProfiles = AAFrequency.calculateHMMProfiles(hmm, width, |
| 102 |
|
0, width, alignViewport.isIgnoreBelowBackground(), |
| 103 |
|
alignViewport.isInfoLetterHeight()); |
| 104 |
0 |
alignViewport.setHmmProfiles(hmmProfiles); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
0 |
List<SequenceGroup> groups = alignment.getGroups(); |
| 111 |
0 |
for (SequenceGroup group : groups) |
| 112 |
|
{ |
| 113 |
0 |
seqs = group.getHmmSequences(); |
| 114 |
0 |
if (!seqs.isEmpty()) |
| 115 |
|
{ |
| 116 |
0 |
HiddenMarkovModel hmm = seqs.get(0).getHMM(); |
| 117 |
0 |
ProfilesI hmmProfiles = AAFrequency.calculateHMMProfiles(hmm, width, |
| 118 |
|
0, width, group.isIgnoreBelowBackground(), |
| 119 |
|
group.isUseInfoLetterHeight()); |
| 120 |
0 |
group.setHmmProfiles(hmmProfiles); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
@return |
| 129 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 130 |
0 |
protected SequenceI[] getSequences()... |
| 131 |
|
{ |
| 132 |
0 |
return alignViewport.getAlignment().getSequencesArray(); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
@return |
| 139 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
0 |
protected AlignmentAnnotation getGapAnnotation()... |
| 141 |
|
{ |
| 142 |
0 |
return alignViewport.getAlignmentGapAnnotation(); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| |
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
|
| 150 |
0 |
@Override... |
| 151 |
|
public void updateAnnotation() |
| 152 |
|
{ |
| 153 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
| 154 |
|
|
| 155 |
0 |
float maxInformation = 0f; |
| 156 |
0 |
List<AlignmentAnnotation> infos = new ArrayList<>(); |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
0 |
List<SequenceI> hmmSeqs = alignment.getHmmSequences(); |
| 162 |
0 |
if (!hmmSeqs.isEmpty()) |
| 163 |
|
{ |
| 164 |
0 |
ProfilesI profile = alignViewport.getHmmProfiles(); |
| 165 |
0 |
float m = updateInformationAnnotation(hmmSeqs.get(0), profile, null, |
| 166 |
|
infos); |
| 167 |
0 |
maxInformation = Math.max(maxInformation, m); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
0 |
for (SequenceGroup group : alignment.getGroups()) |
| 174 |
|
{ |
| 175 |
0 |
hmmSeqs = group.getHmmSequences(); |
| 176 |
0 |
if (!hmmSeqs.isEmpty()) |
| 177 |
|
{ |
| 178 |
0 |
ProfilesI profiles = group.getHmmProfiles(); |
| 179 |
0 |
float m = updateInformationAnnotation(hmmSeqs.get(0), profiles, |
| 180 |
|
group, infos); |
| 181 |
0 |
maxInformation = Math.max(maxInformation, m); |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
0 |
for (AlignmentAnnotation ann : infos) |
| 190 |
|
{ |
| 191 |
0 |
ann.graphMax = maxInformation; |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
@param |
| 204 |
|
@param |
| 205 |
|
@param |
| 206 |
|
@param |
| 207 |
|
@return |
| 208 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 209 |
0 |
protected float updateInformationAnnotation(SequenceI seq,... |
| 210 |
|
ProfilesI profile, SequenceGroup group, |
| 211 |
|
List<AlignmentAnnotation> infos) |
| 212 |
|
{ |
| 213 |
0 |
if (seq == null || profile == null) |
| 214 |
|
{ |
| 215 |
0 |
return 0f; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
0 |
AlignmentAnnotation ann = findOrCreateAnnotation(seq, group); |
| 219 |
|
|
| 220 |
0 |
seq.addAlignmentAnnotation(ann); |
| 221 |
0 |
infos.add(ann); |
| 222 |
|
|
| 223 |
0 |
float max = AAFrequency.completeInformation(ann, profile, |
| 224 |
|
profile.getStartColumn(), profile.getEndColumn() + 1); |
| 225 |
|
|
| 226 |
0 |
return max; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
@param |
| 238 |
|
@param |
| 239 |
|
@return |
| 240 |
|
|
| |
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.24 |
|
| 241 |
0 |
AlignmentAnnotation findOrCreateAnnotation(SequenceI seq,... |
| 242 |
|
SequenceGroup group) |
| 243 |
|
{ |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
0 |
AlignmentAnnotation info = null; |
| 249 |
|
|
| 250 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
| 251 |
0 |
AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation(); |
| 252 |
0 |
if (anns != null) |
| 253 |
|
{ |
| 254 |
0 |
for (AlignmentAnnotation ann : anns) |
| 255 |
|
{ |
| 256 |
0 |
if (HMM_CALC_ID.equals(ann.getCalcId()) && group == ann.groupRef) |
| 257 |
|
{ |
| 258 |
0 |
info = ann; |
| 259 |
0 |
info.setSequenceRef(seq); |
| 260 |
0 |
info.label = seq.getName(); |
| 261 |
0 |
break; |
| 262 |
|
} |
| 263 |
|
} |
| 264 |
|
} |
| 265 |
|
|
| 266 |
0 |
if (info == null) |
| 267 |
|
{ |
| 268 |
0 |
int aWidth = alignment.getWidth(); |
| 269 |
0 |
String desc = MessageManager |
| 270 |
|
.getString("label.information_description"); |
| 271 |
0 |
float graphMax = 6.52f; |
| 272 |
0 |
info = new AlignmentAnnotation(seq.getName(), desc, |
| 273 |
|
new Annotation[aWidth], 0f, graphMax, |
| 274 |
|
AlignmentAnnotation.BAR_GRAPH); |
| 275 |
0 |
info.setCalcId(HMM_CALC_ID); |
| 276 |
0 |
info.setSequenceRef(seq); |
| 277 |
0 |
info.groupRef = group; |
| 278 |
0 |
info.hasText = true; |
| 279 |
0 |
alignment.addAnnotation(info); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
0 |
return info; |
| 283 |
|
} |
| 284 |
|
} |