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
49 // subclass of ViewportProperties similarly to ViewportRanges. Done here as
50 // quick fix for JAL-2665
51 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
53 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
56 public void addPropertyChangeListener(PropertyChangeListener listener)
58 changeSupport.addPropertyChangeListener(listener);
61 public void removePropertyChangeListener(PropertyChangeListener listener)
63 changeSupport.removePropertyChangeListener(listener);
65 // end of event notification functionality initialisation
71 Conservation conserve;
73 boolean displayBoxes = true;
75 boolean displayText = true;
77 boolean colourText = false;
80 * True if the group is defined as a group on the alignment, false if it is
83 boolean isDefined = false;
86 * after Olivier's non-conserved only character display
88 boolean showNonconserved = false;
93 private List<SequenceI> sequences = new ArrayList<>();
96 * representative sequence for this group (if any)
98 private SequenceI seqrep = null;
103 * Colourscheme applied to group if any
105 public ResidueShaderI cs;
107 // start column (base 0)
110 // end column (base 0)
113 public Color outlineColour = Color.black;
115 public Color idColour = null;
117 public int thresholdTextColour = 0;
119 public Color textColour = Color.black;
121 public Color textColour2 = Color.white;
124 * consensus calculation property
126 private boolean ignoreGapsInConsensus = true;
128 private boolean ignoreBelowBackground = true;
130 private boolean infoLetterHeight = false;
133 * consensus calculation property
135 private boolean showSequenceLogo = false;
138 * flag indicating if logo should be rendered normalised
140 private boolean normaliseSequenceLogo;
143 * visibility of rows or represented rows covered by group
145 private boolean hidereps = false;
148 * visibility of columns intersecting this group
150 private boolean hidecols = false;
152 AlignmentAnnotation consensus = null;
154 AlignmentAnnotation conservation = null;
156 AlignmentAnnotation information = null;
158 private boolean showConsensusHistogram;
160 private AnnotatedCollectionI context;
162 private boolean showHMMSequenceLogo;
164 private boolean normaliseHMMSequenceLogo;
166 private boolean showInformationHistogram;
169 * Creates a new SequenceGroup object.
171 public SequenceGroup()
173 groupName = "JGroup:" + this.hashCode();
174 cs = new ResidueShader();
178 * Creates a new SequenceGroup object.
183 * @param displayBoxes
187 * first column of group
189 * last column of group
191 public SequenceGroup(List<SequenceI> sequences, String groupName,
192 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
193 boolean colourText, int start, int end)
196 this.sequences = sequences;
197 this.groupName = groupName;
198 this.displayBoxes = displayBoxes;
199 this.displayText = displayText;
200 this.colourText = colourText;
201 this.cs = new ResidueShader(scheme);
204 recalcConservation();
212 public SequenceGroup(SequenceGroup seqsel)
217 sequences = new ArrayList<>();
218 sequences.addAll(seqsel.sequences);
219 if (seqsel.groupName != null)
221 groupName = new String(seqsel.groupName);
223 displayBoxes = seqsel.displayBoxes;
224 displayText = seqsel.displayText;
225 colourText = seqsel.colourText;
226 startRes = seqsel.startRes;
227 endRes = seqsel.endRes;
228 cs = new ResidueShader((ResidueShader) seqsel.cs);
229 if (seqsel.description != null)
231 description = new String(seqsel.description);
233 hidecols = seqsel.hidecols;
234 hidereps = seqsel.hidereps;
235 showNonconserved = seqsel.showNonconserved;
236 showSequenceLogo = seqsel.showSequenceLogo;
237 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
238 showConsensusHistogram = seqsel.showConsensusHistogram;
239 showHMMSequenceLogo = seqsel.showHMMSequenceLogo;
240 normaliseHMMSequenceLogo = seqsel.normaliseHMMSequenceLogo;
241 showInformationHistogram = seqsel.showInformationHistogram;
242 idColour = seqsel.idColour;
243 outlineColour = seqsel.outlineColour;
244 seqrep = seqsel.seqrep;
245 textColour = seqsel.textColour;
246 textColour2 = seqsel.textColour2;
247 thresholdTextColour = seqsel.thresholdTextColour;
248 width = seqsel.width;
249 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
250 ignoreBelowBackground = seqsel.ignoreBelowBackground;
251 infoLetterHeight = seqsel.infoLetterHeight;
252 if (seqsel.conserve != null)
254 recalcConservation(); // safer than
255 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
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()
519 public void setConservation(Conservation 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 recalcConservation(false);
586 * calculate residue conservation for group - but only if necessary. returns
587 * true if the calculation resulted in a visible change to group
590 * when set, colourschemes for this group are not refreshed after
593 public boolean recalcConservation(boolean defer)
595 if (cs == null && consensus == null && conservation == null
596 && information == null)
600 // TODO: try harder to detect changes in state in order to minimise
601 // recalculation effort
605 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
606 endRes + 1, showSequenceLogo);
607 if (information != null)
609 HiddenMarkovModel hmm = information.sequenceRef.getHMM();
611 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
612 (endRes + 1) - startRes, startRes, endRes + 1,
613 showHMMSequenceLogo, ignoreBelowBackground,
615 _updateInformationRow(info, sequences.size());
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 public ProfilesI consensusData = null;
692 public ProfilesI informationData = null;
694 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
696 if (consensus == null)
700 consensus.label = "Consensus for " + getName();
701 consensus.description = "Percent Identity";
702 consensusData = cnsns;
703 // preserve width if already set
704 int aWidth = (consensus.annotations != null)
705 ? (endRes < consensus.annotations.length
706 ? consensus.annotations.length
709 consensus.annotations = null;
710 consensus.annotations = new Annotation[aWidth]; // should be alignment width
712 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
713 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
716 // ignoreGapsInConsensusCalculation);
720 * Recalculates the information content on the HMM annotation.
725 private void _updateInformationRow(ProfilesI cnsns, long nseq)
727 if (information == null)
731 information.description = MessageManager
732 .getString("label.information_description");
733 informationData = cnsns;
734 // preserve width if already set
735 int aWidth = (information.annotations != null)
736 ? (endRes < information.annotations.length
737 ? information.annotations.length : endRes + 1)
739 information.annotations = null;
740 information.annotations = new Annotation[aWidth]; // should be alignment
742 information.setCalcId(InformationThread.HMM_CALC_ID);
743 AAFrequency.completeInformation(information, cnsns, startRes,
744 endRes + 1, nseq, 0f);
749 * sequence to either add or remove from group
751 * flag passed to delete/addSequence to indicate if group properties
752 * should be recalculated
754 public void addOrRemove(SequenceI s, boolean recalc)
756 synchronized (sequences)
758 if (sequences.contains(s))
760 deleteSequence(s, recalc);
764 addSequence(s, recalc);
775 * true means recalculate conservation
777 public void deleteSequence(SequenceI s, boolean recalc)
779 synchronized (sequences)
782 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
783 sequences.size() + 1, sequences.size());
787 recalcConservation();
795 * @return the first column selected by this group. Runs from 0<=i<N_cols
798 public int getStartRes()
805 * @return the groups last selected column. Runs from 0<=i<N_cols
808 public int getEndRes()
814 * Set the first column selected by this group. Runs from 0<=i<N_cols
818 public void setStartRes(int i)
820 int before = startRes;
822 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
826 * Set the groups last selected column. Runs from 0<=i<N_cols
830 public void setEndRes(int i)
834 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
838 * @return number of sequences in group
842 return sequences.size();
847 * @return the ith sequence
849 public SequenceI getSequenceAt(int i)
851 return sequences.get(i);
858 public void setColourText(boolean state)
866 * @return DOCUMENT ME!
868 public boolean getColourText()
879 public void setDisplayText(boolean state)
887 * @return DOCUMENT ME!
889 public boolean getDisplayText()
900 public void setDisplayBoxes(boolean state)
902 displayBoxes = state;
908 * @return DOCUMENT ME!
910 public boolean getDisplayBoxes()
916 * computes the width of current set of sequences and returns it
918 * @return DOCUMENT ME!
921 public int getWidth()
923 synchronized (sequences)
925 // MC This needs to get reset when characters are inserted and deleted
926 boolean first = true;
927 for (SequenceI seq : sequences)
929 if (first || seq.getLength() > width)
931 width = seq.getLength();
945 public void setOutlineColour(Color c)
953 * @return DOCUMENT ME!
955 public Color getOutlineColour()
957 return outlineColour;
962 * returns the sequences in the group ordered by the ordering given by al.
963 * this used to return an array with null entries regardless, new behaviour is
964 * below. TODO: verify that this does not affect use in applet or application
968 * @return SequenceI[] intersection of sequences in group with al, ordered by
969 * al, or null if group does not intersect with al
971 public SequenceI[] getSequencesInOrder(AlignmentI al)
973 return getSequencesInOrder(al, true);
977 * return an array representing the intersection of the group with al,
978 * optionally returning an array the size of al.getHeight() where nulls mark
979 * the non-intersected sequences
983 * @return null or array
985 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
987 synchronized (sequences)
989 int sSize = sequences.size();
990 int alHeight = al.getHeight();
992 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
995 for (int i = 0; i < alHeight && index < sSize; i++)
997 if (sequences.contains(al.getSequenceAt(i)))
999 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1011 if (index < seqs.length)
1013 SequenceI[] dummy = seqs;
1014 seqs = new SequenceI[index];
1015 while (--index >= 0)
1017 seqs[index] = dummy[index];
1018 dummy[index] = null;
1026 * @return the idColour
1028 public Color getIdColour()
1035 * the idColour to set
1037 public void setIdColour(Color idColour)
1039 this.idColour = idColour;
1043 * @return the representative sequence for this group
1046 public SequenceI getSeqrep()
1052 * set the representative sequence for this group. Note - this affects the
1053 * interpretation of the Hidereps attribute.
1056 * the seqrep to set (null means no sequence representative)
1059 public void setSeqrep(SequenceI seqrep)
1061 this.seqrep = seqrep;
1066 * @return true if group has a sequence representative
1069 public boolean hasSeqrep()
1071 return seqrep != null;
1075 * set visibility of sequences covered by (if no sequence representative is
1076 * defined) or represented by this group.
1080 public void setHidereps(boolean visibility)
1082 hidereps = visibility;
1087 * @return true if sequences represented (or covered) by this group should be
1090 public boolean isHidereps()
1096 * set intended visibility of columns covered by this group
1100 public void setHideCols(boolean visibility)
1102 hidecols = visibility;
1107 * @return true if columns covered by group should be hidden
1109 public boolean isHideCols()
1115 * create a new sequence group from the intersection of this group with an
1116 * alignment Hashtable of hidden representatives
1122 * @return new group containing sequences common to this group and alignment
1124 public SequenceGroup intersect(AlignmentI alignment,
1125 Map<SequenceI, SequenceCollectionI> map)
1127 SequenceGroup sgroup = new SequenceGroup(this);
1128 SequenceI[] insect = getSequencesInOrder(alignment);
1129 sgroup.sequences = new ArrayList<>();
1130 for (int s = 0; insect != null && s < insect.length; s++)
1132 if (map == null || map.containsKey(insect[s]))
1134 sgroup.sequences.add(insect[s]);
1141 * @return the showUnconserved
1143 public boolean getShowNonconserved()
1145 return showNonconserved;
1149 * @param showNonconserved
1150 * the showUnconserved to set
1152 public void setShowNonconserved(boolean displayNonconserved)
1154 this.showNonconserved = displayNonconserved;
1158 * set this alignmentAnnotation object as the one used to render consensus
1163 public void setConsensus(AlignmentAnnotation aan)
1165 if (consensus == null)
1173 * @return automatically calculated consensus row note: the row is a stub if a
1174 * consensus calculation has not yet been performed on the group
1176 public AlignmentAnnotation getConsensus()
1178 // TODO get or calculate and get consensus annotation row for this group
1179 int aWidth = this.getWidth();
1187 if (consensus == null)
1189 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1190 100f, AlignmentAnnotation.BAR_GRAPH);
1191 consensus.hasText = true;
1192 consensus.autoCalculated = true;
1193 consensus.groupRef = this;
1194 consensus.label = "Consensus for " + getName();
1195 consensus.description = "Percent Identity";
1201 * Answers the Hidden Markov Model annotation for this group (creating it if
1206 public AlignmentAnnotation getInformation()
1208 if (information == null)
1210 information = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1211 6.25f, AlignmentAnnotation.BAR_GRAPH);
1212 information.hasText = true;
1213 information.autoCalculated = false;
1214 information.groupRef = this;
1215 information.label = getName();
1216 information.description = MessageManager
1217 .getString("label.information_description");
1218 information.setCalcId(InformationThread.HMM_CALC_ID);
1224 * set this alignmentAnnotation object as the one used to render consensus
1229 public void setConservationRow(AlignmentAnnotation aan)
1231 if (conservation == null)
1238 * get the conservation annotation row for this group
1240 * @return autoCalculated annotation row
1242 public AlignmentAnnotation getConservationRow()
1244 if (conservation == null)
1246 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1247 11f, AlignmentAnnotation.BAR_GRAPH);
1250 conservation.hasText = true;
1251 conservation.autoCalculated = true;
1252 conservation.groupRef = this;
1253 conservation.label = "Conservation for " + getName();
1254 conservation.description = "Conservation for group " + getName()
1255 + " less than " + consPercGaps + "% gaps";
1256 return conservation;
1261 * @return true if annotation rows have been instantiated for this group
1263 public boolean hasAnnotationRows()
1265 return consensus != null || conservation != null;
1268 public SequenceI getConsensusSeq()
1271 StringBuffer seqs = new StringBuffer();
1272 for (int i = 0; i < consensus.annotations.length; i++)
1274 if (consensus.annotations[i] != null)
1276 if (consensus.annotations[i].description.charAt(0) == '[')
1278 seqs.append(consensus.annotations[i].description.charAt(1));
1282 seqs.append(consensus.annotations[i].displayCharacter);
1287 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1289 sq.setDescription("Percentage Identity Consensus "
1290 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1294 public void setIgnoreGapsConsensus(boolean state)
1296 if (this.ignoreGapsInConsensus != state && consensus != null)
1298 ignoreGapsInConsensus = state;
1299 recalcConservation();
1301 ignoreGapsInConsensus = state;
1304 public boolean getIgnoreGapsConsensus()
1306 return ignoreGapsInConsensus;
1309 public void setIgnoreBelowBackground(boolean state)
1311 if (this.ignoreBelowBackground != state)
1313 ignoreBelowBackground = state;
1315 ignoreBelowBackground = state;
1318 public boolean getIgnoreBelowBackground()
1320 return ignoreBelowBackground;
1323 public void setInfoLetterHeight(boolean state)
1325 if (this.infoLetterHeight != state)
1327 infoLetterHeight = state;
1329 infoLetterHeight = state;
1332 public boolean getInfoLetterHeight()
1334 return infoLetterHeight;
1338 * @param showSequenceLogo
1339 * indicates if a sequence logo is shown for consensus annotation
1341 public void setshowSequenceLogo(boolean showSequenceLogo)
1343 // TODO: decouple calculation from settings update
1344 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1346 this.showSequenceLogo = showSequenceLogo;
1347 recalcConservation();
1349 this.showSequenceLogo = showSequenceLogo;
1354 * @param showConsHist
1355 * flag indicating if the consensus histogram for this group should
1358 public void setShowConsensusHistogram(boolean showConsHist)
1361 if (showConsensusHistogram != showConsHist && consensus != null)
1363 this.showConsensusHistogram = showConsHist;
1364 recalcConservation();
1366 this.showConsensusHistogram = showConsHist;
1370 * @return the showConsensusHistogram
1372 public boolean isShowConsensusHistogram()
1374 return showConsensusHistogram;
1378 * set flag indicating if logo should be normalised when rendered
1382 public void setNormaliseSequenceLogo(boolean norm)
1384 normaliseSequenceLogo = norm;
1387 public boolean isNormaliseSequenceLogo()
1389 return normaliseSequenceLogo;
1394 * returns a new array with all annotation involving this group
1396 public AlignmentAnnotation[] getAlignmentAnnotation()
1398 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1400 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1401 synchronized (sequences)
1403 for (SequenceI seq : sequences)
1405 AlignmentAnnotation[] aa = seq.getAnnotation();
1408 for (AlignmentAnnotation al : aa)
1410 if (al.groupRef == this)
1417 if (consensus != null)
1419 annot.add(consensus);
1421 if (conservation != null)
1423 annot.add(conservation);
1426 return annot.toArray(new AlignmentAnnotation[0]);
1430 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1432 return AlignmentAnnotation.findAnnotation(
1433 Arrays.asList(getAlignmentAnnotation()), calcId);
1437 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1438 String calcId, String label)
1440 return AlignmentAnnotation.findAnnotations(
1441 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1445 * Answer true if any annotation matches the calcId passed in (if not null).
1450 public boolean hasAnnotation(String calcId)
1452 return AlignmentAnnotation
1453 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1457 * Remove all sequences from the group (leaving other properties unchanged).
1461 synchronized (sequences)
1463 int before = sequences.size();
1465 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1471 * Sets the alignment or group context for this group, and whether it is
1472 * defined as a group
1475 * the context for the group
1477 * whether the group is defined on the alignment or is just a
1479 * @throws IllegalArgumentException
1480 * if setting the context would result in a circular reference chain
1482 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1485 this.isDefined = defined;
1489 * Sets the alignment or group context for this group
1492 * the context for the group
1493 * @throws IllegalArgumentException
1494 * if setting the context would result in a circular reference chain
1496 public void setContext(AnnotatedCollectionI ctx)
1498 AnnotatedCollectionI ref = ctx;
1501 if (ref == this || ref.getContext() == ctx)
1503 throw new IllegalArgumentException(
1504 "Circular reference in SequenceGroup.context");
1506 ref = ref.getContext();
1514 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1517 public AnnotatedCollectionI getContext()
1522 public boolean isDefined()
1527 public void setColourScheme(ColourSchemeI scheme)
1531 cs = new ResidueShader();
1533 cs.setColourScheme(scheme);
1536 public void setGroupColourScheme(ResidueShaderI scheme)
1541 public ColourSchemeI getColourScheme()
1543 return cs == null ? null : cs.getColourScheme();
1546 public ResidueShaderI getGroupColourScheme()
1552 public boolean isNucleotide()
1554 if (context != null)
1556 return context.isNucleotide();
1563 * @return true if seq is a member of the group
1566 public boolean contains(SequenceI seq1)
1568 return sequences.contains(seq1);
1574 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1576 public boolean contains(SequenceI seq, int apos)
1578 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1581 public boolean isShowInformationHistogram()
1583 return showInformationHistogram;
1586 public void setShowInformationHistogram(boolean state)
1588 if (showInformationHistogram != state && information != null)
1590 this.showInformationHistogram = state;
1591 // recalcConservation(); TODO don't know what to do here next
1593 this.showInformationHistogram = state;
1597 public boolean isShowHMMSequenceLogo()
1599 return showHMMSequenceLogo;
1602 public void setshowHMMSequenceLogo(boolean state)
1604 showHMMSequenceLogo = state;
1608 public boolean isNormaliseHMMSequenceLogo()
1610 return normaliseHMMSequenceLogo;
1613 public void setNormaliseHMMSequenceLogo(boolean state)
1615 normaliseSequenceLogo = state;
1619 * Returns all HMM consensus sequences. This will not return real sequences
1623 public List<SequenceI> getHMMConsensusSequences()
1625 List<SequenceI> seqs = new ArrayList<>();
1627 for (int position = 0; position < sequences.size(); position++)
1629 SequenceI seq = sequences.get(position);
1630 if (seq.isHMMConsensusSequence())