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,
266 boolean copyAnnotation)
268 int iSize = sequences.size();
269 SequenceI[] seqs = new SequenceI[iSize];
270 SequenceI[] inorder = getSequencesInOrder(align);
272 for (int i = 0, ipos = 0; i < inorder.length; i++)
274 SequenceI seq = inorder[i];
276 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
277 if (seqs[ipos] != null)
279 seqs[ipos].setDescription(seq.getDescription());
281 if (seq.getAnnotation() != null && copyAnnotation)
283 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
284 // Only copy annotation that is either a score or referenced by the
285 // alignment's annotation vector
286 for (int a = 0; a < seq.getAnnotation().length; a++)
288 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
291 boolean found = false;
292 for (int pos = 0; pos < alann.length; pos++)
294 if (alann[pos] == tocopy)
305 AlignmentAnnotation newannot = new AlignmentAnnotation(
306 seq.getAnnotation()[a]);
307 newannot.restrict(startRes, endRes);
308 newannot.setSequenceRef(seqs[ipos]);
309 newannot.adjustForAlignment();
310 seqs[ipos].addAlignmentAnnotation(newannot);
320 if (iSize != inorder.length)
322 SequenceI[] nseqs = new SequenceI[iSize];
323 System.arraycopy(seqs, 0, nseqs, 0, iSize);
331 * If sequence ends in gaps, the end residue can be correctly calculated here
337 public int findEndRes(SequenceI seq)
342 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
344 ch = seq.getCharAt(j);
345 if (!jalview.util.Comparison.isGap((ch)))
353 eres += seq.getStart() - 1;
360 public List<SequenceI> getSequences()
366 public List<SequenceI> getSequences(
367 Map<SequenceI, SequenceCollectionI> hiddenReps)
369 if (hiddenReps == null)
371 // TODO: need a synchronizedCollection here ?
376 List<SequenceI> allSequences = new ArrayList<>();
377 for (SequenceI seq : sequences)
379 allSequences.add(seq);
380 if (hiddenReps.containsKey(seq))
382 SequenceCollectionI hsg = hiddenReps.get(seq);
383 for (SequenceI seq2 : hsg.getSequences())
385 if (seq2 != seq && !allSequences.contains(seq2))
387 allSequences.add(seq2);
397 public SequenceI[] getSequencesAsArray(
398 Map<SequenceI, SequenceCollectionI> map)
400 List<SequenceI> tmp = getSequences(map);
405 return tmp.toArray(new SequenceI[tmp.size()]);
414 * @return DOCUMENT ME!
416 public boolean adjustForRemoveLeft(int col)
418 // return value is true if the group still exists
421 startRes = startRes - col;
426 endRes = endRes - col;
428 if (startRes > endRes)
435 // must delete this group!!
448 * @return DOCUMENT ME!
450 public boolean adjustForRemoveRight(int col)
469 * @return DOCUMENT ME!
471 public String getName()
476 public String getDescription()
487 public void setName(String name)
490 // TODO: URGENT: update dependent objects (annotation row)
493 public void setDescription(String desc)
501 * @return DOCUMENT ME!
503 public Conservation getConservation()
505 return conservationData;
514 public void setConservation(Conservation c)
516 conservationData = c;
520 * Add s to this sequence group. If aligment sequence is already contained in
521 * group, it will not be added again, but recalculation may happen if the flag
525 * alignment sequence to be added
527 * true means Group's conservation should be recalculated
529 public void addSequence(SequenceI s, boolean recalc)
531 synchronized (sequences)
533 if (s != null && !sequences.contains(s))
536 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
537 sequences.size() - 1, sequences.size());
542 recalcConservation();
548 * Max Gaps Threshold (percent) for performing a conservation calculation
550 private int consPercGaps = 25;
553 * @return Max Gaps Threshold for performing a conservation calculation
555 public int getConsPercGaps()
561 * set Max Gaps Threshold (percent) for performing a conservation calculation
563 * @param consPercGaps
565 public void setConsPercGaps(int consPercGaps)
567 this.consPercGaps = consPercGaps;
571 * calculate residue conservation and colourschemes for group - but only if
572 * necessary. returns true if the calculation resulted in a visible change to
575 public boolean recalcConservation()
577 return recalcAnnotations(false);
581 * Recalculates column consensus, conservation, and HMM annotation for the
582 * group (as applicable). Returns true if the calculation resulted in a
583 * visible change to group.
586 * when set, colourschemes for this group are not refreshed after
589 public boolean recalcAnnotations(boolean defer)
591 if (cs == null && consensus == null && conservation == null
592 && hmmInformation == null)
596 // TODO: try harder to detect changes in state in order to minimise
597 // recalculation effort
601 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
602 endRes + 1, showSequenceLogo);
603 if (hmmInformation != null)
605 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
607 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
608 (endRes + 1) - startRes, startRes, endRes + 1,
609 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
610 _updateInformationRow(info);
613 if (consensus != null)
615 _updateConsensusRow(cnsns, sequences.size());
620 cs.setConsensus(cnsns);
624 if ((conservation != null)
625 || (cs != null && cs.conservationApplied()))
627 Conservation c = new Conservation(groupName, sequences, startRes,
630 c.verdict(false, consPercGaps);
631 if (conservation != null)
633 _updateConservationRow(c);
637 if (cs.conservationApplied())
639 cs.setConservation(c);
642 // eager update - will cause a refresh of overview regardless
645 if (cs != null && !defer)
647 // TODO: JAL-2034 should cs.alignmentChanged modify return state
648 cs.alignmentChanged(context != null ? context : this, null);
655 } catch (java.lang.OutOfMemoryError err)
658 System.out.println("Out of memory loading groups: " + err);
663 private void _updateConservationRow(Conservation c)
665 if (conservation == null)
670 conservation.label = "Conservation for " + getName();
671 conservation.description = "Conservation for group " + getName()
672 + " less than " + consPercGaps + "% gaps";
673 // preserve width if already set
674 int aWidth = (conservation.annotations != null)
675 ? (endRes < conservation.annotations.length
676 ? conservation.annotations.length
679 conservation.annotations = null;
680 conservation.annotations = new Annotation[aWidth]; // should be alignment
682 c.completeAnnotations(conservation, null, startRes, endRes + 1);
685 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
687 if (consensus == null)
691 consensus.label = "Consensus for " + getName();
692 consensus.description = "Percent Identity";
693 consensusProfiles = cnsns;
694 // preserve width if already set
695 int aWidth = (consensus.annotations != null)
696 ? (endRes < consensus.annotations.length
697 ? consensus.annotations.length
700 consensus.annotations = null;
701 consensus.annotations = new Annotation[aWidth]; // should be alignment width
703 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
704 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
707 // ignoreGapsInConsensusCalculation);
711 * Recalculates the information content on the HMM annotation
715 private void _updateInformationRow(ProfilesI cnsns)
717 if (hmmInformation == null)
719 createInformationAnnotation();
721 hmmInformation.description = MessageManager
722 .getString("label.information_description");
723 setHmmProfiles(cnsns);
724 // preserve width if already set
725 int aWidth = (hmmInformation.annotations != null)
726 ? (endRes < hmmInformation.annotations.length
727 ? hmmInformation.annotations.length : endRes + 1)
729 hmmInformation.annotations = null;
730 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
732 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
733 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
739 * sequence to either add or remove from group
741 * flag passed to delete/addSequence to indicate if group properties
742 * should be recalculated
744 public void addOrRemove(SequenceI s, boolean recalc)
746 synchronized (sequences)
748 if (sequences.contains(s))
750 deleteSequence(s, recalc);
754 addSequence(s, recalc);
765 * true means recalculate conservation
767 public void deleteSequence(SequenceI s, boolean recalc)
769 synchronized (sequences)
772 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
773 sequences.size() + 1, sequences.size());
777 recalcConservation();
785 * @return the first column selected by this group. Runs from 0<=i<N_cols
788 public int getStartRes()
795 * @return the groups last selected column. Runs from 0<=i<N_cols
798 public int getEndRes()
804 * Set the first column selected by this group. Runs from 0<=i<N_cols
808 public void setStartRes(int i)
810 int before = startRes;
812 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
816 * Set the groups last selected column. Runs from 0<=i<N_cols
820 public void setEndRes(int i)
824 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
828 * @return number of sequences in group
832 return sequences.size();
837 * @return the ith sequence
839 public SequenceI getSequenceAt(int i)
841 return sequences.get(i);
848 public void setColourText(boolean state)
856 * @return DOCUMENT ME!
858 public boolean getColourText()
869 public void setDisplayText(boolean state)
877 * @return DOCUMENT ME!
879 public boolean getDisplayText()
890 public void setDisplayBoxes(boolean state)
892 displayBoxes = state;
898 * @return DOCUMENT ME!
900 public boolean getDisplayBoxes()
906 * computes the width of current set of sequences and returns it
908 * @return DOCUMENT ME!
911 public int getWidth()
913 synchronized (sequences)
915 // MC This needs to get reset when characters are inserted and deleted
916 boolean first = true;
917 for (SequenceI seq : sequences)
919 if (first || seq.getLength() > width)
921 width = seq.getLength();
935 public void setOutlineColour(Color c)
943 * @return DOCUMENT ME!
945 public Color getOutlineColour()
947 return outlineColour;
952 * returns the sequences in the group ordered by the ordering given by al.
953 * this used to return an array with null entries regardless, new behaviour is
954 * below. TODO: verify that this does not affect use in applet or application
958 * @return SequenceI[] intersection of sequences in group with al, ordered by
959 * al, or null if group does not intersect with al
961 public SequenceI[] getSequencesInOrder(AlignmentI al)
963 return getSequencesInOrder(al, true);
967 * return an array representing the intersection of the group with al,
968 * optionally returning an array the size of al.getHeight() where nulls mark
969 * the non-intersected sequences
973 * @return null or array
975 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
977 synchronized (sequences)
979 int sSize = sequences.size();
980 int alHeight = al.getHeight();
982 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
985 for (int i = 0; i < alHeight && index < sSize; i++)
987 if (sequences.contains(al.getSequenceAt(i)))
989 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1001 if (index < seqs.length)
1003 SequenceI[] dummy = seqs;
1004 seqs = new SequenceI[index];
1005 while (--index >= 0)
1007 seqs[index] = dummy[index];
1008 dummy[index] = null;
1016 * @return the idColour
1018 public Color getIdColour()
1025 * the idColour to set
1027 public void setIdColour(Color idColour)
1029 this.idColour = idColour;
1033 * @return the representative sequence for this group
1036 public SequenceI getSeqrep()
1042 * set the representative sequence for this group. Note - this affects the
1043 * interpretation of the Hidereps attribute.
1046 * the seqrep to set (null means no sequence representative)
1049 public void setSeqrep(SequenceI seqrep)
1051 this.seqrep = seqrep;
1056 * @return true if group has a sequence representative
1059 public boolean hasSeqrep()
1061 return seqrep != null;
1065 * set visibility of sequences covered by (if no sequence representative is
1066 * defined) or represented by this group.
1070 public void setHidereps(boolean visibility)
1072 hidereps = visibility;
1077 * @return true if sequences represented (or covered) by this group should be
1080 public boolean isHidereps()
1086 * set intended visibility of columns covered by this group
1090 public void setHideCols(boolean visibility)
1092 hidecols = visibility;
1097 * @return true if columns covered by group should be hidden
1099 public boolean isHideCols()
1105 * create a new sequence group from the intersection of this group with an
1106 * alignment Hashtable of hidden representatives
1112 * @return new group containing sequences common to this group and alignment
1114 public SequenceGroup intersect(AlignmentI alignment,
1115 Map<SequenceI, SequenceCollectionI> map)
1117 SequenceGroup sgroup = new SequenceGroup(this);
1118 SequenceI[] insect = getSequencesInOrder(alignment);
1119 sgroup.sequences = new ArrayList<>();
1120 for (int s = 0; insect != null && s < insect.length; s++)
1122 if (map == null || map.containsKey(insect[s]))
1124 sgroup.sequences.add(insect[s]);
1131 * @return the showUnconserved
1133 public boolean getShowNonconserved()
1135 return showNonconserved;
1139 * @param showNonconserved
1140 * the showUnconserved to set
1142 public void setShowNonconserved(boolean displayNonconserved)
1144 this.showNonconserved = displayNonconserved;
1148 * set this alignmentAnnotation object as the one used to render consensus
1153 public void setConsensus(AlignmentAnnotation aan)
1155 if (consensus == null)
1163 * @return automatically calculated consensus row note: the row is a stub if a
1164 * consensus calculation has not yet been performed on the group
1166 public AlignmentAnnotation getConsensus()
1168 // TODO get or calculate and get consensus annotation row for this group
1169 int aWidth = this.getWidth();
1177 if (consensus == null)
1179 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1180 100f, AlignmentAnnotation.BAR_GRAPH);
1181 consensus.hasText = true;
1182 consensus.autoCalculated = true;
1183 consensus.groupRef = this;
1184 consensus.label = "Consensus for " + getName();
1185 consensus.description = "Percent Identity";
1191 * Creates the Hidden Markov Model annotation for this group
1193 void createInformationAnnotation()
1195 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1196 6.25f, AlignmentAnnotation.BAR_GRAPH);
1197 hmmInformation.hasText = true;
1198 hmmInformation.autoCalculated = false;
1199 hmmInformation.groupRef = this;
1200 hmmInformation.label = getName();
1201 hmmInformation.description = MessageManager
1202 .getString("label.information_description");
1203 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1207 * set this alignmentAnnotation object as the one used to render consensus
1212 public void setConservationRow(AlignmentAnnotation aan)
1214 if (conservation == null)
1221 * get the conservation annotation row for this group
1223 * @return autoCalculated annotation row
1225 public AlignmentAnnotation getConservationRow()
1227 if (conservation == null)
1229 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1230 11f, AlignmentAnnotation.BAR_GRAPH);
1233 conservation.hasText = true;
1234 conservation.autoCalculated = true;
1235 conservation.groupRef = this;
1236 conservation.label = "Conservation for " + getName();
1237 conservation.description = "Conservation for group " + getName()
1238 + " less than " + consPercGaps + "% gaps";
1239 return conservation;
1244 * @return true if annotation rows have been instantiated for this group
1246 public boolean hasAnnotationRows()
1248 return consensus != null || conservation != null;
1251 public SequenceI getConsensusSeq()
1254 StringBuffer seqs = new StringBuffer();
1255 for (int i = 0; i < consensus.annotations.length; i++)
1257 if (consensus.annotations[i] != null)
1259 String desc = consensus.annotations[i].description;
1260 if (desc.length() > 1 && desc.charAt(0) == '[')
1262 seqs.append(desc.charAt(1));
1266 seqs.append(consensus.annotations[i].displayCharacter);
1271 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1273 sq.setDescription("Percentage Identity Consensus "
1274 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1278 public void setIgnoreGapsConsensus(boolean state)
1280 if (this.ignoreGapsInConsensus != state && consensus != null)
1282 ignoreGapsInConsensus = state;
1283 recalcConservation();
1285 ignoreGapsInConsensus = state;
1288 public boolean isIgnoreGapsConsensus()
1290 return ignoreGapsInConsensus;
1293 public void setIgnoreBelowBackground(boolean state)
1295 hmmIgnoreBelowBackground = state;
1298 public boolean isIgnoreBelowBackground()
1300 return hmmIgnoreBelowBackground;
1303 public void setInfoLetterHeight(boolean state)
1305 hmmUseInfoLetterHeight = state;
1308 public boolean isUseInfoLetterHeight()
1310 return hmmUseInfoLetterHeight;
1314 * @param showSequenceLogo
1315 * indicates if a sequence logo is shown for consensus annotation
1317 public void setshowSequenceLogo(boolean showSequenceLogo)
1319 // TODO: decouple calculation from settings update
1320 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1322 this.showSequenceLogo = showSequenceLogo;
1323 recalcConservation();
1325 this.showSequenceLogo = showSequenceLogo;
1330 * @param showConsHist
1331 * flag indicating if the consensus histogram for this group should
1334 public void setShowConsensusHistogram(boolean showConsHist)
1337 if (showConsensusHistogram != showConsHist && consensus != null)
1339 this.showConsensusHistogram = showConsHist;
1340 recalcConservation();
1342 this.showConsensusHistogram = showConsHist;
1346 * @return the showConsensusHistogram
1348 public boolean isShowConsensusHistogram()
1350 return showConsensusHistogram;
1354 * set flag indicating if logo should be normalised when rendered
1358 public void setNormaliseSequenceLogo(boolean norm)
1360 normaliseSequenceLogo = norm;
1363 public boolean isNormaliseSequenceLogo()
1365 return normaliseSequenceLogo;
1370 * returns a new array with all annotation involving this group
1372 public AlignmentAnnotation[] getAlignmentAnnotation()
1374 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1376 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1377 synchronized (sequences)
1379 for (SequenceI seq : sequences)
1381 AlignmentAnnotation[] aa = seq.getAnnotation();
1384 for (AlignmentAnnotation al : aa)
1386 if (al.groupRef == this)
1393 if (consensus != null)
1395 annot.add(consensus);
1397 if (conservation != null)
1399 annot.add(conservation);
1402 return annot.toArray(new AlignmentAnnotation[0]);
1406 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1408 return AlignmentAnnotation.findAnnotation(
1409 Arrays.asList(getAlignmentAnnotation()), calcId);
1413 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1414 String calcId, String label)
1416 return AlignmentAnnotation.findAnnotations(
1417 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1421 * Answer true if any annotation matches the calcId passed in (if not null).
1426 public boolean hasAnnotation(String calcId)
1428 return AlignmentAnnotation
1429 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1433 * Remove all sequences from the group (leaving other properties unchanged).
1437 synchronized (sequences)
1439 int before = sequences.size();
1441 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1447 * Sets the alignment or group context for this group, and whether it is
1448 * defined as a group
1451 * the context for the group
1453 * whether the group is defined on the alignment or is just a
1455 * @throws IllegalArgumentException
1456 * if setting the context would result in a circular reference chain
1458 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1461 this.isDefined = defined;
1465 * Sets the alignment or group context for this group
1468 * the context for the group
1469 * @throws IllegalArgumentException
1470 * if setting the context would result in a circular reference chain
1472 public void setContext(AnnotatedCollectionI ctx)
1474 AnnotatedCollectionI ref = ctx;
1477 if (ref == this || ref.getContext() == ctx)
1479 throw new IllegalArgumentException(
1480 "Circular reference in SequenceGroup.context");
1482 ref = ref.getContext();
1490 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1493 public AnnotatedCollectionI getContext()
1498 public boolean isDefined()
1503 public void setColourScheme(ColourSchemeI scheme)
1507 cs = new ResidueShader();
1509 cs.setColourScheme(scheme);
1512 public void setGroupColourScheme(ResidueShaderI scheme)
1517 public ColourSchemeI getColourScheme()
1519 return cs == null ? null : cs.getColourScheme();
1522 public ResidueShaderI getGroupColourScheme()
1528 public boolean isNucleotide()
1530 if (context != null)
1532 return context.isNucleotide();
1539 * @return true if seq is a member of the group
1542 public boolean contains(SequenceI seq1)
1544 return sequences.contains(seq1);
1550 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1552 public boolean contains(SequenceI seq, int apos)
1554 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1557 public boolean isShowInformationHistogram()
1559 return hmmShowHistogram;
1562 public void setShowInformationHistogram(boolean state)
1564 if (hmmShowHistogram != state && hmmInformation != null)
1566 this.hmmShowHistogram = state;
1567 // recalcConservation(); TODO don't know what to do here next
1569 this.hmmShowHistogram = state;
1572 public boolean isShowHMMSequenceLogo()
1574 return hmmShowSequenceLogo;
1577 public void setShowHMMSequenceLogo(boolean state)
1579 hmmShowSequenceLogo = state;
1582 public boolean isNormaliseHMMSequenceLogo()
1584 return hmmNormaliseSequenceLogo;
1587 public void setNormaliseHMMSequenceLogo(boolean state)
1589 hmmNormaliseSequenceLogo = state;
1592 public ProfilesI getConsensusData()
1594 return consensusProfiles;
1597 public ProfilesI getHmmProfiles()
1602 public void setHmmProfiles(ProfilesI hmmProfiles)
1604 this.hmmProfiles = hmmProfiles;
1608 public List<SequenceI> getHmmSequences()
1610 List<SequenceI> result = new ArrayList<>();
1611 for (int i = 0; i < sequences.size(); i++)
1613 SequenceI seq = sequences.get(i);
1614 if (seq.hasHMMProfile())