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;
30 import java.awt.Color;
31 import java.beans.PropertyChangeListener;
32 import java.beans.PropertyChangeSupport;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
39 * Collects a set contiguous ranges on a set of sequences
44 public class SequenceGroup implements AnnotatedCollectionI
46 // TODO ideally this event notification functionality should be separated into
48 // subclass of ViewportProperties similarly to ViewportRanges. Done here as
49 // quick fix for JAL-2665
50 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
52 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
55 public void addPropertyChangeListener(PropertyChangeListener listener)
57 changeSupport.addPropertyChangeListener(listener);
60 public void removePropertyChangeListener(PropertyChangeListener listener)
62 changeSupport.removePropertyChangeListener(listener);
64 // end of event notification functionality initialisation
70 Conservation conserve;
72 boolean displayBoxes = true;
74 boolean displayText = true;
76 boolean colourText = false;
79 * True if the group is defined as a group on the alignment, false if it is
82 boolean isDefined = false;
85 * after Olivier's non-conserved only character display
87 boolean showNonconserved = false;
92 private List<SequenceI> sequences = new ArrayList<>();
95 * representative sequence for this group (if any)
97 private SequenceI seqrep = null;
102 * Colourscheme applied to group if any
104 public ResidueShaderI cs;
106 // start column (base 0)
109 // end column (base 0)
112 public Color outlineColour = Color.black;
114 public Color idColour = null;
116 public int thresholdTextColour = 0;
118 public Color textColour = Color.black;
120 public Color textColour2 = Color.white;
123 * consensus calculation property
125 private boolean ignoreGapsInConsensus = true;
127 private boolean ignoreBelowBackground = true;
129 private boolean infoLetterHeight = false;
132 * consensus calculation property
134 private boolean showSequenceLogo = false;
137 * flag indicating if logo should be rendered normalised
139 private boolean normaliseSequenceLogo;
142 * visibility of rows or represented rows covered by group
144 private boolean hidereps = false;
147 * visibility of columns intersecting this group
149 private boolean hidecols = false;
151 AlignmentAnnotation consensus = null;
153 AlignmentAnnotation conservation = null;
155 AlignmentAnnotation information = null;
157 private boolean showConsensusHistogram;
159 private AnnotatedCollectionI context;
161 private boolean showHMMSequenceLogo;
163 private boolean normaliseHMMSequenceLogo;
165 private boolean showInformationHistogram;
168 * Creates a new SequenceGroup object.
170 public SequenceGroup()
172 groupName = "JGroup:" + this.hashCode();
173 cs = new ResidueShader();
177 * Creates a new SequenceGroup object.
182 * @param displayBoxes
186 * first column of group
188 * last column of group
190 public SequenceGroup(List<SequenceI> sequences, String groupName,
191 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
192 boolean colourText, int start, int end)
195 this.sequences = sequences;
196 this.groupName = groupName;
197 this.displayBoxes = displayBoxes;
198 this.displayText = displayText;
199 this.colourText = colourText;
200 this.cs = new ResidueShader(scheme);
203 recalcConservation();
211 public SequenceGroup(SequenceGroup seqsel)
216 sequences = new ArrayList<>();
217 sequences.addAll(seqsel.sequences);
218 if (seqsel.groupName != null)
220 groupName = new String(seqsel.groupName);
222 displayBoxes = seqsel.displayBoxes;
223 displayText = seqsel.displayText;
224 colourText = seqsel.colourText;
225 startRes = seqsel.startRes;
226 endRes = seqsel.endRes;
227 cs = new ResidueShader((ResidueShader) seqsel.cs);
228 if (seqsel.description != null)
230 description = new String(seqsel.description);
232 hidecols = seqsel.hidecols;
233 hidereps = seqsel.hidereps;
234 showNonconserved = seqsel.showNonconserved;
235 showSequenceLogo = seqsel.showSequenceLogo;
236 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
237 showConsensusHistogram = seqsel.showConsensusHistogram;
238 showHMMSequenceLogo = seqsel.showHMMSequenceLogo;
239 normaliseHMMSequenceLogo = seqsel.normaliseHMMSequenceLogo;
240 showInformationHistogram = seqsel.showInformationHistogram;
241 idColour = seqsel.idColour;
242 outlineColour = seqsel.outlineColour;
243 seqrep = seqsel.seqrep;
244 textColour = seqsel.textColour;
245 textColour2 = seqsel.textColour2;
246 thresholdTextColour = seqsel.thresholdTextColour;
247 width = seqsel.width;
248 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
249 ignoreBelowBackground = seqsel.ignoreBelowBackground;
250 infoLetterHeight = seqsel.infoLetterHeight;
251 if (seqsel.conserve != null)
253 recalcConservation(); // safer than
254 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
259 public boolean isShowSequenceLogo()
261 return showSequenceLogo;
264 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
266 int iSize = sequences.size();
267 SequenceI[] seqs = new SequenceI[iSize];
268 SequenceI[] inorder = getSequencesInOrder(align);
270 for (int i = 0, ipos = 0; i < inorder.length; i++)
272 SequenceI seq = inorder[i];
274 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
275 if (seqs[ipos] != null)
277 seqs[ipos].setDescription(seq.getDescription());
278 seqs[ipos].setDBRefs(seq.getDBRefs());
279 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
280 if (seq.getDatasetSequence() != null)
282 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
285 if (seq.getAnnotation() != null)
287 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
288 // Only copy annotation that is either a score or referenced by the
289 // alignment's annotation vector
290 for (int a = 0; a < seq.getAnnotation().length; a++)
292 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
295 boolean found = false;
296 for (int pos = 0; pos < alann.length; pos++)
298 if (alann[pos] == tocopy)
309 AlignmentAnnotation newannot = new AlignmentAnnotation(
310 seq.getAnnotation()[a]);
311 newannot.restrict(startRes, endRes);
312 newannot.setSequenceRef(seqs[ipos]);
313 newannot.adjustForAlignment();
314 seqs[ipos].addAlignmentAnnotation(newannot);
324 if (iSize != inorder.length)
326 SequenceI[] nseqs = new SequenceI[iSize];
327 System.arraycopy(seqs, 0, nseqs, 0, iSize);
335 * If sequence ends in gaps, the end residue can be correctly calculated here
341 public int findEndRes(SequenceI seq)
346 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
348 ch = seq.getCharAt(j);
349 if (!jalview.util.Comparison.isGap((ch)))
357 eres += seq.getStart() - 1;
364 public List<SequenceI> getSequences()
370 public List<SequenceI> getSequences(
371 Map<SequenceI, SequenceCollectionI> hiddenReps)
373 if (hiddenReps == null)
375 // TODO: need a synchronizedCollection here ?
380 List<SequenceI> allSequences = new ArrayList<>();
381 for (SequenceI seq : sequences)
383 allSequences.add(seq);
384 if (hiddenReps.containsKey(seq))
386 SequenceCollectionI hsg = hiddenReps.get(seq);
387 for (SequenceI seq2 : hsg.getSequences())
389 if (seq2 != seq && !allSequences.contains(seq2))
391 allSequences.add(seq2);
401 public SequenceI[] getSequencesAsArray(
402 Map<SequenceI, SequenceCollectionI> map)
404 List<SequenceI> tmp = getSequences(map);
409 return tmp.toArray(new SequenceI[tmp.size()]);
418 * @return DOCUMENT ME!
420 public boolean adjustForRemoveLeft(int col)
422 // return value is true if the group still exists
425 startRes = startRes - col;
430 endRes = endRes - col;
432 if (startRes > endRes)
439 // must delete this group!!
452 * @return DOCUMENT ME!
454 public boolean adjustForRemoveRight(int col)
473 * @return DOCUMENT ME!
475 public String getName()
480 public String getDescription()
491 public void setName(String name)
494 // TODO: URGENT: update dependent objects (annotation row)
497 public void setDescription(String desc)
505 * @return DOCUMENT ME!
507 public Conservation getConservation()
518 public void setConservation(Conservation c)
524 * Add s to this sequence group. If aligment sequence is already contained in
525 * group, it will not be added again, but recalculation may happen if the flag
529 * alignment sequence to be added
531 * true means Group's conservation should be recalculated
533 public void addSequence(SequenceI s, boolean recalc)
535 synchronized (sequences)
537 if (s != null && !sequences.contains(s))
540 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
541 sequences.size() - 1, sequences.size());
546 recalcConservation();
552 * Max Gaps Threshold (percent) for performing a conservation calculation
554 private int consPercGaps = 25;
557 * @return Max Gaps Threshold for performing a conservation calculation
559 public int getConsPercGaps()
565 * set Max Gaps Threshold (percent) for performing a conservation calculation
567 * @param consPercGaps
569 public void setConsPercGaps(int consPercGaps)
571 this.consPercGaps = consPercGaps;
575 * calculate residue conservation and colourschemes for group - but only if
576 * necessary. returns true if the calculation resulted in a visible change to
579 public boolean recalcConservation()
581 return recalcConservation(false);
585 * calculate residue conservation for group - but only if necessary. returns
586 * true if the calculation resulted in a visible change to group
589 * when set, colourschemes for this group are not refreshed after
592 public boolean recalcConservation(boolean defer)
594 if (cs == null && consensus == null && conservation == null
595 && information == null)
599 // TODO: try harder to detect changes in state in order to minimise
600 // recalculation effort
604 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
605 endRes + 1, showSequenceLogo);
606 if (information != null)
608 HiddenMarkovModel hmm = information.sequenceRef.getHMM();
610 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
611 (endRes + 1) - startRes, startRes, endRes + 1,
612 showHMMSequenceLogo, ignoreBelowBackground,
614 _updateInformationRow(info, sequences.size());
617 if (consensus != null)
619 _updateConsensusRow(cnsns, sequences.size());
624 cs.setConsensus(cnsns);
628 if ((conservation != null)
629 || (cs != null && cs.conservationApplied()))
631 Conservation c = new Conservation(groupName, sequences, startRes,
634 c.verdict(false, consPercGaps);
635 if (conservation != null)
637 _updateConservationRow(c);
641 if (cs.conservationApplied())
643 cs.setConservation(c);
646 // eager update - will cause a refresh of overview regardless
649 if (cs != null && !defer)
651 // TODO: JAL-2034 should cs.alignmentChanged modify return state
652 cs.alignmentChanged(context != null ? context : this, null);
659 } catch (java.lang.OutOfMemoryError err)
662 System.out.println("Out of memory loading groups: " + err);
667 private void _updateConservationRow(Conservation c)
669 if (conservation == null)
674 conservation.label = "Conservation for " + getName();
675 conservation.description = "Conservation for group " + getName()
676 + " less than " + consPercGaps + "% gaps";
677 // preserve width if already set
678 int aWidth = (conservation.annotations != null)
679 ? (endRes < conservation.annotations.length
680 ? conservation.annotations.length
683 conservation.annotations = null;
684 conservation.annotations = new Annotation[aWidth]; // should be alignment
686 c.completeAnnotations(conservation, null, startRes, endRes + 1);
689 public ProfilesI consensusData = null;
691 public ProfilesI informationData = null;
693 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
695 if (consensus == null)
699 consensus.label = "Consensus for " + getName();
700 consensus.description = "Percent Identity";
701 consensusData = cnsns;
702 // preserve width if already set
703 int aWidth = (consensus.annotations != null)
704 ? (endRes < consensus.annotations.length
705 ? consensus.annotations.length
708 consensus.annotations = null;
709 consensus.annotations = new Annotation[aWidth]; // should be alignment width
711 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
712 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
715 // ignoreGapsInConsensusCalculation);
719 * Recalculates the information content on the HMM annotation.
724 private void _updateInformationRow(ProfilesI cnsns, long nseq)
726 if (information == null)
730 information.description = MessageManager
731 .getString("label.information_description");
732 informationData = cnsns;
733 // preserve width if already set
734 int aWidth = (information.annotations != null)
735 ? (endRes < information.annotations.length
736 ? information.annotations.length : endRes + 1)
738 information.annotations = null;
739 information.annotations = new Annotation[aWidth]; // should be alignment
741 information.calcId = "HMM";
742 AAFrequency.completeInformation(information, cnsns, startRes,
743 endRes + 1, nseq, 0f); // TODO:
747 // ignoreGapsInInformationCalculation);
752 * sequence to either add or remove from group
754 * flag passed to delete/addSequence to indicate if group properties
755 * should be recalculated
757 public void addOrRemove(SequenceI s, boolean recalc)
759 synchronized (sequences)
761 if (sequences.contains(s))
763 deleteSequence(s, recalc);
767 addSequence(s, recalc);
778 * true means recalculate conservation
780 public void deleteSequence(SequenceI s, boolean recalc)
782 synchronized (sequences)
785 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
786 sequences.size() + 1, sequences.size());
790 recalcConservation();
798 * @return the first column selected by this group. Runs from 0<=i<N_cols
801 public int getStartRes()
808 * @return the groups last selected column. Runs from 0<=i<N_cols
811 public int getEndRes()
817 * Set the first column selected by this group. Runs from 0<=i<N_cols
821 public void setStartRes(int i)
823 int before = startRes;
825 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
829 * Set the groups last selected column. Runs from 0<=i<N_cols
833 public void setEndRes(int i)
837 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
841 * @return number of sequences in group
845 return sequences.size();
850 * @return the ith sequence
852 public SequenceI getSequenceAt(int i)
854 return sequences.get(i);
861 public void setColourText(boolean state)
869 * @return DOCUMENT ME!
871 public boolean getColourText()
882 public void setDisplayText(boolean state)
890 * @return DOCUMENT ME!
892 public boolean getDisplayText()
903 public void setDisplayBoxes(boolean state)
905 displayBoxes = state;
911 * @return DOCUMENT ME!
913 public boolean getDisplayBoxes()
919 * computes the width of current set of sequences and returns it
921 * @return DOCUMENT ME!
924 public int getWidth()
926 synchronized (sequences)
928 // MC This needs to get reset when characters are inserted and deleted
929 boolean first = true;
930 for (SequenceI seq : sequences)
932 if (first || seq.getLength() > width)
934 width = seq.getLength();
948 public void setOutlineColour(Color c)
956 * @return DOCUMENT ME!
958 public Color getOutlineColour()
960 return outlineColour;
965 * returns the sequences in the group ordered by the ordering given by al.
966 * this used to return an array with null entries regardless, new behaviour is
967 * below. TODO: verify that this does not affect use in applet or application
971 * @return SequenceI[] intersection of sequences in group with al, ordered by
972 * al, or null if group does not intersect with al
974 public SequenceI[] getSequencesInOrder(AlignmentI al)
976 return getSequencesInOrder(al, true);
980 * return an array representing the intersection of the group with al,
981 * optionally returning an array the size of al.getHeight() where nulls mark
982 * the non-intersected sequences
986 * @return null or array
988 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
990 synchronized (sequences)
992 int sSize = sequences.size();
993 int alHeight = al.getHeight();
995 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
998 for (int i = 0; i < alHeight && index < sSize; i++)
1000 if (sequences.contains(al.getSequenceAt(i)))
1002 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1014 if (index < seqs.length)
1016 SequenceI[] dummy = seqs;
1017 seqs = new SequenceI[index];
1018 while (--index >= 0)
1020 seqs[index] = dummy[index];
1021 dummy[index] = null;
1029 * @return the idColour
1031 public Color getIdColour()
1038 * the idColour to set
1040 public void setIdColour(Color idColour)
1042 this.idColour = idColour;
1046 * @return the representative sequence for this group
1049 public SequenceI getSeqrep()
1055 * set the representative sequence for this group. Note - this affects the
1056 * interpretation of the Hidereps attribute.
1059 * the seqrep to set (null means no sequence representative)
1062 public void setSeqrep(SequenceI seqrep)
1064 this.seqrep = seqrep;
1069 * @return true if group has a sequence representative
1072 public boolean hasSeqrep()
1074 return seqrep != null;
1078 * set visibility of sequences covered by (if no sequence representative is
1079 * defined) or represented by this group.
1083 public void setHidereps(boolean visibility)
1085 hidereps = visibility;
1090 * @return true if sequences represented (or covered) by this group should be
1093 public boolean isHidereps()
1099 * set intended visibility of columns covered by this group
1103 public void setHideCols(boolean visibility)
1105 hidecols = visibility;
1110 * @return true if columns covered by group should be hidden
1112 public boolean isHideCols()
1118 * create a new sequence group from the intersection of this group with an
1119 * alignment Hashtable of hidden representatives
1125 * @return new group containing sequences common to this group and alignment
1127 public SequenceGroup intersect(AlignmentI alignment,
1128 Map<SequenceI, SequenceCollectionI> map)
1130 SequenceGroup sgroup = new SequenceGroup(this);
1131 SequenceI[] insect = getSequencesInOrder(alignment);
1132 sgroup.sequences = new ArrayList<>();
1133 for (int s = 0; insect != null && s < insect.length; s++)
1135 if (map == null || map.containsKey(insect[s]))
1137 sgroup.sequences.add(insect[s]);
1144 * @return the showUnconserved
1146 public boolean getShowNonconserved()
1148 return showNonconserved;
1152 * @param showNonconserved
1153 * the showUnconserved to set
1155 public void setShowNonconserved(boolean displayNonconserved)
1157 this.showNonconserved = displayNonconserved;
1161 * set this alignmentAnnotation object as the one used to render consensus
1166 public void setConsensus(AlignmentAnnotation aan)
1168 if (consensus == null)
1176 * @return automatically calculated consensus row note: the row is a stub if a
1177 * consensus calculation has not yet been performed on the group
1179 public AlignmentAnnotation getConsensus()
1181 // TODO get or calculate and get consensus annotation row for this group
1182 int aWidth = this.getWidth();
1190 if (consensus == null)
1192 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1193 100f, AlignmentAnnotation.BAR_GRAPH);
1194 consensus.hasText = true;
1195 consensus.autoCalculated = true;
1196 consensus.groupRef = this;
1197 consensus.label = "Consensus for " + getName();
1198 consensus.description = "Percent Identity";
1205 * @return information content annotation.
1207 public AlignmentAnnotation getInformation()
1209 // TODO get or calculate and get information annotation row for this group
1210 int aWidth = this.getWidth();
1218 if (information == null)
1220 information = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1221 6.25f, AlignmentAnnotation.BAR_GRAPH);
1222 information.hasText = true;
1223 information.autoCalculated = false;
1224 information.groupRef = this;
1225 information.label = getName();
1226 information.description = "Information content, measured in bits";
1227 information.calcId = "HMM";
1233 * set this alignmentAnnotation object as the one used to render consensus
1238 public void setConservationRow(AlignmentAnnotation aan)
1240 if (conservation == null)
1247 * get the conservation annotation row for this group
1249 * @return autoCalculated annotation row
1251 public AlignmentAnnotation getConservationRow()
1253 if (conservation == null)
1255 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1256 11f, AlignmentAnnotation.BAR_GRAPH);
1259 conservation.hasText = true;
1260 conservation.autoCalculated = true;
1261 conservation.groupRef = this;
1262 conservation.label = "Conservation for " + getName();
1263 conservation.description = "Conservation for group " + getName()
1264 + " less than " + consPercGaps + "% gaps";
1265 return conservation;
1270 * @return true if annotation rows have been instantiated for this group
1272 public boolean hasAnnotationRows()
1274 return consensus != null || conservation != null;
1277 public SequenceI getConsensusSeq()
1280 StringBuffer seqs = new StringBuffer();
1281 for (int i = 0; i < consensus.annotations.length; i++)
1283 if (consensus.annotations[i] != null)
1285 if (consensus.annotations[i].description.charAt(0) == '[')
1287 seqs.append(consensus.annotations[i].description.charAt(1));
1291 seqs.append(consensus.annotations[i].displayCharacter);
1296 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1298 sq.setDescription("Percentage Identity Consensus "
1299 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1303 public void setIgnoreGapsConsensus(boolean state)
1305 if (this.ignoreGapsInConsensus != state && consensus != null)
1307 ignoreGapsInConsensus = state;
1308 recalcConservation();
1310 ignoreGapsInConsensus = state;
1313 public boolean getIgnoreGapsConsensus()
1315 return ignoreGapsInConsensus;
1318 public void setIgnoreBelowBackground(boolean state)
1320 if (this.ignoreBelowBackground != state)
1322 ignoreBelowBackground = state;
1324 ignoreBelowBackground = state;
1327 public boolean getIgnoreBelowBackground()
1329 return ignoreBelowBackground;
1332 public void setInfoLetterHeight(boolean state)
1334 if (this.infoLetterHeight != state)
1336 infoLetterHeight = state;
1338 infoLetterHeight = state;
1341 public boolean getInfoLetterHeight()
1343 return infoLetterHeight;
1347 * @param showSequenceLogo
1348 * indicates if a sequence logo is shown for consensus annotation
1350 public void setshowSequenceLogo(boolean showSequenceLogo)
1352 // TODO: decouple calculation from settings update
1353 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1355 this.showSequenceLogo = showSequenceLogo;
1356 recalcConservation();
1358 this.showSequenceLogo = showSequenceLogo;
1363 * @param showConsHist
1364 * flag indicating if the consensus histogram for this group should
1367 public void setShowConsensusHistogram(boolean showConsHist)
1370 if (showConsensusHistogram != showConsHist && consensus != null)
1372 this.showConsensusHistogram = showConsHist;
1373 recalcConservation();
1375 this.showConsensusHistogram = showConsHist;
1379 * @return the showConsensusHistogram
1381 public boolean isShowConsensusHistogram()
1383 return showConsensusHistogram;
1387 * set flag indicating if logo should be normalised when rendered
1391 public void setNormaliseSequenceLogo(boolean norm)
1393 normaliseSequenceLogo = norm;
1396 public boolean isNormaliseSequenceLogo()
1398 return normaliseSequenceLogo;
1403 * returns a new array with all annotation involving this group
1405 public AlignmentAnnotation[] getAlignmentAnnotation()
1407 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1409 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1410 synchronized (sequences)
1412 for (SequenceI seq : sequences)
1414 AlignmentAnnotation[] aa = seq.getAnnotation();
1417 for (AlignmentAnnotation al : aa)
1419 if (al.groupRef == this)
1426 if (consensus != null)
1428 annot.add(consensus);
1430 if (conservation != null)
1432 annot.add(conservation);
1435 return annot.toArray(new AlignmentAnnotation[0]);
1439 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1441 return AlignmentAnnotation.findAnnotation(
1442 Arrays.asList(getAlignmentAnnotation()), calcId);
1446 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1447 String calcId, String label)
1449 return AlignmentAnnotation.findAnnotations(
1450 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1454 * Answer true if any annotation matches the calcId passed in (if not null).
1459 public boolean hasAnnotation(String calcId)
1461 return AlignmentAnnotation
1462 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1466 * Remove all sequences from the group (leaving other properties unchanged).
1470 synchronized (sequences)
1472 int before = sequences.size();
1474 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1480 * Sets the alignment or group context for this group, and whether it is
1481 * defined as a group
1484 * the context for the group
1486 * whether the group is defined on the alignment or is just a
1488 * @throws IllegalArgumentException
1489 * if setting the context would result in a circular reference chain
1491 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1494 this.isDefined = defined;
1498 * Sets the alignment or group context for this group
1501 * the context for the group
1502 * @throws IllegalArgumentException
1503 * if setting the context would result in a circular reference chain
1505 public void setContext(AnnotatedCollectionI ctx)
1507 AnnotatedCollectionI ref = ctx;
1510 if (ref == this || ref.getContext() == ctx)
1512 throw new IllegalArgumentException(
1513 "Circular reference in SequenceGroup.context");
1515 ref = ref.getContext();
1523 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1526 public AnnotatedCollectionI getContext()
1531 public boolean isDefined()
1536 public void setColourScheme(ColourSchemeI scheme)
1540 cs = new ResidueShader();
1542 cs.setColourScheme(scheme);
1545 public void setGroupColourScheme(ResidueShaderI scheme)
1550 public ColourSchemeI getColourScheme()
1552 return cs == null ? null : cs.getColourScheme();
1555 public ResidueShaderI getGroupColourScheme()
1561 public boolean isNucleotide()
1563 if (context != null)
1565 return context.isNucleotide();
1572 * @return true if seq is a member of the group
1575 public boolean contains(SequenceI seq1)
1577 return sequences.contains(seq1);
1583 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1585 public boolean contains(SequenceI seq, int apos)
1587 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1590 public boolean isShowInformationHistogram()
1592 return showInformationHistogram;
1595 public void setShowInformationHistogram(boolean state)
1597 if (showInformationHistogram != state && information != null)
1599 this.showInformationHistogram = state;
1600 // recalcConservation(); TODO don't know what to do here next
1602 this.showInformationHistogram = state;
1606 public boolean isShowHMMSequenceLogo()
1608 return showHMMSequenceLogo;
1611 public void setshowHMMSequenceLogo(boolean state)
1613 showHMMSequenceLogo = state;
1617 public boolean isNormaliseHMMSequenceLogo()
1619 return normaliseHMMSequenceLogo;
1622 public void setNormaliseHMMSequenceLogo(boolean state)
1624 normaliseSequenceLogo = state;
1628 * Returns all HMM consensus sequences. This will not return real sequences
1632 public List<SequenceI> getHMMConsensusSequences()
1634 List<SequenceI> seqs = new ArrayList<>();
1636 for (int position = 0; position < sequences.size(); position++)
1638 SequenceI seq = sequences.get(position);
1639 if (seq.isHMMConsensusSequence())