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];
301 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
302 if (seqs[ipos] != null)
304 seqs[ipos].setDescription(seq.getDescription());
305 seqs[ipos].setDBRefs(seq.getDBRefs());
306 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
307 if (seq.getDatasetSequence() != null)
309 seqs[ipos].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; pos < alann.length; 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 seqs[ipos].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 positions
845 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
852 * Set the groups last selected column. Runs from 0<=i<N_cols
856 public void setEndRes(int i)
860 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
864 * @return number of sequences in group
868 return sequences.size();
873 * @return the ith sequence
875 public SequenceI getSequenceAt(int i)
877 return sequences.get(i);
884 public void setColourText(boolean state)
892 * @return DOCUMENT ME!
894 public boolean getColourText()
905 public void setDisplayText(boolean state)
913 * @return DOCUMENT ME!
915 public boolean getDisplayText()
926 public void setDisplayBoxes(boolean state)
928 displayBoxes = state;
934 * @return DOCUMENT ME!
936 public boolean getDisplayBoxes()
942 * computes the width of current set of sequences and returns it
944 * @return DOCUMENT ME!
947 public int getWidth()
949 synchronized (sequences)
951 // MC This needs to get reset when characters are inserted and deleted
952 boolean first = true;
953 for (SequenceI seq : sequences)
955 if (first || seq.getLength() > width)
957 width = seq.getLength();
971 public void setOutlineColour(Color c)
979 * @return DOCUMENT ME!
981 public Color getOutlineColour()
983 return outlineColour;
988 * returns the sequences in the group ordered by the ordering given by al.
989 * this used to return an array with null entries regardless, new behaviour is
990 * below. TODO: verify that this does not affect use in applet or application
994 * @return SequenceI[] intersection of sequences in group with al, ordered by
995 * al, or null if group does not intersect with al
997 public SequenceI[] getSequencesInOrder(AlignmentI al)
999 return getSequencesInOrder(al, true);
1003 * return an array representing the intersection of the group with al,
1004 * optionally returning an array the size of al.getHeight() where nulls mark
1005 * the non-intersected sequences
1009 * @return null or array
1011 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
1013 synchronized (sequences)
1015 int sSize = sequences.size();
1016 int alHeight = al.getHeight();
1018 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
1021 for (int i = 0; i < alHeight && index < sSize; i++)
1023 if (sequences.contains(al.getSequenceAt(i)))
1025 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1037 if (index < seqs.length)
1039 SequenceI[] dummy = seqs;
1040 seqs = new SequenceI[index];
1041 while (--index >= 0)
1043 seqs[index] = dummy[index];
1044 dummy[index] = null;
1052 * @return the idColour
1054 public Color getIdColour()
1061 * the idColour to set
1063 public void setIdColour(Color idColour)
1065 this.idColour = idColour;
1069 * @return the representative sequence for this group
1072 public SequenceI getSeqrep()
1078 * set the representative sequence for this group. Note - this affects the
1079 * interpretation of the Hidereps attribute.
1082 * the seqrep to set (null means no sequence representative)
1085 public void setSeqrep(SequenceI seqrep)
1087 this.seqrep = seqrep;
1092 * @return true if group has a sequence representative
1095 public boolean hasSeqrep()
1097 return seqrep != null;
1101 * set visibility of sequences covered by (if no sequence representative is
1102 * defined) or represented by this group.
1106 public void setHidereps(boolean visibility)
1108 hidereps = visibility;
1113 * @return true if sequences represented (or covered) by this group should be
1116 public boolean isHidereps()
1122 * set intended visibility of columns covered by this group
1126 public void setHideCols(boolean visibility)
1128 hidecols = visibility;
1133 * @return true if columns covered by group should be hidden
1135 public boolean isHideCols()
1141 * create a new sequence group from the intersection of this group with an
1142 * alignment Hashtable of hidden representatives
1148 * @return new group containing sequences common to this group and alignment
1150 public SequenceGroup intersect(AlignmentI alignment,
1151 Map<SequenceI, SequenceCollectionI> map)
1153 SequenceGroup sgroup = new SequenceGroup(this);
1154 SequenceI[] insect = getSequencesInOrder(alignment);
1155 sgroup.sequences = new ArrayList<>();
1156 for (int s = 0; insect != null && s < insect.length; s++)
1158 if (map == null || map.containsKey(insect[s]))
1160 sgroup.sequences.add(insect[s]);
1167 * @return the showUnconserved
1169 public boolean getShowNonconserved()
1171 return showNonconserved;
1175 * @param showNonconserved
1176 * the showUnconserved to set
1178 public void setShowNonconserved(boolean displayNonconserved)
1180 this.showNonconserved = displayNonconserved;
1184 * set this alignmentAnnotation object as the one used to render consensus
1189 public void setConsensus(AlignmentAnnotation aan)
1191 if (consensus == null)
1199 * @return automatically calculated consensus row note: the row is a stub if a
1200 * consensus calculation has not yet been performed on the group
1202 public AlignmentAnnotation getConsensus()
1204 // TODO get or calculate and get consensus annotation row for this group
1205 int aWidth = this.getWidth();
1213 if (consensus == null)
1215 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1216 100f, AlignmentAnnotation.BAR_GRAPH);
1217 consensus.hasText = true;
1218 consensus.autoCalculated = true;
1219 consensus.groupRef = this;
1220 consensus.label = "Consensus for " + getName();
1221 consensus.description = "Percent Identity";
1227 * Creates the Hidden Markov Model annotation for this group
1229 void createInformationAnnotation()
1231 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1232 6.25f, AlignmentAnnotation.BAR_GRAPH);
1233 hmmInformation.hasText = true;
1234 hmmInformation.autoCalculated = false;
1235 hmmInformation.groupRef = this;
1236 hmmInformation.label = getName();
1237 hmmInformation.description = MessageManager
1238 .getString("label.information_description");
1239 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1243 * set this alignmentAnnotation object as the one used to render consensus
1248 public void setConservationRow(AlignmentAnnotation aan)
1250 if (conservation == null)
1257 * get the conservation annotation row for this group
1259 * @return autoCalculated annotation row
1261 public AlignmentAnnotation getConservationRow()
1263 if (conservation == null)
1265 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1266 11f, AlignmentAnnotation.BAR_GRAPH);
1269 conservation.hasText = true;
1270 conservation.autoCalculated = true;
1271 conservation.groupRef = this;
1272 conservation.label = "Conservation for " + getName();
1273 conservation.description = "Conservation for group " + getName()
1274 + " less than " + consPercGaps + "% gaps";
1275 return conservation;
1280 * @return true if annotation rows have been instantiated for this group
1282 public boolean hasAnnotationRows()
1284 return consensus != null || conservation != null;
1287 public SequenceI getConsensusSeq()
1290 StringBuffer seqs = new StringBuffer();
1291 for (int i = 0; i < consensus.annotations.length; i++)
1293 if (consensus.annotations[i] != null)
1295 String desc = consensus.annotations[i].description;
1296 if (desc.length() > 1 && desc.charAt(0) == '[')
1298 seqs.append(desc.charAt(1));
1302 seqs.append(consensus.annotations[i].displayCharacter);
1307 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1309 sq.setDescription("Percentage Identity Consensus "
1310 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1314 public void setIgnoreGapsConsensus(boolean state)
1316 if (this.ignoreGapsInConsensus != state && consensus != null)
1318 ignoreGapsInConsensus = state;
1319 recalcConservation();
1321 ignoreGapsInConsensus = state;
1324 public boolean getIgnoreGapsConsensus()
1326 return ignoreGapsInConsensus;
1329 public void setIgnoreBelowBackground(boolean state)
1331 hmmIgnoreBelowBackground = state;
1334 public boolean isIgnoreBelowBackground()
1336 return hmmIgnoreBelowBackground;
1339 public void setInfoLetterHeight(boolean state)
1341 hmmUseInfoLetterHeight = state;
1344 public boolean isUseInfoLetterHeight()
1346 return hmmUseInfoLetterHeight;
1350 * @param showSequenceLogo
1351 * indicates if a sequence logo is shown for consensus annotation
1353 public void setshowSequenceLogo(boolean showSequenceLogo)
1355 // TODO: decouple calculation from settings update
1356 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1358 this.showSequenceLogo = showSequenceLogo;
1359 recalcConservation();
1361 this.showSequenceLogo = showSequenceLogo;
1366 * @param showConsHist
1367 * flag indicating if the consensus histogram for this group should
1370 public void setShowConsensusHistogram(boolean showConsHist)
1373 if (showConsensusHistogram != showConsHist && consensus != null)
1375 this.showConsensusHistogram = showConsHist;
1376 recalcConservation();
1378 this.showConsensusHistogram = showConsHist;
1382 * @return the showConsensusHistogram
1384 public boolean isShowConsensusHistogram()
1386 return showConsensusHistogram;
1390 * set flag indicating if logo should be normalised when rendered
1394 public void setNormaliseSequenceLogo(boolean norm)
1396 normaliseSequenceLogo = norm;
1399 public boolean isNormaliseSequenceLogo()
1401 return normaliseSequenceLogo;
1406 * returns a new array with all annotation involving this group
1408 public AlignmentAnnotation[] getAlignmentAnnotation()
1410 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1412 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1413 synchronized (sequences)
1415 for (SequenceI seq : sequences)
1417 AlignmentAnnotation[] aa = seq.getAnnotation();
1420 for (AlignmentAnnotation al : aa)
1422 if (al.groupRef == this)
1429 if (consensus != null)
1431 annot.add(consensus);
1433 if (conservation != null)
1435 annot.add(conservation);
1438 return annot.toArray(new AlignmentAnnotation[0]);
1442 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1444 return AlignmentAnnotation.findAnnotation(
1445 Arrays.asList(getAlignmentAnnotation()), calcId);
1449 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1450 String calcId, String label)
1452 return AlignmentAnnotation.findAnnotations(
1453 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1457 * Answer true if any annotation matches the calcId passed in (if not null).
1462 public boolean hasAnnotation(String calcId)
1464 return AlignmentAnnotation
1465 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1469 * Remove all sequences from the group (leaving other properties unchanged).
1473 synchronized (sequences)
1475 int before = sequences.size();
1477 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1483 * Sets the alignment or group context for this group, and whether it is
1484 * defined as a group
1487 * the context for the group
1489 * whether the group is defined on the alignment or is just a
1491 * @throws IllegalArgumentException
1492 * if setting the context would result in a circular reference chain
1494 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1497 this.isDefined = defined;
1501 * Sets the alignment or group context for this group
1504 * the context for the group
1505 * @throws IllegalArgumentException
1506 * if setting the context would result in a circular reference chain
1508 public void setContext(AnnotatedCollectionI ctx)
1510 AnnotatedCollectionI ref = ctx;
1513 if (ref == this || ref.getContext() == ctx)
1515 throw new IllegalArgumentException(
1516 "Circular reference in SequenceGroup.context");
1518 ref = ref.getContext();
1526 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1529 public AnnotatedCollectionI getContext()
1534 public boolean isDefined()
1539 public void setColourScheme(ColourSchemeI scheme)
1543 cs = new ResidueShader();
1545 cs.setColourScheme(scheme);
1548 public void setGroupColourScheme(ResidueShaderI scheme)
1553 public ColourSchemeI getColourScheme()
1555 return cs == null ? null : cs.getColourScheme();
1558 public ResidueShaderI getGroupColourScheme()
1564 public boolean isNucleotide()
1566 if (context != null)
1568 return context.isNucleotide();
1575 * @return true if seq is a member of the group
1578 public boolean contains(SequenceI seq1)
1580 return sequences.contains(seq1);
1586 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1588 public boolean contains(SequenceI seq, int apos)
1590 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1593 public boolean isShowInformationHistogram()
1595 return hmmShowHistogram;
1598 public void setShowInformationHistogram(boolean state)
1600 if (hmmShowHistogram != state && hmmInformation != null)
1602 this.hmmShowHistogram = state;
1603 // recalcConservation(); TODO don't know what to do here next
1605 this.hmmShowHistogram = state;
1608 public boolean isShowHMMSequenceLogo()
1610 return hmmShowSequenceLogo;
1613 public void setShowHMMSequenceLogo(boolean state)
1615 hmmShowSequenceLogo = state;
1618 public boolean isNormaliseHMMSequenceLogo()
1620 return hmmNormaliseSequenceLogo;
1623 public void setNormaliseHMMSequenceLogo(boolean state)
1625 hmmNormaliseSequenceLogo = state;
1628 public ProfilesI getConsensusData()
1630 return consensusProfiles;
1633 public ProfilesI getHmmProfiles()
1638 public void setHmmProfiles(ProfilesI hmmProfiles)
1640 this.hmmProfiles = hmmProfiles;
1644 public List<SequenceI> getHmmSequences()
1646 List<SequenceI> result = new ArrayList<>();
1647 for (int i = 0; i < sequences.size(); i++)
1649 SequenceI seq = sequences.get(i);
1650 if (seq.hasHMMProfile())