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 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 Conservation conservationData;
74 ProfilesI consensusProfiles;
76 ProfilesI hmmProfiles;
78 boolean displayBoxes = true;
80 boolean displayText = true;
82 boolean colourText = false;
85 * true if the group is defined as a group on the alignment, false if it is
88 boolean isDefined = false;
91 * after Olivier's non-conserved only character display
93 boolean showNonconserved = false;
96 * sequences in the group
98 private List<SequenceI> sequences;
101 * representative sequence for this group (if any)
103 private SequenceI seqrep = null;
108 * colour scheme applied to group if any
110 public ResidueShaderI cs;
113 * start column (base 0)
115 private int startRes = 0;
118 * end column (base 0)
120 private int endRes = 0;
122 public Color outlineColour = Color.black;
124 public Color idColour = null;
126 public int thresholdTextColour = 0;
128 public Color textColour = Color.black;
130 public Color textColour2 = Color.white;
133 * properties for consensus annotation
135 private boolean ignoreGapsInConsensus = true;
137 private boolean showSequenceLogo = false;
139 private boolean normaliseSequenceLogo;
142 * properties for HMM information annotation
144 private boolean hmmIgnoreBelowBackground = true;
146 private boolean hmmUseInfoLetterHeight;
148 private boolean hmmShowSequenceLogo;
150 private boolean hmmNormaliseSequenceLogo;
152 private boolean hmmShowHistogram;
155 * visibility of rows or represented rows covered by group
157 private boolean hidereps = false;
160 * visibility of columns intersecting this group
162 private boolean hidecols;
164 AlignmentAnnotation consensus = null;
166 AlignmentAnnotation conservation = null;
168 private AlignmentAnnotation hmmInformation;
170 private boolean showConsensusHistogram;
172 private AnnotatedCollectionI context;
176 * Constructor, assigning a generated default name of "JGroup:" with object
179 public SequenceGroup()
181 groupName = "JGroup:" + this.hashCode();
182 cs = new ResidueShader();
183 sequences = new ArrayList<>();
187 * Creates a new SequenceGroup object.
192 * @param displayBoxes
196 * first column of group
198 * last column of group
200 public SequenceGroup(List<SequenceI> sequences, String groupName,
201 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
202 boolean colourText, int start, int end)
205 this.sequences = sequences;
206 this.groupName = groupName;
207 this.displayBoxes = displayBoxes;
208 this.displayText = displayText;
209 this.colourText = colourText;
210 this.cs = new ResidueShader(scheme);
213 recalcConservation();
220 * @param keepsequences
221 * if false do not add sequences from seqsel to new instance
223 public SequenceGroup(SequenceGroup seqsel)
229 sequences = new ArrayList<>();
230 sequences.addAll(seqsel.sequences);
231 if (seqsel.groupName != null)
233 groupName = new String(seqsel.groupName);
235 displayBoxes = seqsel.displayBoxes;
236 displayText = seqsel.displayText;
237 colourText = seqsel.colourText;
239 startRes = seqsel.startRes;
240 endRes = seqsel.endRes;
241 cs = new ResidueShader((ResidueShader) seqsel.cs);
242 if (seqsel.description != null)
244 description = new String(seqsel.description);
246 hidecols = seqsel.hidecols;
247 hidereps = seqsel.hidereps;
248 showNonconserved = seqsel.showNonconserved;
249 showSequenceLogo = seqsel.showSequenceLogo;
250 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
251 showConsensusHistogram = seqsel.showConsensusHistogram;
252 hmmShowSequenceLogo = seqsel.hmmShowSequenceLogo;
253 hmmNormaliseSequenceLogo = seqsel.hmmNormaliseSequenceLogo;
254 hmmShowHistogram = seqsel.hmmShowHistogram;
255 idColour = seqsel.idColour;
256 outlineColour = seqsel.outlineColour;
257 seqrep = seqsel.seqrep;
258 textColour = seqsel.textColour;
259 textColour2 = seqsel.textColour2;
260 thresholdTextColour = seqsel.thresholdTextColour;
261 width = seqsel.width;
262 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
263 hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
264 hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
265 if (seqsel.conserve != null)
267 // todo avoid doing this if we don't actually want derived calculations
269 recalcConservation(); // safer than
270 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
276 * Constructor that copies the given list of sequences
280 public SequenceGroup(List<SequenceI> seqs)
283 this.sequences.addAll(seqs);
286 public boolean isShowSequenceLogo()
288 return showSequenceLogo;
291 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
293 int iSize = sequences.size();
294 SequenceI[] seqs = new SequenceI[iSize];
295 SequenceI[] inorder = getSequencesInOrder(align);
297 for (int i = 0, ipos = 0; i < inorder.length; i++)
299 SequenceI seq = inorder[i];
300 SequenceI seqipos = seqs[ipos] = seq.getSubSequence(startRes,
304 seqipos.setDescription(seq.getDescription());
305 seqipos.setDBRefs(seq.getDBRefs());
306 seqipos.setSequenceFeatures(seq.getSequenceFeatures());
307 if (seq.getDatasetSequence() != null)
309 seqipos.setDatasetSequence(seq.getDatasetSequence());
312 if (seq.getAnnotation() != null)
314 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
315 // Only copy annotation that is either a score or referenced by the
316 // alignment's annotation vector
317 for (int a = 0; a < seq.getAnnotation().length; a++)
319 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
322 boolean found = false;
323 for (int pos = 0, np = alann.length; pos < np; pos++)
325 if (alann[pos] == tocopy)
336 AlignmentAnnotation newannot = new AlignmentAnnotation(
337 seq.getAnnotation()[a]);
338 newannot.restrict(startRes, endRes);
339 newannot.setSequenceRef(seqs[ipos]);
340 newannot.adjustForAlignment();
341 seqipos.addAlignmentAnnotation(newannot);
351 if (iSize != inorder.length)
353 SequenceI[] nseqs = new SequenceI[iSize];
354 System.arraycopy(seqs, 0, nseqs, 0, iSize);
362 * If sequence ends in gaps, the end residue can be correctly calculated here
368 public int findEndRes(SequenceI seq)
373 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
375 ch = seq.getCharAt(j);
376 if (!jalview.util.Comparison.isGap((ch)))
384 eres += seq.getStart() - 1;
391 public List<SequenceI> getSequences()
397 public List<SequenceI> getSequences(
398 Map<SequenceI, SequenceCollectionI> hiddenReps)
400 if (hiddenReps == null)
402 // TODO: need a synchronizedCollection here ?
407 List<SequenceI> allSequences = new ArrayList<>();
408 for (SequenceI seq : sequences)
410 allSequences.add(seq);
411 if (hiddenReps.containsKey(seq))
413 SequenceCollectionI hsg = hiddenReps.get(seq);
414 for (SequenceI seq2 : hsg.getSequences())
416 if (seq2 != seq && !allSequences.contains(seq2))
418 allSequences.add(seq2);
428 public SequenceI[] getSequencesAsArray(
429 Map<SequenceI, SequenceCollectionI> map)
431 List<SequenceI> tmp = getSequences(map);
436 return tmp.toArray(new SequenceI[tmp.size()]);
445 * @return DOCUMENT ME!
447 public boolean adjustForRemoveLeft(int col)
449 // return value is true if the group still exists
452 startRes = startRes - col;
457 endRes = endRes - col;
459 if (startRes > endRes)
466 // must delete this group!!
479 * @return DOCUMENT ME!
481 public boolean adjustForRemoveRight(int col)
500 * @return DOCUMENT ME!
502 public String getName()
507 public String getDescription()
518 public void setName(String name)
521 // TODO: URGENT: update dependent objects (annotation row)
524 public void setDescription(String desc)
532 * @return DOCUMENT ME!
534 public Conservation getConservation()
545 public void setConservation(Conservation c)
551 * Add s to this sequence group. If aligment sequence is already contained in
552 * group, it will not be added again, but recalculation may happen if the flag
556 * alignment sequence to be added
558 * true means Group's conservation should be recalculated
560 public void addSequence(SequenceI s, boolean recalc)
562 synchronized (sequences)
564 if (s != null && !sequences.contains(s))
567 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
568 sequences.size() - 1, sequences.size());
573 recalcConservation();
579 * Max Gaps Threshold (percent) for performing a conservation calculation
581 private int consPercGaps = 25;
584 * @return Max Gaps Threshold for performing a conservation calculation
586 public int getConsPercGaps()
592 * set Max Gaps Threshold (percent) for performing a conservation calculation
594 * @param consPercGaps
596 public void setConsPercGaps(int consPercGaps)
598 this.consPercGaps = consPercGaps;
602 * calculate residue conservation and colourschemes for group - but only if
603 * necessary. returns true if the calculation resulted in a visible change to
606 public boolean recalcConservation()
608 return recalcConservation(false);
612 * Recalculates column consensus, conservation, and HMM annotation for the
613 * group (as applicable). Returns true if the calculation resulted in a
614 * visible change to group.
617 * when set, colourschemes for this group are not refreshed after
620 public boolean recalcConservation(boolean defer)
622 if (cs == null && consensus == null && conservation == null
623 && hmmInformation == null)
627 // TODO: try harder to detect changes in state in order to minimise
628 // recalculation effort
632 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
633 endRes + 1, showSequenceLogo);
634 if (hmmInformation != null)
636 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
638 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
639 (endRes + 1) - startRes, startRes, endRes + 1,
640 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
641 _updateInformationRow(info);
644 if (consensus != null)
646 _updateConsensusRow(cnsns, sequences.size());
651 cs.setConsensus(cnsns);
655 if ((conservation != null)
656 || (cs != null && cs.conservationApplied()))
658 Conservation c = new Conservation(groupName, sequences, startRes,
661 c.verdict(false, consPercGaps);
662 if (conservation != null)
664 _updateConservationRow(c);
668 if (cs.conservationApplied())
670 cs.setConservation(c);
673 // eager update - will cause a refresh of overview regardless
676 if (cs != null && !defer)
678 // TODO: JAL-2034 should cs.alignmentChanged modify return state
679 cs.alignmentChanged(context != null ? context : this, null);
686 } catch (java.lang.OutOfMemoryError err)
689 System.out.println("Out of memory loading groups: " + err);
694 private void _updateConservationRow(Conservation c)
696 if (conservation == null)
701 conservation.label = "Conservation for " + getName();
702 conservation.description = "Conservation for group " + getName()
703 + " less than " + consPercGaps + "% gaps";
704 // preserve width if already set
705 int aWidth = (conservation.annotations != null)
706 ? (endRes < conservation.annotations.length
707 ? conservation.annotations.length
710 conservation.annotations = null;
711 conservation.annotations = new Annotation[aWidth]; // should be alignment
713 c.completeAnnotations(conservation, null, startRes, endRes + 1);
716 public ProfilesI consensusData = null;
718 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
720 if (consensus == null)
724 consensus.label = "Consensus for " + getName();
725 consensus.description = "Percent Identity";
726 consensusData = cnsns;
727 // preserve width if already set
728 int aWidth = (consensus.annotations != null)
729 ? (endRes < consensus.annotations.length
730 ? consensus.annotations.length
733 consensus.annotations = null;
734 consensus.annotations = new Annotation[aWidth]; // should be alignment width
736 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
737 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
740 // ignoreGapsInConsensusCalculation);
744 * Recalculates the information content on the HMM annotation
748 private void _updateInformationRow(ProfilesI cnsns)
750 if (hmmInformation == null)
752 createInformationAnnotation();
754 hmmInformation.description = MessageManager
755 .getString("label.information_description");
756 setHmmProfiles(cnsns);
757 // preserve width if already set
758 int aWidth = (hmmInformation.annotations != null)
759 ? (endRes < hmmInformation.annotations.length
760 ? hmmInformation.annotations.length : endRes + 1)
762 hmmInformation.annotations = null;
763 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
765 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
766 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
772 * sequence to either add or remove from group
774 * flag passed to delete/addSequence to indicate if group properties
775 * should be recalculated
777 public void addOrRemove(SequenceI s, boolean recalc)
779 synchronized (sequences)
781 if (sequences.contains(s))
783 deleteSequence(s, recalc);
787 addSequence(s, recalc);
798 * true means recalculate conservation
800 public void deleteSequence(SequenceI s, boolean recalc)
802 synchronized (sequences)
805 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
806 sequences.size() + 1, sequences.size());
810 recalcConservation();
818 * @return the first column selected by this group. Runs from 0<=i<N_cols
821 public int getStartRes()
828 * @return the groups last selected column. Runs from 0<=i<N_cols
831 public int getEndRes()
837 * Set the first column selected by this group. Runs from 0<=i<N_cols
841 public void setStartRes(int newStart)
843 int before = startRes;
844 startRes = Math.max(0, newStart); // sanity check for negative start column
846 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
851 * Set the groups last selected column. Runs from 0<=i<N_cols
855 public void setEndRes(int i)
859 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
863 * @return number of sequences in group
867 return sequences.size();
872 * @return the ith sequence
874 public SequenceI getSequenceAt(int i)
876 return sequences.get(i);
883 public void setColourText(boolean state)
891 * @return DOCUMENT ME!
893 public boolean getColourText()
904 public void setDisplayText(boolean state)
912 * @return DOCUMENT ME!
914 public boolean getDisplayText()
925 public void setDisplayBoxes(boolean state)
927 displayBoxes = state;
933 * @return DOCUMENT ME!
935 public boolean getDisplayBoxes()
941 * computes the width of current set of sequences and returns it
943 * @return DOCUMENT ME!
946 public int getWidth()
948 synchronized (sequences)
950 // MC This needs to get reset when characters are inserted and deleted
951 boolean first = true;
952 for (SequenceI seq : sequences)
954 if (first || seq.getLength() > width)
956 width = seq.getLength();
970 public void setOutlineColour(Color c)
978 * @return DOCUMENT ME!
980 public Color getOutlineColour()
982 return outlineColour;
987 * returns the sequences in the group ordered by the ordering given by al.
988 * this used to return an array with null entries regardless, new behaviour is
989 * below. TODO: verify that this does not affect use in applet or application
993 * @return SequenceI[] intersection of sequences in group with al, ordered by
994 * al, or null if group does not intersect with al
996 public SequenceI[] getSequencesInOrder(AlignmentI al)
998 return getSequencesInOrder(al, true);
1002 * return an array representing the intersection of the group with al,
1003 * optionally returning an array the size of al.getHeight() where nulls mark
1004 * the non-intersected sequences
1008 * @return null or array
1010 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
1012 synchronized (sequences)
1014 int sSize = sequences.size();
1015 int alHeight = al.getHeight();
1017 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
1020 for (int i = 0; i < alHeight && index < sSize; i++)
1022 if (sequences.contains(al.getSequenceAt(i)))
1024 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1036 if (index < seqs.length)
1038 SequenceI[] dummy = seqs;
1039 seqs = new SequenceI[index];
1040 while (--index >= 0)
1042 seqs[index] = dummy[index];
1043 dummy[index] = null;
1051 * @return the idColour
1053 public Color getIdColour()
1060 * the idColour to set
1062 public void setIdColour(Color idColour)
1064 this.idColour = idColour;
1068 * @return the representative sequence for this group
1071 public SequenceI getSeqrep()
1077 * set the representative sequence for this group. Note - this affects the
1078 * interpretation of the Hidereps attribute.
1081 * the seqrep to set (null means no sequence representative)
1084 public void setSeqrep(SequenceI seqrep)
1086 this.seqrep = seqrep;
1091 * @return true if group has a sequence representative
1094 public boolean hasSeqrep()
1096 return seqrep != null;
1100 * set visibility of sequences covered by (if no sequence representative is
1101 * defined) or represented by this group.
1105 public void setHidereps(boolean visibility)
1107 hidereps = visibility;
1112 * @return true if sequences represented (or covered) by this group should be
1115 public boolean isHidereps()
1121 * set intended visibility of columns covered by this group
1125 public void setHideCols(boolean visibility)
1127 hidecols = visibility;
1132 * @return true if columns covered by group should be hidden
1134 public boolean isHideCols()
1140 * create a new sequence group from the intersection of this group with an
1141 * alignment Hashtable of hidden representatives
1147 * @return new group containing sequences common to this group and alignment
1149 public SequenceGroup intersect(AlignmentI alignment,
1150 Map<SequenceI, SequenceCollectionI> map)
1152 SequenceGroup sgroup = new SequenceGroup(this);
1153 SequenceI[] insect = getSequencesInOrder(alignment);
1154 sgroup.sequences = new ArrayList<>();
1155 for (int s = 0; insect != null && s < insect.length; s++)
1157 if (map == null || map.containsKey(insect[s]))
1159 sgroup.sequences.add(insect[s]);
1166 * @return the showUnconserved
1168 public boolean getShowNonconserved()
1170 return showNonconserved;
1174 * @param showNonconserved
1175 * the showUnconserved to set
1177 public void setShowNonconserved(boolean displayNonconserved)
1179 this.showNonconserved = displayNonconserved;
1183 * set this alignmentAnnotation object as the one used to render consensus
1188 public void setConsensus(AlignmentAnnotation aan)
1190 if (consensus == null)
1198 * @return automatically calculated consensus row note: the row is a stub if a
1199 * consensus calculation has not yet been performed on the group
1201 public AlignmentAnnotation getConsensus()
1203 // TODO get or calculate and get consensus annotation row for this group
1204 int aWidth = this.getWidth();
1212 if (consensus == null)
1214 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1215 100f, AlignmentAnnotation.BAR_GRAPH);
1216 consensus.hasText = true;
1217 consensus.autoCalculated = true;
1218 consensus.groupRef = this;
1219 consensus.label = "Consensus for " + getName();
1220 consensus.description = "Percent Identity";
1226 * Creates the Hidden Markov Model annotation for this group
1228 void createInformationAnnotation()
1230 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1231 6.25f, AlignmentAnnotation.BAR_GRAPH);
1232 hmmInformation.hasText = true;
1233 hmmInformation.autoCalculated = false;
1234 hmmInformation.groupRef = this;
1235 hmmInformation.label = getName();
1236 hmmInformation.description = MessageManager
1237 .getString("label.information_description");
1238 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1242 * set this alignmentAnnotation object as the one used to render consensus
1247 public void setConservationRow(AlignmentAnnotation aan)
1249 if (conservation == null)
1256 * get the conservation annotation row for this group
1258 * @return autoCalculated annotation row
1260 public AlignmentAnnotation getConservationRow()
1262 if (conservation == null)
1264 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1265 11f, AlignmentAnnotation.BAR_GRAPH);
1268 conservation.hasText = true;
1269 conservation.autoCalculated = true;
1270 conservation.groupRef = this;
1271 conservation.label = "Conservation for " + getName();
1272 conservation.description = "Conservation for group " + getName()
1273 + " less than " + consPercGaps + "% gaps";
1274 return conservation;
1279 * @return true if annotation rows have been instantiated for this group
1281 public boolean hasAnnotationRows()
1283 return consensus != null || conservation != null;
1286 public SequenceI getConsensusSeq()
1289 StringBuffer seqs = new StringBuffer();
1290 for (int i = 0; i < consensus.annotations.length; i++)
1292 if (consensus.annotations[i] != null)
1294 String desc = consensus.annotations[i].description;
1295 if (desc.length() > 1 && desc.charAt(0) == '[')
1297 seqs.append(desc.charAt(1));
1301 seqs.append(consensus.annotations[i].displayCharacter);
1306 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1308 sq.setDescription("Percentage Identity Consensus "
1309 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1313 public void setIgnoreGapsConsensus(boolean state)
1315 if (this.ignoreGapsInConsensus != state && consensus != null)
1317 ignoreGapsInConsensus = state;
1318 recalcConservation();
1320 ignoreGapsInConsensus = state;
1323 public boolean getIgnoreGapsConsensus()
1325 return ignoreGapsInConsensus;
1328 public void setIgnoreBelowBackground(boolean state)
1330 hmmIgnoreBelowBackground = state;
1333 public boolean isIgnoreBelowBackground()
1335 return hmmIgnoreBelowBackground;
1338 public void setInfoLetterHeight(boolean state)
1340 hmmUseInfoLetterHeight = state;
1343 public boolean isUseInfoLetterHeight()
1345 return hmmUseInfoLetterHeight;
1349 * @param showSequenceLogo
1350 * indicates if a sequence logo is shown for consensus annotation
1352 public void setshowSequenceLogo(boolean showSequenceLogo)
1354 // TODO: decouple calculation from settings update
1355 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1357 this.showSequenceLogo = showSequenceLogo;
1358 recalcConservation();
1360 this.showSequenceLogo = showSequenceLogo;
1365 * @param showConsHist
1366 * flag indicating if the consensus histogram for this group should
1369 public void setShowConsensusHistogram(boolean showConsHist)
1372 if (showConsensusHistogram != showConsHist && consensus != null)
1374 this.showConsensusHistogram = showConsHist;
1375 recalcConservation();
1377 this.showConsensusHistogram = showConsHist;
1381 * @return the showConsensusHistogram
1383 public boolean isShowConsensusHistogram()
1385 return showConsensusHistogram;
1389 * set flag indicating if logo should be normalised when rendered
1393 public void setNormaliseSequenceLogo(boolean norm)
1395 normaliseSequenceLogo = norm;
1398 public boolean isNormaliseSequenceLogo()
1400 return normaliseSequenceLogo;
1405 * returns a new array with all annotation involving this group
1407 public AlignmentAnnotation[] getAlignmentAnnotation()
1409 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1411 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1412 synchronized (sequences)
1414 for (SequenceI seq : sequences)
1416 AlignmentAnnotation[] aa = seq.getAnnotation();
1419 for (AlignmentAnnotation al : aa)
1421 if (al.groupRef == this)
1428 if (consensus != null)
1430 annot.add(consensus);
1432 if (conservation != null)
1434 annot.add(conservation);
1437 return annot.toArray(new AlignmentAnnotation[0]);
1441 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1443 return AlignmentAnnotation.findAnnotation(
1444 Arrays.asList(getAlignmentAnnotation()), calcId);
1448 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1449 String calcId, String label)
1451 return AlignmentAnnotation.findAnnotations(
1452 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1456 * Answer true if any annotation matches the calcId passed in (if not null).
1461 public boolean hasAnnotation(String calcId)
1463 return AlignmentAnnotation
1464 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1468 * Remove all sequences from the group (leaving other properties unchanged).
1472 synchronized (sequences)
1474 int before = sequences.size();
1476 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1482 * Sets the alignment or group context for this group, and whether it is
1483 * defined as a group
1486 * the context for the group
1488 * whether the group is defined on the alignment or is just a
1490 * @throws IllegalArgumentException
1491 * if setting the context would result in a circular reference chain
1493 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1496 this.isDefined = defined;
1500 * Sets the alignment or group context for this group
1503 * the context for the group
1504 * @throws IllegalArgumentException
1505 * if setting the context would result in a circular reference chain
1507 public void setContext(AnnotatedCollectionI ctx)
1509 AnnotatedCollectionI ref = ctx;
1512 if (ref == this || ref.getContext() == ctx)
1514 throw new IllegalArgumentException(
1515 "Circular reference in SequenceGroup.context");
1517 ref = ref.getContext();
1525 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1528 public AnnotatedCollectionI getContext()
1533 public boolean isDefined()
1538 public void setColourScheme(ColourSchemeI scheme)
1542 cs = new ResidueShader();
1544 cs.setColourScheme(scheme);
1547 public void setGroupColourScheme(ResidueShaderI scheme)
1552 public ColourSchemeI getColourScheme()
1554 return cs == null ? null : cs.getColourScheme();
1557 public ResidueShaderI getGroupColourScheme()
1563 public boolean isNucleotide()
1565 if (context != null)
1567 return context.isNucleotide();
1574 * @return true if seq is a member of the group
1577 public boolean contains(SequenceI seq1)
1579 return sequences.contains(seq1);
1585 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1587 public boolean contains(SequenceI seq, int apos)
1589 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1592 public boolean isShowInformationHistogram()
1594 return hmmShowHistogram;
1597 public void setShowInformationHistogram(boolean state)
1599 if (hmmShowHistogram != state && hmmInformation != null)
1601 this.hmmShowHistogram = state;
1602 // recalcConservation(); TODO don't know what to do here next
1604 this.hmmShowHistogram = state;
1607 public boolean isShowHMMSequenceLogo()
1609 return hmmShowSequenceLogo;
1612 public void setShowHMMSequenceLogo(boolean state)
1614 hmmShowSequenceLogo = state;
1617 public boolean isNormaliseHMMSequenceLogo()
1619 return hmmNormaliseSequenceLogo;
1622 public void setNormaliseHMMSequenceLogo(boolean state)
1624 hmmNormaliseSequenceLogo = state;
1627 public ProfilesI getConsensusData()
1629 return consensusProfiles;
1632 public ProfilesI getHmmProfiles()
1637 public void setHmmProfiles(ProfilesI hmmProfiles)
1639 this.hmmProfiles = hmmProfiles;
1643 public List<SequenceI> getHmmSequences()
1645 List<SequenceI> result = new ArrayList<>();
1646 for (int i = 0; i < sequences.size(); i++)
1648 SequenceI seq = sequences.get(i);
1649 if (seq.hasHMMProfile())