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;
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;
99 * start column (base 0)
101 private int startRes = 0;
104 * end column (base 0)
106 private int endRes = 0;
108 public Color outlineColour = Color.black;
110 public Color idColour;
112 public int thresholdTextColour;
114 public Color textColour = Color.black;
116 public Color textColour2 = Color.white;
119 * properties for consensus annotation
121 private boolean ignoreGapsInConsensus = true;
123 private boolean showSequenceLogo;
125 private boolean normaliseSequenceLogo;
127 private boolean showConsensusHistogram;
130 * properties for HMM information annotation
132 private boolean hmmIgnoreBelowBackground = true;
134 private boolean hmmUseInfoLetterHeight;
136 private boolean hmmShowSequenceLogo;
138 private boolean hmmNormaliseSequenceLogo;
140 private boolean hmmShowHistogram;
143 * visibility of rows or represented rows covered by group
145 private boolean hidereps;
148 * visibility of columns intersecting this group
150 private boolean hidecols;
152 private AlignmentAnnotation consensus;
154 private AlignmentAnnotation conservation;
156 private AlignmentAnnotation hmmInformation;
159 * Constructor, assigning a generated default name of "JGroup:" with object
162 public SequenceGroup()
164 groupName = "JGroup:" + this.hashCode();
165 cs = new ResidueShader();
166 sequences = new ArrayList<>();
170 * Creates a new SequenceGroup object.
175 * @param displayBoxes
179 * first column of group
181 * last column of group
183 public SequenceGroup(List<SequenceI> sequences, String groupName,
184 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
185 boolean colourText, int start, int end)
188 this.sequences = sequences;
189 this.groupName = groupName;
190 this.displayBoxes = displayBoxes;
191 this.displayText = displayText;
192 this.colourText = colourText;
193 this.cs = new ResidueShader(scheme);
196 recalcConservation();
204 public SequenceGroup(SequenceGroup seqsel)
213 * @param keepsequences
214 * if false do not add sequences from seqsel to new instance
216 public SequenceGroup(SequenceGroup seqsel, boolean keepsequences)
222 sequences = new ArrayList<>();
225 sequences.addAll(seqsel.sequences);
227 if (seqsel.groupName != null)
229 groupName = new String(seqsel.groupName);
231 displayBoxes = seqsel.displayBoxes;
232 displayText = seqsel.displayText;
233 colourText = seqsel.colourText;
235 startRes = seqsel.startRes;
236 endRes = seqsel.endRes;
237 cs = new ResidueShader((ResidueShader) seqsel.cs);
238 if (seqsel.description != null)
240 description = new String(seqsel.description);
242 hidecols = seqsel.hidecols;
243 hidereps = seqsel.hidereps;
244 showNonconserved = seqsel.showNonconserved;
245 showSequenceLogo = seqsel.showSequenceLogo;
246 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
247 showConsensusHistogram = seqsel.showConsensusHistogram;
248 hmmShowSequenceLogo = seqsel.hmmShowSequenceLogo;
249 hmmNormaliseSequenceLogo = seqsel.hmmNormaliseSequenceLogo;
250 hmmShowHistogram = seqsel.hmmShowHistogram;
251 idColour = seqsel.idColour;
252 outlineColour = seqsel.outlineColour;
253 seqrep = seqsel.seqrep;
254 textColour = seqsel.textColour;
255 textColour2 = seqsel.textColour2;
256 thresholdTextColour = seqsel.thresholdTextColour;
257 width = seqsel.width;
258 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
259 hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
260 hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
261 if (keepsequences && seqsel.conservationData != null)
263 // todo avoid doing this if we don't actually want derived calculations
265 recalcConservation(); // safer than
266 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
271 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
274 public void addPropertyChangeListener(PropertyChangeListener listener)
276 changeSupport.addPropertyChangeListener(listener);
279 public void removePropertyChangeListener(PropertyChangeListener listener)
281 changeSupport.removePropertyChangeListener(listener);
285 * Constructor that copies the given list of sequences
289 public SequenceGroup(List<SequenceI> seqs)
292 this.sequences.addAll(seqs);
295 public boolean isShowSequenceLogo()
297 return showSequenceLogo;
300 public SequenceI[] getSelectionAsNewSequences(AlignmentI align,
301 boolean copyAnnotation)
303 int iSize = sequences.size();
304 SequenceI[] seqs = new SequenceI[iSize];
305 SequenceI[] inorder = getSequencesInOrder(align);
307 for (int i = 0, ipos = 0; i < inorder.length; i++)
309 SequenceI seq = inorder[i];
311 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
312 if (seqs[ipos] != null)
314 seqs[ipos].setDescription(seq.getDescription());
316 if (seq.getAnnotation() != null && copyAnnotation)
318 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
319 // Only copy annotation that is either a score or referenced by the
320 // alignment's annotation vector
321 for (int a = 0; a < seq.getAnnotation().length; a++)
323 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
326 boolean found = false;
327 for (int pos = 0; pos < alann.length; pos++)
329 if (alann[pos] == tocopy)
340 AlignmentAnnotation newannot = new AlignmentAnnotation(
341 seq.getAnnotation()[a]);
342 newannot.restrict(startRes, endRes);
343 newannot.setSequenceRef(seqs[ipos]);
344 newannot.adjustForAlignment();
345 seqs[ipos].addAlignmentAnnotation(newannot);
355 if (iSize != inorder.length)
357 SequenceI[] nseqs = new SequenceI[iSize];
358 System.arraycopy(seqs, 0, nseqs, 0, iSize);
366 * If sequence ends in gaps, the end residue can be correctly calculated here
372 public int findEndRes(SequenceI seq)
377 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
379 ch = seq.getCharAt(j);
380 if (!jalview.util.Comparison.isGap((ch)))
388 eres += seq.getStart() - 1;
395 public List<SequenceI> getSequences()
401 public List<SequenceI> getSequences(
402 Map<SequenceI, SequenceCollectionI> hiddenReps)
404 if (hiddenReps == null)
406 // TODO: need a synchronizedCollection here ?
411 List<SequenceI> allSequences = new ArrayList<>();
412 for (SequenceI seq : sequences)
414 allSequences.add(seq);
415 if (hiddenReps.containsKey(seq))
417 SequenceCollectionI hsg = hiddenReps.get(seq);
418 for (SequenceI seq2 : hsg.getSequences())
420 if (seq2 != seq && !allSequences.contains(seq2))
422 allSequences.add(seq2);
432 public SequenceI[] getSequencesAsArray(
433 Map<SequenceI, SequenceCollectionI> map)
435 List<SequenceI> tmp = getSequences(map);
440 return tmp.toArray(new SequenceI[tmp.size()]);
449 * @return DOCUMENT ME!
451 public boolean adjustForRemoveLeft(int col)
453 // return value is true if the group still exists
456 startRes = startRes - col;
461 endRes = endRes - col;
463 if (startRes > endRes)
470 // must delete this group!!
483 * @return DOCUMENT ME!
485 public boolean adjustForRemoveRight(int col)
504 * @return DOCUMENT ME!
506 public String getName()
511 public String getDescription()
522 public void setName(String name)
525 // TODO: URGENT: update dependent objects (annotation row)
528 public void setDescription(String desc)
536 * @return DOCUMENT ME!
538 public Conservation getConservation()
540 return conservationData;
549 public void setConservation(Conservation c)
551 conservationData = c;
555 * Add s to this sequence group. If aligment sequence is already contained in
556 * group, it will not be added again, but recalculation may happen if the flag
560 * alignment sequence to be added
562 * true means Group's conservation should be recalculated
564 public void addSequence(SequenceI s, boolean recalc)
566 synchronized (sequences)
568 if (s != null && !sequences.contains(s))
571 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
572 sequences.size() - 1, sequences.size());
577 recalcConservation();
583 * Max Gaps Threshold (percent) for performing a conservation calculation
585 private int consPercGaps = 25;
588 * @return Max Gaps Threshold for performing a conservation calculation
590 public int getConsPercGaps()
596 * set Max Gaps Threshold (percent) for performing a conservation calculation
598 * @param consPercGaps
600 public void setConsPercGaps(int consPercGaps)
602 this.consPercGaps = consPercGaps;
606 * calculate residue conservation and colourschemes for group - but only if
607 * necessary. returns true if the calculation resulted in a visible change to
610 public boolean recalcConservation()
612 return recalcAnnotations(false);
616 * Recalculates column consensus, conservation, and HMM annotation for the
617 * group (as applicable). Returns true if the calculation resulted in a
618 * visible change to group.
621 * when set, colourschemes for this group are not refreshed after
624 public boolean recalcAnnotations(boolean defer)
626 if (cs == null && consensus == null && conservation == null
627 && hmmInformation == null)
631 // TODO: try harder to detect changes in state in order to minimise
632 // recalculation effort
636 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
637 endRes + 1, showSequenceLogo);
638 if (hmmInformation != null)
640 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
642 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
643 (endRes + 1) - startRes, startRes, endRes + 1,
644 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
645 _updateInformationRow(info);
648 if (consensus != null)
650 _updateConsensusRow(cnsns, sequences.size());
655 cs.setConsensus(cnsns);
659 if ((conservation != null)
660 || (cs != null && cs.conservationApplied()))
662 Conservation c = new Conservation(groupName, sequences, startRes,
665 c.verdict(false, consPercGaps);
666 if (conservation != null)
668 _updateConservationRow(c);
672 if (cs.conservationApplied())
674 cs.setConservation(c);
677 // eager update - will cause a refresh of overview regardless
680 if (cs != null && !defer)
682 // TODO: JAL-2034 should cs.alignmentChanged modify return state
683 cs.alignmentChanged(context != null ? context : this, null);
690 } catch (java.lang.OutOfMemoryError err)
693 System.out.println("Out of memory loading groups: " + err);
698 private void _updateConservationRow(Conservation c)
700 if (conservation == null)
705 conservation.label = "Conservation for " + getName();
706 conservation.description = "Conservation for group " + getName()
707 + " less than " + consPercGaps + "% gaps";
708 // preserve width if already set
709 int aWidth = (conservation.annotations != null)
710 ? (endRes < conservation.annotations.length
711 ? conservation.annotations.length
714 conservation.annotations = null;
715 conservation.annotations = new Annotation[aWidth]; // should be alignment
717 c.completeAnnotations(conservation, null, startRes, endRes + 1);
720 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
722 if (consensus == null)
726 consensus.label = "Consensus for " + getName();
727 consensus.description = "Percent Identity";
728 consensusProfiles = cnsns;
729 // preserve width if already set
730 int aWidth = (consensus.annotations != null)
731 ? (endRes < consensus.annotations.length
732 ? consensus.annotations.length
735 consensus.annotations = null;
736 consensus.annotations = new Annotation[aWidth]; // should be alignment width
738 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
739 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
742 // ignoreGapsInConsensusCalculation);
746 * Recalculates the information content on the HMM annotation
750 private void _updateInformationRow(ProfilesI cnsns)
752 if (hmmInformation == null)
754 createInformationAnnotation();
756 hmmInformation.description = MessageManager
757 .getString("label.information_description");
758 setHmmProfiles(cnsns);
759 // preserve width if already set
760 int aWidth = (hmmInformation.annotations != null)
761 ? (endRes < hmmInformation.annotations.length
762 ? hmmInformation.annotations.length : endRes + 1)
764 hmmInformation.annotations = null;
765 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
767 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
768 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
774 * sequence to either add or remove from group
776 * flag passed to delete/addSequence to indicate if group properties
777 * should be recalculated
779 public void addOrRemove(SequenceI s, boolean recalc)
781 synchronized (sequences)
783 if (sequences.contains(s))
785 deleteSequence(s, recalc);
789 addSequence(s, recalc);
800 * true means recalculate conservation
802 public void deleteSequence(SequenceI s, boolean recalc)
804 synchronized (sequences)
807 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
808 sequences.size() + 1, sequences.size());
812 recalcConservation();
820 * @return the first column selected by this group. Runs from 0<=i<N_cols
823 public int getStartRes()
830 * @return the groups last selected column. Runs from 0<=i<N_cols
833 public int getEndRes()
839 * Set the first column selected by this group. Runs from 0<=i<N_cols
843 public void setStartRes(int newStart)
845 int before = startRes;
846 startRes= Math.max(0,newStart); // sanity check for negative start column positions
847 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
854 * Set the groups last selected column. Runs from 0<=i<N_cols
858 public void setEndRes(int i)
862 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
866 * @return number of sequences in group
870 return sequences.size();
875 * @return the ith sequence
877 public SequenceI getSequenceAt(int i)
879 return sequences.get(i);
886 public void setColourText(boolean state)
894 * @return DOCUMENT ME!
896 public boolean getColourText()
907 public void setDisplayText(boolean state)
915 * @return DOCUMENT ME!
917 public boolean getDisplayText()
928 public void setDisplayBoxes(boolean state)
930 displayBoxes = state;
936 * @return DOCUMENT ME!
938 public boolean getDisplayBoxes()
944 * computes the width of current set of sequences and returns it
946 * @return DOCUMENT ME!
949 public int getWidth()
951 synchronized (sequences)
953 // MC This needs to get reset when characters are inserted and deleted
954 boolean first = true;
955 for (SequenceI seq : sequences)
957 if (first || seq.getLength() > width)
959 width = seq.getLength();
973 public void setOutlineColour(Color c)
981 * @return DOCUMENT ME!
983 public Color getOutlineColour()
985 return outlineColour;
990 * returns the sequences in the group ordered by the ordering given by al.
991 * this used to return an array with null entries regardless, new behaviour is
992 * below. TODO: verify that this does not affect use in applet or application
996 * @return SequenceI[] intersection of sequences in group with al, ordered by
997 * al, or null if group does not intersect with al
999 public SequenceI[] getSequencesInOrder(AlignmentI al)
1001 return getSequencesInOrder(al, true);
1005 * return an array representing the intersection of the group with al,
1006 * optionally returning an array the size of al.getHeight() where nulls mark
1007 * the non-intersected sequences
1011 * @return null or array
1013 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
1015 synchronized (sequences)
1017 int sSize = sequences.size();
1018 int alHeight = al.getHeight();
1020 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
1023 for (int i = 0; i < alHeight && index < sSize; i++)
1025 if (sequences.contains(al.getSequenceAt(i)))
1027 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1039 if (index < seqs.length)
1041 SequenceI[] dummy = seqs;
1042 seqs = new SequenceI[index];
1043 while (--index >= 0)
1045 seqs[index] = dummy[index];
1046 dummy[index] = null;
1054 * @return the idColour
1056 public Color getIdColour()
1063 * the idColour to set
1065 public void setIdColour(Color idColour)
1067 this.idColour = idColour;
1071 * @return the representative sequence for this group
1074 public SequenceI getSeqrep()
1080 * set the representative sequence for this group. Note - this affects the
1081 * interpretation of the Hidereps attribute.
1084 * the seqrep to set (null means no sequence representative)
1087 public void setSeqrep(SequenceI seqrep)
1089 this.seqrep = seqrep;
1094 * @return true if group has a sequence representative
1097 public boolean hasSeqrep()
1099 return seqrep != null;
1103 * set visibility of sequences covered by (if no sequence representative is
1104 * defined) or represented by this group.
1108 public void setHidereps(boolean visibility)
1110 hidereps = visibility;
1115 * @return true if sequences represented (or covered) by this group should be
1118 public boolean isHidereps()
1124 * set intended visibility of columns covered by this group
1128 public void setHideCols(boolean visibility)
1130 hidecols = visibility;
1135 * @return true if columns covered by group should be hidden
1137 public boolean isHideCols()
1143 * create a new sequence group from the intersection of this group with an
1144 * alignment Hashtable of hidden representatives
1150 * @return new group containing sequences common to this group and alignment
1152 public SequenceGroup intersect(AlignmentI alignment,
1153 Map<SequenceI, SequenceCollectionI> map)
1155 SequenceGroup sgroup = new SequenceGroup(this);
1156 SequenceI[] insect = getSequencesInOrder(alignment);
1157 sgroup.sequences = new ArrayList<>();
1158 for (int s = 0; insect != null && s < insect.length; s++)
1160 if (map == null || map.containsKey(insect[s]))
1162 sgroup.sequences.add(insect[s]);
1169 * @return the showUnconserved
1171 public boolean getShowNonconserved()
1173 return showNonconserved;
1177 * @param showNonconserved
1178 * the showUnconserved to set
1180 public void setShowNonconserved(boolean displayNonconserved)
1182 this.showNonconserved = displayNonconserved;
1186 * set this alignmentAnnotation object as the one used to render consensus
1191 public void setConsensus(AlignmentAnnotation aan)
1193 if (consensus == null)
1201 * @return automatically calculated consensus row note: the row is a stub if a
1202 * consensus calculation has not yet been performed on the group
1204 public AlignmentAnnotation getConsensus()
1206 // TODO get or calculate and get consensus annotation row for this group
1207 int aWidth = this.getWidth();
1215 if (consensus == null)
1217 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1218 100f, AlignmentAnnotation.BAR_GRAPH);
1219 consensus.hasText = true;
1220 consensus.autoCalculated = true;
1221 consensus.groupRef = this;
1222 consensus.label = "Consensus for " + getName();
1223 consensus.description = "Percent Identity";
1229 * Creates the Hidden Markov Model annotation for this group
1231 void createInformationAnnotation()
1233 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1234 6.25f, AlignmentAnnotation.BAR_GRAPH);
1235 hmmInformation.hasText = true;
1236 hmmInformation.autoCalculated = false;
1237 hmmInformation.groupRef = this;
1238 hmmInformation.label = getName();
1239 hmmInformation.description = MessageManager
1240 .getString("label.information_description");
1241 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1245 * set this alignmentAnnotation object as the one used to render consensus
1250 public void setConservationRow(AlignmentAnnotation aan)
1252 if (conservation == null)
1259 * get the conservation annotation row for this group
1261 * @return autoCalculated annotation row
1263 public AlignmentAnnotation getConservationRow()
1265 if (conservation == null)
1267 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1268 11f, AlignmentAnnotation.BAR_GRAPH);
1271 conservation.hasText = true;
1272 conservation.autoCalculated = true;
1273 conservation.groupRef = this;
1274 conservation.label = "Conservation for " + getName();
1275 conservation.description = "Conservation for group " + getName()
1276 + " less than " + consPercGaps + "% gaps";
1277 return conservation;
1282 * @return true if annotation rows have been instantiated for this group
1284 public boolean hasAnnotationRows()
1286 return consensus != null || conservation != null;
1289 public SequenceI getConsensusSeq()
1292 StringBuffer seqs = new StringBuffer();
1293 for (int i = 0; i < consensus.annotations.length; i++)
1295 if (consensus.annotations[i] != null)
1297 String desc = consensus.annotations[i].description;
1298 if (desc.length() > 1 && desc.charAt(0) == '[')
1300 seqs.append(desc.charAt(1));
1304 seqs.append(consensus.annotations[i].displayCharacter);
1309 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1311 sq.setDescription("Percentage Identity Consensus "
1312 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1316 public void setIgnoreGapsConsensus(boolean state)
1318 if (this.ignoreGapsInConsensus != state && consensus != null)
1320 ignoreGapsInConsensus = state;
1321 recalcConservation();
1323 ignoreGapsInConsensus = state;
1326 public boolean isIgnoreGapsConsensus()
1328 return ignoreGapsInConsensus;
1331 public void setIgnoreBelowBackground(boolean state)
1333 hmmIgnoreBelowBackground = state;
1336 public boolean isIgnoreBelowBackground()
1338 return hmmIgnoreBelowBackground;
1341 public void setInfoLetterHeight(boolean state)
1343 hmmUseInfoLetterHeight = state;
1346 public boolean isUseInfoLetterHeight()
1348 return hmmUseInfoLetterHeight;
1352 * @param showSequenceLogo
1353 * indicates if a sequence logo is shown for consensus annotation
1355 public void setshowSequenceLogo(boolean showSequenceLogo)
1357 // TODO: decouple calculation from settings update
1358 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1360 this.showSequenceLogo = showSequenceLogo;
1361 recalcConservation();
1363 this.showSequenceLogo = showSequenceLogo;
1368 * @param showConsHist
1369 * flag indicating if the consensus histogram for this group should
1372 public void setShowConsensusHistogram(boolean showConsHist)
1375 if (showConsensusHistogram != showConsHist && consensus != null)
1377 this.showConsensusHistogram = showConsHist;
1378 recalcConservation();
1380 this.showConsensusHistogram = showConsHist;
1384 * @return the showConsensusHistogram
1386 public boolean isShowConsensusHistogram()
1388 return showConsensusHistogram;
1392 * set flag indicating if logo should be normalised when rendered
1396 public void setNormaliseSequenceLogo(boolean norm)
1398 normaliseSequenceLogo = norm;
1401 public boolean isNormaliseSequenceLogo()
1403 return normaliseSequenceLogo;
1408 * returns a new array with all annotation involving this group
1410 public AlignmentAnnotation[] getAlignmentAnnotation()
1412 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1414 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1415 synchronized (sequences)
1417 for (SequenceI seq : sequences)
1419 AlignmentAnnotation[] aa = seq.getAnnotation();
1422 for (AlignmentAnnotation al : aa)
1424 if (al.groupRef == this)
1431 if (consensus != null)
1433 annot.add(consensus);
1435 if (conservation != null)
1437 annot.add(conservation);
1440 return annot.toArray(new AlignmentAnnotation[0]);
1444 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1446 return AlignmentAnnotation.findAnnotation(
1447 Arrays.asList(getAlignmentAnnotation()), calcId);
1451 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1452 String calcId, String label)
1454 return AlignmentAnnotation.findAnnotations(
1455 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1459 * Answer true if any annotation matches the calcId passed in (if not null).
1464 public boolean hasAnnotation(String calcId)
1466 return AlignmentAnnotation
1467 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1471 * Remove all sequences from the group (leaving other properties unchanged).
1475 synchronized (sequences)
1477 int before = sequences.size();
1479 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1485 * Sets the alignment or group context for this group, and whether it is
1486 * defined as a group
1489 * the context for the group
1491 * whether the group is defined on the alignment or is just a
1493 * @throws IllegalArgumentException
1494 * if setting the context would result in a circular reference chain
1496 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1499 this.isDefined = defined;
1503 * Sets the alignment or group context for this group
1506 * the context for the group
1507 * @throws IllegalArgumentException
1508 * if setting the context would result in a circular reference chain
1510 public void setContext(AnnotatedCollectionI ctx)
1512 AnnotatedCollectionI ref = ctx;
1515 if (ref == this || ref.getContext() == ctx)
1517 throw new IllegalArgumentException(
1518 "Circular reference in SequenceGroup.context");
1520 ref = ref.getContext();
1528 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1531 public AnnotatedCollectionI getContext()
1536 public boolean isDefined()
1541 public void setColourScheme(ColourSchemeI scheme)
1545 cs = new ResidueShader();
1547 cs.setColourScheme(scheme);
1550 public void setGroupColourScheme(ResidueShaderI scheme)
1555 public ColourSchemeI getColourScheme()
1557 return cs == null ? null : cs.getColourScheme();
1560 public ResidueShaderI getGroupColourScheme()
1566 public boolean isNucleotide()
1568 if (context != null)
1570 return context.isNucleotide();
1577 * @return true if seq is a member of the group
1580 public boolean contains(SequenceI seq1)
1582 return sequences.contains(seq1);
1588 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1590 public boolean contains(SequenceI seq, int apos)
1592 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1595 public boolean isShowInformationHistogram()
1597 return hmmShowHistogram;
1600 public void setShowInformationHistogram(boolean state)
1602 if (hmmShowHistogram != state && hmmInformation != null)
1604 this.hmmShowHistogram = state;
1605 // recalcConservation(); TODO don't know what to do here next
1607 this.hmmShowHistogram = state;
1610 public boolean isShowHMMSequenceLogo()
1612 return hmmShowSequenceLogo;
1615 public void setShowHMMSequenceLogo(boolean state)
1617 hmmShowSequenceLogo = state;
1620 public boolean isNormaliseHMMSequenceLogo()
1622 return hmmNormaliseSequenceLogo;
1625 public void setNormaliseHMMSequenceLogo(boolean state)
1627 hmmNormaliseSequenceLogo = state;
1630 public ProfilesI getConsensusData()
1632 return consensusProfiles;
1635 public ProfilesI getHmmProfiles()
1640 public void setHmmProfiles(ProfilesI hmmProfiles)
1642 this.hmmProfiles = hmmProfiles;
1646 public List<SequenceI> getHmmSequences()
1648 List<SequenceI> result = new ArrayList<>();
1649 for (int i = 0; i < sequences.size(); i++)
1651 SequenceI seq = sequences.get(i);
1652 if (seq.hasHMMProfile())