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;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.renderer.ResidueShader;
26 import jalview.renderer.ResidueShaderI;
27 import jalview.schemes.ColourSchemeI;
28 import jalview.util.MessageManager;
29 import jalview.workers.InformationThread;
31 import java.awt.Color;
32 import java.beans.PropertyChangeListener;
33 import java.beans.PropertyChangeSupport;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
40 * Collects a set contiguous ranges on a set of sequences
45 public class SequenceGroup implements AnnotatedCollectionI
47 // TODO ideally this event notification functionality should be separated into
48 // a subclass of ViewportProperties similarly to ViewportRanges.
49 // Done here as a quick fix for JAL-2665
50 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
52 private String groupName;
54 private String description;
56 private AnnotatedCollectionI context;
58 private Conservation conservationData;
60 private ProfilesI consensusProfiles;
62 private ProfilesI hmmProfiles;
64 private boolean displayBoxes = true;
66 private boolean displayText = true;
68 private boolean colourText = false;
71 * true if the group is defined as a group on the alignment, false if it is
74 private boolean isDefined;
77 * after Olivier's non-conserved only character display
79 private boolean showNonconserved;
82 * sequences in the group
84 private List<SequenceI> sequences = new ArrayList<>();
87 * representative sequence for this group (if any)
89 private SequenceI seqrep;
91 private int width = -1;
94 * colour scheme applied to group if any
96 public ResidueShaderI cs;
98 // start column (base 0)
101 // end column (base 0)
104 public Color outlineColour = Color.black;
106 public Color idColour;
108 public int thresholdTextColour;
110 public Color textColour = Color.black;
112 public Color textColour2 = Color.white;
115 * properties for consensus annotation
117 private boolean ignoreGapsInConsensus = true;
119 private boolean showSequenceLogo;
121 private boolean normaliseSequenceLogo;
123 private boolean showConsensusHistogram;
126 * properties for HMM information annotation
128 private boolean hmmIgnoreBelowBackground = true;
130 private boolean hmmUseInfoLetterHeight;
132 private boolean hmmShowSequenceLogo;
134 private boolean hmmNormaliseSequenceLogo;
136 private boolean hmmShowHistogram;
139 * visibility of rows or represented rows covered by group
141 private boolean hidereps;
144 * visibility of columns intersecting this group
146 private boolean hidecols;
148 private AlignmentAnnotation consensus;
150 private AlignmentAnnotation conservation;
152 private AlignmentAnnotation hmmInformation;
155 * Constructor, assigning a generated default name of "JGroup:" with object
158 public SequenceGroup()
160 groupName = "JGroup:" + this.hashCode();
161 cs = new ResidueShader();
165 * Creates a new SequenceGroup object.
170 * @param displayBoxes
174 * first column of group
176 * last column of group
178 public SequenceGroup(List<SequenceI> sequences, String groupName,
179 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
180 boolean colourText, int start, int end)
183 this.sequences = sequences;
184 this.groupName = groupName;
185 this.displayBoxes = displayBoxes;
186 this.displayText = displayText;
187 this.colourText = colourText;
188 this.cs = new ResidueShader(scheme);
191 recalcConservation();
199 public SequenceGroup(SequenceGroup seqsel)
204 sequences = new ArrayList<>();
205 sequences.addAll(seqsel.sequences);
206 if (seqsel.groupName != null)
208 groupName = new String(seqsel.groupName);
210 displayBoxes = seqsel.displayBoxes;
211 displayText = seqsel.displayText;
212 colourText = seqsel.colourText;
213 startRes = seqsel.startRes;
214 endRes = seqsel.endRes;
215 cs = new ResidueShader((ResidueShader) seqsel.cs);
216 if (seqsel.description != null)
218 description = new String(seqsel.description);
220 hidecols = seqsel.hidecols;
221 hidereps = seqsel.hidereps;
222 showNonconserved = seqsel.showNonconserved;
223 showSequenceLogo = seqsel.showSequenceLogo;
224 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
225 showConsensusHistogram = seqsel.showConsensusHistogram;
226 hmmShowSequenceLogo = seqsel.hmmShowSequenceLogo;
227 hmmNormaliseSequenceLogo = seqsel.hmmNormaliseSequenceLogo;
228 hmmShowHistogram = seqsel.hmmShowHistogram;
229 idColour = seqsel.idColour;
230 outlineColour = seqsel.outlineColour;
231 seqrep = seqsel.seqrep;
232 textColour = seqsel.textColour;
233 textColour2 = seqsel.textColour2;
234 thresholdTextColour = seqsel.thresholdTextColour;
235 width = seqsel.width;
236 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
237 hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
238 hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
239 if (seqsel.conservationData != null)
241 recalcConservation(); // safer than
242 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
247 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
250 public void addPropertyChangeListener(PropertyChangeListener listener)
252 changeSupport.addPropertyChangeListener(listener);
255 public void removePropertyChangeListener(PropertyChangeListener listener)
257 changeSupport.removePropertyChangeListener(listener);
260 public boolean isShowSequenceLogo()
262 return showSequenceLogo;
265 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
267 int iSize = sequences.size();
268 SequenceI[] seqs = new SequenceI[iSize];
269 SequenceI[] inorder = getSequencesInOrder(align);
271 for (int i = 0, ipos = 0; i < inorder.length; i++)
273 SequenceI seq = inorder[i];
275 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
276 if (seqs[ipos] != null)
278 seqs[ipos].setDescription(seq.getDescription());
279 seqs[ipos].setDBRefs(seq.getDBRefs());
280 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
281 if (seq.getDatasetSequence() != null)
283 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
286 if (seq.getAnnotation() != null)
288 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
289 // Only copy annotation that is either a score or referenced by the
290 // alignment's annotation vector
291 for (int a = 0; a < seq.getAnnotation().length; a++)
293 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
296 boolean found = false;
297 for (int pos = 0; pos < alann.length; pos++)
299 if (alann[pos] == tocopy)
310 AlignmentAnnotation newannot = new AlignmentAnnotation(
311 seq.getAnnotation()[a]);
312 newannot.restrict(startRes, endRes);
313 newannot.setSequenceRef(seqs[ipos]);
314 newannot.adjustForAlignment();
315 seqs[ipos].addAlignmentAnnotation(newannot);
325 if (iSize != inorder.length)
327 SequenceI[] nseqs = new SequenceI[iSize];
328 System.arraycopy(seqs, 0, nseqs, 0, iSize);
336 * If sequence ends in gaps, the end residue can be correctly calculated here
342 public int findEndRes(SequenceI seq)
347 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
349 ch = seq.getCharAt(j);
350 if (!jalview.util.Comparison.isGap((ch)))
358 eres += seq.getStart() - 1;
365 public List<SequenceI> getSequences()
371 public List<SequenceI> getSequences(
372 Map<SequenceI, SequenceCollectionI> hiddenReps)
374 if (hiddenReps == null)
376 // TODO: need a synchronizedCollection here ?
381 List<SequenceI> allSequences = new ArrayList<>();
382 for (SequenceI seq : sequences)
384 allSequences.add(seq);
385 if (hiddenReps.containsKey(seq))
387 SequenceCollectionI hsg = hiddenReps.get(seq);
388 for (SequenceI seq2 : hsg.getSequences())
390 if (seq2 != seq && !allSequences.contains(seq2))
392 allSequences.add(seq2);
402 public SequenceI[] getSequencesAsArray(
403 Map<SequenceI, SequenceCollectionI> map)
405 List<SequenceI> tmp = getSequences(map);
410 return tmp.toArray(new SequenceI[tmp.size()]);
419 * @return DOCUMENT ME!
421 public boolean adjustForRemoveLeft(int col)
423 // return value is true if the group still exists
426 startRes = startRes - col;
431 endRes = endRes - col;
433 if (startRes > endRes)
440 // must delete this group!!
453 * @return DOCUMENT ME!
455 public boolean adjustForRemoveRight(int col)
474 * @return DOCUMENT ME!
476 public String getName()
481 public String getDescription()
492 public void setName(String name)
495 // TODO: URGENT: update dependent objects (annotation row)
498 public void setDescription(String desc)
506 * @return DOCUMENT ME!
508 public Conservation getConservation()
510 return conservationData;
519 public void setConservation(Conservation c)
521 conservationData = c;
525 * Add s to this sequence group. If aligment sequence is already contained in
526 * group, it will not be added again, but recalculation may happen if the flag
530 * alignment sequence to be added
532 * true means Group's conservation should be recalculated
534 public void addSequence(SequenceI s, boolean recalc)
536 synchronized (sequences)
538 if (s != null && !sequences.contains(s))
541 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
542 sequences.size() - 1, sequences.size());
547 recalcConservation();
553 * Max Gaps Threshold (percent) for performing a conservation calculation
555 private int consPercGaps = 25;
558 * @return Max Gaps Threshold for performing a conservation calculation
560 public int getConsPercGaps()
566 * set Max Gaps Threshold (percent) for performing a conservation calculation
568 * @param consPercGaps
570 public void setConsPercGaps(int consPercGaps)
572 this.consPercGaps = consPercGaps;
576 * calculate residue conservation and colourschemes for group - but only if
577 * necessary. returns true if the calculation resulted in a visible change to
580 public boolean recalcConservation()
582 return recalcAnnotations(false);
586 * Recalculates column consensus, conservation, and HMM annotation for the
587 * group (as applicable). Returns true if the calculation resulted in a
588 * visible change to group.
591 * when set, colourschemes for this group are not refreshed after
594 public boolean recalcAnnotations(boolean defer)
596 if (cs == null && consensus == null && conservation == null
597 && hmmInformation == null)
601 // TODO: try harder to detect changes in state in order to minimise
602 // recalculation effort
606 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
607 endRes + 1, showSequenceLogo);
608 if (hmmInformation != null)
610 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
612 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
613 (endRes + 1) - startRes, startRes, endRes + 1,
614 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
615 _updateInformationRow(info);
618 if (consensus != null)
620 _updateConsensusRow(cnsns, sequences.size());
625 cs.setConsensus(cnsns);
629 if ((conservation != null)
630 || (cs != null && cs.conservationApplied()))
632 Conservation c = new Conservation(groupName, sequences, startRes,
635 c.verdict(false, consPercGaps);
636 if (conservation != null)
638 _updateConservationRow(c);
642 if (cs.conservationApplied())
644 cs.setConservation(c);
647 // eager update - will cause a refresh of overview regardless
650 if (cs != null && !defer)
652 // TODO: JAL-2034 should cs.alignmentChanged modify return state
653 cs.alignmentChanged(context != null ? context : this, null);
660 } catch (java.lang.OutOfMemoryError err)
663 System.out.println("Out of memory loading groups: " + err);
668 private void _updateConservationRow(Conservation c)
670 if (conservation == null)
675 conservation.label = "Conservation for " + getName();
676 conservation.description = "Conservation for group " + getName()
677 + " less than " + consPercGaps + "% gaps";
678 // preserve width if already set
679 int aWidth = (conservation.annotations != null)
680 ? (endRes < conservation.annotations.length
681 ? conservation.annotations.length
684 conservation.annotations = null;
685 conservation.annotations = new Annotation[aWidth]; // should be alignment
687 c.completeAnnotations(conservation, null, startRes, endRes + 1);
690 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
692 if (consensus == null)
696 consensus.label = "Consensus for " + getName();
697 consensus.description = "Percent Identity";
698 consensusProfiles = cnsns;
699 // preserve width if already set
700 int aWidth = (consensus.annotations != null)
701 ? (endRes < consensus.annotations.length
702 ? consensus.annotations.length
705 consensus.annotations = null;
706 consensus.annotations = new Annotation[aWidth]; // should be alignment width
708 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
709 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
712 // ignoreGapsInConsensusCalculation);
716 * Recalculates the information content on the HMM annotation
720 private void _updateInformationRow(ProfilesI cnsns)
722 if (hmmInformation == null)
724 createInformationAnnotation();
726 hmmInformation.description = MessageManager
727 .getString("label.information_description");
728 setHmmProfiles(cnsns);
729 // preserve width if already set
730 int aWidth = (hmmInformation.annotations != null)
731 ? (endRes < hmmInformation.annotations.length
732 ? hmmInformation.annotations.length : endRes + 1)
734 hmmInformation.annotations = null;
735 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
737 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
738 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
744 * sequence to either add or remove from group
746 * flag passed to delete/addSequence to indicate if group properties
747 * should be recalculated
749 public void addOrRemove(SequenceI s, boolean recalc)
751 synchronized (sequences)
753 if (sequences.contains(s))
755 deleteSequence(s, recalc);
759 addSequence(s, recalc);
770 * true means recalculate conservation
772 public void deleteSequence(SequenceI s, boolean recalc)
774 synchronized (sequences)
777 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
778 sequences.size() + 1, sequences.size());
782 recalcConservation();
790 * @return the first column selected by this group. Runs from 0<=i<N_cols
793 public int getStartRes()
800 * @return the groups last selected column. Runs from 0<=i<N_cols
803 public int getEndRes()
809 * Set the first column selected by this group. Runs from 0<=i<N_cols
813 public void setStartRes(int i)
815 int before = startRes;
817 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
821 * Set the groups last selected column. Runs from 0<=i<N_cols
825 public void setEndRes(int i)
829 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
833 * @return number of sequences in group
837 return sequences.size();
842 * @return the ith sequence
844 public SequenceI getSequenceAt(int i)
846 return sequences.get(i);
853 public void setColourText(boolean state)
861 * @return DOCUMENT ME!
863 public boolean getColourText()
874 public void setDisplayText(boolean state)
882 * @return DOCUMENT ME!
884 public boolean getDisplayText()
895 public void setDisplayBoxes(boolean state)
897 displayBoxes = state;
903 * @return DOCUMENT ME!
905 public boolean getDisplayBoxes()
911 * computes the width of current set of sequences and returns it
913 * @return DOCUMENT ME!
916 public int getWidth()
918 synchronized (sequences)
920 // MC This needs to get reset when characters are inserted and deleted
921 boolean first = true;
922 for (SequenceI seq : sequences)
924 if (first || seq.getLength() > width)
926 width = seq.getLength();
940 public void setOutlineColour(Color c)
948 * @return DOCUMENT ME!
950 public Color getOutlineColour()
952 return outlineColour;
957 * returns the sequences in the group ordered by the ordering given by al.
958 * this used to return an array with null entries regardless, new behaviour is
959 * below. TODO: verify that this does not affect use in applet or application
963 * @return SequenceI[] intersection of sequences in group with al, ordered by
964 * al, or null if group does not intersect with al
966 public SequenceI[] getSequencesInOrder(AlignmentI al)
968 return getSequencesInOrder(al, true);
972 * return an array representing the intersection of the group with al,
973 * optionally returning an array the size of al.getHeight() where nulls mark
974 * the non-intersected sequences
978 * @return null or array
980 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
982 synchronized (sequences)
984 int sSize = sequences.size();
985 int alHeight = al.getHeight();
987 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
990 for (int i = 0; i < alHeight && index < sSize; i++)
992 if (sequences.contains(al.getSequenceAt(i)))
994 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1006 if (index < seqs.length)
1008 SequenceI[] dummy = seqs;
1009 seqs = new SequenceI[index];
1010 while (--index >= 0)
1012 seqs[index] = dummy[index];
1013 dummy[index] = null;
1021 * @return the idColour
1023 public Color getIdColour()
1030 * the idColour to set
1032 public void setIdColour(Color idColour)
1034 this.idColour = idColour;
1038 * @return the representative sequence for this group
1041 public SequenceI getSeqrep()
1047 * set the representative sequence for this group. Note - this affects the
1048 * interpretation of the Hidereps attribute.
1051 * the seqrep to set (null means no sequence representative)
1054 public void setSeqrep(SequenceI seqrep)
1056 this.seqrep = seqrep;
1061 * @return true if group has a sequence representative
1064 public boolean hasSeqrep()
1066 return seqrep != null;
1070 * set visibility of sequences covered by (if no sequence representative is
1071 * defined) or represented by this group.
1075 public void setHidereps(boolean visibility)
1077 hidereps = visibility;
1082 * @return true if sequences represented (or covered) by this group should be
1085 public boolean isHidereps()
1091 * set intended visibility of columns covered by this group
1095 public void setHideCols(boolean visibility)
1097 hidecols = visibility;
1102 * @return true if columns covered by group should be hidden
1104 public boolean isHideCols()
1110 * create a new sequence group from the intersection of this group with an
1111 * alignment Hashtable of hidden representatives
1117 * @return new group containing sequences common to this group and alignment
1119 public SequenceGroup intersect(AlignmentI alignment,
1120 Map<SequenceI, SequenceCollectionI> map)
1122 SequenceGroup sgroup = new SequenceGroup(this);
1123 SequenceI[] insect = getSequencesInOrder(alignment);
1124 sgroup.sequences = new ArrayList<>();
1125 for (int s = 0; insect != null && s < insect.length; s++)
1127 if (map == null || map.containsKey(insect[s]))
1129 sgroup.sequences.add(insect[s]);
1136 * @return the showUnconserved
1138 public boolean getShowNonconserved()
1140 return showNonconserved;
1144 * @param showNonconserved
1145 * the showUnconserved to set
1147 public void setShowNonconserved(boolean displayNonconserved)
1149 this.showNonconserved = displayNonconserved;
1153 * set this alignmentAnnotation object as the one used to render consensus
1158 public void setConsensus(AlignmentAnnotation aan)
1160 if (consensus == null)
1168 * @return automatically calculated consensus row note: the row is a stub if a
1169 * consensus calculation has not yet been performed on the group
1171 public AlignmentAnnotation getConsensus()
1173 // TODO get or calculate and get consensus annotation row for this group
1174 int aWidth = this.getWidth();
1182 if (consensus == null)
1184 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1185 100f, AlignmentAnnotation.BAR_GRAPH);
1186 consensus.hasText = true;
1187 consensus.autoCalculated = true;
1188 consensus.groupRef = this;
1189 consensus.label = "Consensus for " + getName();
1190 consensus.description = "Percent Identity";
1196 * Creates the Hidden Markov Model annotation for this group
1198 void createInformationAnnotation()
1200 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1201 6.25f, AlignmentAnnotation.BAR_GRAPH);
1202 hmmInformation.hasText = true;
1203 hmmInformation.autoCalculated = false;
1204 hmmInformation.groupRef = this;
1205 hmmInformation.label = getName();
1206 hmmInformation.description = MessageManager
1207 .getString("label.information_description");
1208 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1212 * set this alignmentAnnotation object as the one used to render consensus
1217 public void setConservationRow(AlignmentAnnotation aan)
1219 if (conservation == null)
1226 * get the conservation annotation row for this group
1228 * @return autoCalculated annotation row
1230 public AlignmentAnnotation getConservationRow()
1232 if (conservation == null)
1234 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1235 11f, AlignmentAnnotation.BAR_GRAPH);
1238 conservation.hasText = true;
1239 conservation.autoCalculated = true;
1240 conservation.groupRef = this;
1241 conservation.label = "Conservation for " + getName();
1242 conservation.description = "Conservation for group " + getName()
1243 + " less than " + consPercGaps + "% gaps";
1244 return conservation;
1249 * @return true if annotation rows have been instantiated for this group
1251 public boolean hasAnnotationRows()
1253 return consensus != null || conservation != null;
1256 public SequenceI getConsensusSeq()
1259 StringBuffer seqs = new StringBuffer();
1260 for (int i = 0; i < consensus.annotations.length; i++)
1262 if (consensus.annotations[i] != null)
1264 String desc = consensus.annotations[i].description;
1265 if (desc.length() > 1 && desc.charAt(0) == '[')
1267 seqs.append(desc.charAt(1));
1271 seqs.append(consensus.annotations[i].displayCharacter);
1276 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1278 sq.setDescription("Percentage Identity Consensus "
1279 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1283 public void setIgnoreGapsConsensus(boolean state)
1285 if (this.ignoreGapsInConsensus != state && consensus != null)
1287 ignoreGapsInConsensus = state;
1288 recalcConservation();
1290 ignoreGapsInConsensus = state;
1293 public boolean isIgnoreGapsConsensus()
1295 return ignoreGapsInConsensus;
1298 public void setIgnoreBelowBackground(boolean state)
1300 hmmIgnoreBelowBackground = state;
1303 public boolean isIgnoreBelowBackground()
1305 return hmmIgnoreBelowBackground;
1308 public void setInfoLetterHeight(boolean state)
1310 hmmUseInfoLetterHeight = state;
1313 public boolean isUseInfoLetterHeight()
1315 return hmmUseInfoLetterHeight;
1319 * @param showSequenceLogo
1320 * indicates if a sequence logo is shown for consensus annotation
1322 public void setshowSequenceLogo(boolean showSequenceLogo)
1324 // TODO: decouple calculation from settings update
1325 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1327 this.showSequenceLogo = showSequenceLogo;
1328 recalcConservation();
1330 this.showSequenceLogo = showSequenceLogo;
1335 * @param showConsHist
1336 * flag indicating if the consensus histogram for this group should
1339 public void setShowConsensusHistogram(boolean showConsHist)
1342 if (showConsensusHistogram != showConsHist && consensus != null)
1344 this.showConsensusHistogram = showConsHist;
1345 recalcConservation();
1347 this.showConsensusHistogram = showConsHist;
1351 * @return the showConsensusHistogram
1353 public boolean isShowConsensusHistogram()
1355 return showConsensusHistogram;
1359 * set flag indicating if logo should be normalised when rendered
1363 public void setNormaliseSequenceLogo(boolean norm)
1365 normaliseSequenceLogo = norm;
1368 public boolean isNormaliseSequenceLogo()
1370 return normaliseSequenceLogo;
1375 * returns a new array with all annotation involving this group
1377 public AlignmentAnnotation[] getAlignmentAnnotation()
1379 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1381 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1382 synchronized (sequences)
1384 for (SequenceI seq : sequences)
1386 AlignmentAnnotation[] aa = seq.getAnnotation();
1389 for (AlignmentAnnotation al : aa)
1391 if (al.groupRef == this)
1398 if (consensus != null)
1400 annot.add(consensus);
1402 if (conservation != null)
1404 annot.add(conservation);
1407 return annot.toArray(new AlignmentAnnotation[0]);
1411 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1413 return AlignmentAnnotation.findAnnotation(
1414 Arrays.asList(getAlignmentAnnotation()), calcId);
1418 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1419 String calcId, String label)
1421 return AlignmentAnnotation.findAnnotations(
1422 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1426 * Answer true if any annotation matches the calcId passed in (if not null).
1431 public boolean hasAnnotation(String calcId)
1433 return AlignmentAnnotation
1434 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1438 * Remove all sequences from the group (leaving other properties unchanged).
1442 synchronized (sequences)
1444 int before = sequences.size();
1446 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1452 * Sets the alignment or group context for this group, and whether it is
1453 * defined as a group
1456 * the context for the group
1458 * whether the group is defined on the alignment or is just a
1460 * @throws IllegalArgumentException
1461 * if setting the context would result in a circular reference chain
1463 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1466 this.isDefined = defined;
1470 * Sets the alignment or group context for this group
1473 * the context for the group
1474 * @throws IllegalArgumentException
1475 * if setting the context would result in a circular reference chain
1477 public void setContext(AnnotatedCollectionI ctx)
1479 AnnotatedCollectionI ref = ctx;
1482 if (ref == this || ref.getContext() == ctx)
1484 throw new IllegalArgumentException(
1485 "Circular reference in SequenceGroup.context");
1487 ref = ref.getContext();
1495 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1498 public AnnotatedCollectionI getContext()
1503 public boolean isDefined()
1508 public void setColourScheme(ColourSchemeI scheme)
1512 cs = new ResidueShader();
1514 cs.setColourScheme(scheme);
1517 public void setGroupColourScheme(ResidueShaderI scheme)
1522 public ColourSchemeI getColourScheme()
1524 return cs == null ? null : cs.getColourScheme();
1527 public ResidueShaderI getGroupColourScheme()
1533 public boolean isNucleotide()
1535 if (context != null)
1537 return context.isNucleotide();
1544 * @return true if seq is a member of the group
1547 public boolean contains(SequenceI seq1)
1549 return sequences.contains(seq1);
1555 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1557 public boolean contains(SequenceI seq, int apos)
1559 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1562 public boolean isShowInformationHistogram()
1564 return hmmShowHistogram;
1567 public void setShowInformationHistogram(boolean state)
1569 if (hmmShowHistogram != state && hmmInformation != null)
1571 this.hmmShowHistogram = state;
1572 // recalcConservation(); TODO don't know what to do here next
1574 this.hmmShowHistogram = state;
1577 public boolean isShowHMMSequenceLogo()
1579 return hmmShowSequenceLogo;
1582 public void setShowHMMSequenceLogo(boolean state)
1584 hmmShowSequenceLogo = state;
1587 public boolean isNormaliseHMMSequenceLogo()
1589 return hmmNormaliseSequenceLogo;
1592 public void setNormaliseHMMSequenceLogo(boolean state)
1594 hmmNormaliseSequenceLogo = state;
1597 public ProfilesI getConsensusData()
1599 return consensusProfiles;
1602 public ProfilesI getHmmProfiles()
1607 public void setHmmProfiles(ProfilesI hmmProfiles)
1609 this.hmmProfiles = hmmProfiles;
1613 public List<SequenceI> getHmmSequences()
1615 List<SequenceI> result = new ArrayList<>();
1616 for (int i = 0; i < sequences.size(); i++)
1618 SequenceI seq = sequences.get(i);
1619 if (seq.hasHMMProfile())