2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.renderer.ResidueShader;
26 import jalview.renderer.ResidueShaderI;
27 import jalview.schemes.ColourSchemeI;
28 import jalview.util.MessageManager;
29 import jalview.workers.InformationThread;
31 import java.awt.Color;
32 import java.beans.PropertyChangeListener;
33 import java.beans.PropertyChangeSupport;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
40 * Collects a set contiguous ranges on a set of sequences
45 public class SequenceGroup implements AnnotatedCollectionI
47 // TODO ideally this event notification functionality should be separated into
48 // a subclass of ViewportProperties similarly to ViewportRanges.
49 // Done here as a quick fix for JAL-2665
50 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
52 private String groupName;
54 private String description;
56 private AnnotatedCollectionI context;
58 private Conservation conservationData;
60 private ProfilesI consensusProfiles;
62 private ProfilesI hmmProfiles;
64 private boolean displayBoxes = true;
66 private boolean displayText = true;
68 private boolean colourText = false;
71 * true if the group is defined as a group on the alignment, false if it is
74 private boolean isDefined;
77 * after Olivier's non-conserved only character display
79 private boolean showNonconserved;
82 * sequences in the group
84 private List<SequenceI> sequences = new ArrayList<>();
87 * representative sequence for this group (if any)
89 private SequenceI seqrep;
92 * HMM consensus sequence for group (if any)
94 private SequenceI hmmConsensus;
96 private int width = -1;
99 * colour scheme applied to group if any
101 public ResidueShaderI cs;
103 // start column (base 0)
104 private int startRes;
106 // end column (base 0)
109 public Color outlineColour = Color.black;
111 public Color idColour;
113 public int thresholdTextColour;
115 public Color textColour = Color.black;
117 public Color textColour2 = Color.white;
120 * properties for consensus annotation
122 private boolean ignoreGapsInConsensus = true;
124 private boolean showSequenceLogo;
126 private boolean normaliseSequenceLogo;
128 private boolean showConsensusHistogram;
131 * properties for HMM information annotation
133 private boolean hmmIgnoreBelowBackground = true;
135 private boolean hmmUseInfoLetterHeight;
137 private boolean showHMMSequenceLogo;
139 private boolean hmmNormaliseSequenceLogo;
141 private boolean hmmShowHistogram;
144 * visibility of rows or represented rows covered by group
146 private boolean hidereps;
149 * visibility of columns intersecting this group
151 private boolean hidecols;
153 private AlignmentAnnotation consensus;
155 private AlignmentAnnotation conservation;
157 private AlignmentAnnotation hmmInformation;
160 * Constructor, assigning a generated default name of "JGroup:" with object
163 public SequenceGroup()
165 groupName = "JGroup:" + this.hashCode();
166 cs = new ResidueShader();
170 * Creates a new SequenceGroup object.
175 * @param displayBoxes
179 * first column of group
181 * last column of group
183 public SequenceGroup(List<SequenceI> sequences, String groupName,
184 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
185 boolean colourText, int start, int end)
188 this.sequences = sequences;
189 this.groupName = groupName;
190 this.displayBoxes = displayBoxes;
191 this.displayText = displayText;
192 this.colourText = colourText;
193 this.cs = new ResidueShader(scheme);
196 recalcConservation();
204 public SequenceGroup(SequenceGroup seqsel)
209 sequences = new ArrayList<>();
210 sequences.addAll(seqsel.sequences);
211 if (seqsel.groupName != null)
213 groupName = new String(seqsel.groupName);
215 displayBoxes = seqsel.displayBoxes;
216 displayText = seqsel.displayText;
217 colourText = seqsel.colourText;
218 startRes = seqsel.startRes;
219 endRes = seqsel.endRes;
220 cs = new ResidueShader((ResidueShader) seqsel.cs);
221 if (seqsel.description != null)
223 description = new String(seqsel.description);
225 hidecols = seqsel.hidecols;
226 hidereps = seqsel.hidereps;
227 showNonconserved = seqsel.showNonconserved;
228 showSequenceLogo = seqsel.showSequenceLogo;
229 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
230 showConsensusHistogram = seqsel.showConsensusHistogram;
231 showHMMSequenceLogo = seqsel.showHMMSequenceLogo;
232 hmmNormaliseSequenceLogo = seqsel.hmmNormaliseSequenceLogo;
233 hmmShowHistogram = seqsel.hmmShowHistogram;
234 idColour = seqsel.idColour;
235 outlineColour = seqsel.outlineColour;
236 seqrep = seqsel.seqrep;
237 textColour = seqsel.textColour;
238 textColour2 = seqsel.textColour2;
239 thresholdTextColour = seqsel.thresholdTextColour;
240 width = seqsel.width;
241 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
242 hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
243 hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
244 if (seqsel.conservationData != null)
246 recalcConservation(); // safer than
247 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
252 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
255 public void addPropertyChangeListener(PropertyChangeListener listener)
257 changeSupport.addPropertyChangeListener(listener);
260 public void removePropertyChangeListener(PropertyChangeListener listener)
262 changeSupport.removePropertyChangeListener(listener);
265 public boolean isShowSequenceLogo()
267 return showSequenceLogo;
270 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
272 int iSize = sequences.size();
273 SequenceI[] seqs = new SequenceI[iSize];
274 SequenceI[] inorder = getSequencesInOrder(align);
276 for (int i = 0, ipos = 0; i < inorder.length; i++)
278 SequenceI seq = inorder[i];
280 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
281 if (seqs[ipos] != null)
283 seqs[ipos].setDescription(seq.getDescription());
284 seqs[ipos].setDBRefs(seq.getDBRefs());
285 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
286 seqs[ipos].setIsHMMConsensusSequence(seq.isHMMConsensusSequence());
287 if (seq.getDatasetSequence() != null)
289 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
292 if (seq.getAnnotation() != null)
294 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
295 // Only copy annotation that is either a score or referenced by the
296 // alignment's annotation vector
297 for (int a = 0; a < seq.getAnnotation().length; a++)
299 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
302 boolean found = false;
303 for (int pos = 0; pos < alann.length; pos++)
305 if (alann[pos] == tocopy)
316 AlignmentAnnotation newannot = new AlignmentAnnotation(
317 seq.getAnnotation()[a]);
318 newannot.restrict(startRes, endRes);
319 newannot.setSequenceRef(seqs[ipos]);
320 newannot.adjustForAlignment();
321 seqs[ipos].addAlignmentAnnotation(newannot);
331 if (iSize != inorder.length)
333 SequenceI[] nseqs = new SequenceI[iSize];
334 System.arraycopy(seqs, 0, nseqs, 0, iSize);
342 * If sequence ends in gaps, the end residue can be correctly calculated here
348 public int findEndRes(SequenceI seq)
353 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
355 ch = seq.getCharAt(j);
356 if (!jalview.util.Comparison.isGap((ch)))
364 eres += seq.getStart() - 1;
371 public List<SequenceI> getSequences()
377 public List<SequenceI> getSequences(
378 Map<SequenceI, SequenceCollectionI> hiddenReps)
380 if (hiddenReps == null)
382 // TODO: need a synchronizedCollection here ?
387 List<SequenceI> allSequences = new ArrayList<>();
388 for (SequenceI seq : sequences)
390 allSequences.add(seq);
391 if (hiddenReps.containsKey(seq))
393 SequenceCollectionI hsg = hiddenReps.get(seq);
394 for (SequenceI seq2 : hsg.getSequences())
396 if (seq2 != seq && !allSequences.contains(seq2))
398 allSequences.add(seq2);
408 public SequenceI[] getSequencesAsArray(
409 Map<SequenceI, SequenceCollectionI> map)
411 List<SequenceI> tmp = getSequences(map);
416 return tmp.toArray(new SequenceI[tmp.size()]);
425 * @return DOCUMENT ME!
427 public boolean adjustForRemoveLeft(int col)
429 // return value is true if the group still exists
432 startRes = startRes - col;
437 endRes = endRes - col;
439 if (startRes > endRes)
446 // must delete this group!!
459 * @return DOCUMENT ME!
461 public boolean adjustForRemoveRight(int col)
480 * @return DOCUMENT ME!
482 public String getName()
487 public String getDescription()
498 public void setName(String name)
501 // TODO: URGENT: update dependent objects (annotation row)
504 public void setDescription(String desc)
512 * @return DOCUMENT ME!
514 public Conservation getConservation()
516 return conservationData;
525 public void setConservation(Conservation c)
527 conservationData = c;
531 * Add s to this sequence group. If aligment sequence is already contained in
532 * group, it will not be added again, but recalculation may happen if the flag
536 * alignment sequence to be added
538 * true means Group's conservation should be recalculated
540 public void addSequence(SequenceI s, boolean recalc)
542 synchronized (sequences)
544 if (s != null && !sequences.contains(s))
547 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
548 sequences.size() - 1, sequences.size());
553 recalcConservation();
559 * Max Gaps Threshold (percent) for performing a conservation calculation
561 private int consPercGaps = 25;
564 * @return Max Gaps Threshold for performing a conservation calculation
566 public int getConsPercGaps()
572 * set Max Gaps Threshold (percent) for performing a conservation calculation
574 * @param consPercGaps
576 public void setConsPercGaps(int consPercGaps)
578 this.consPercGaps = consPercGaps;
582 * calculate residue conservation and colourschemes for group - but only if
583 * necessary. returns true if the calculation resulted in a visible change to
586 public boolean recalcConservation()
588 return recalcAnnotations(false);
592 * Recalculates column consensus, conservation, and HMM annotation for the
593 * group (as applicable). Returns true if the calculation resulted in a
594 * visible change to group.
597 * when set, colourschemes for this group are not refreshed after
600 public boolean recalcAnnotations(boolean defer)
602 if (cs == null && consensus == null && conservation == null
603 && hmmInformation == null)
607 // TODO: try harder to detect changes in state in order to minimise
608 // recalculation effort
612 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
613 endRes + 1, showSequenceLogo);
614 if (hmmInformation != null)
616 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
618 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
619 (endRes + 1) - startRes, startRes, endRes + 1,
620 showHMMSequenceLogo, hmmIgnoreBelowBackground,
621 hmmUseInfoLetterHeight);
622 _updateInformationRow(info, sequences.size());
625 if (consensus != null)
627 _updateConsensusRow(cnsns, sequences.size());
632 cs.setConsensus(cnsns);
636 if ((conservation != null)
637 || (cs != null && cs.conservationApplied()))
639 Conservation c = new Conservation(groupName, sequences, startRes,
642 c.verdict(false, consPercGaps);
643 if (conservation != null)
645 _updateConservationRow(c);
649 if (cs.conservationApplied())
651 cs.setConservation(c);
654 // eager update - will cause a refresh of overview regardless
657 if (cs != null && !defer)
659 // TODO: JAL-2034 should cs.alignmentChanged modify return state
660 cs.alignmentChanged(context != null ? context : this, null);
667 } catch (java.lang.OutOfMemoryError err)
670 System.out.println("Out of memory loading groups: " + err);
675 private void _updateConservationRow(Conservation c)
677 if (conservation == null)
682 conservation.label = "Conservation for " + getName();
683 conservation.description = "Conservation for group " + getName()
684 + " less than " + consPercGaps + "% gaps";
685 // preserve width if already set
686 int aWidth = (conservation.annotations != null)
687 ? (endRes < conservation.annotations.length
688 ? conservation.annotations.length
691 conservation.annotations = null;
692 conservation.annotations = new Annotation[aWidth]; // should be alignment
694 c.completeAnnotations(conservation, null, startRes, endRes + 1);
697 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
699 if (consensus == null)
703 consensus.label = "Consensus for " + getName();
704 consensus.description = "Percent Identity";
705 consensusProfiles = cnsns;
706 // preserve width if already set
707 int aWidth = (consensus.annotations != null)
708 ? (endRes < consensus.annotations.length
709 ? consensus.annotations.length
712 consensus.annotations = null;
713 consensus.annotations = new Annotation[aWidth]; // should be alignment width
715 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
716 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
719 // ignoreGapsInConsensusCalculation);
723 * Recalculates the information content on the HMM annotation.
728 private void _updateInformationRow(ProfilesI cnsns, long nseq)
730 if (hmmInformation == null)
732 createInformationAnnotation();
734 hmmInformation.description = MessageManager
735 .getString("label.information_description");
736 setHmmProfiles(cnsns);
737 // preserve width if already set
738 int aWidth = (hmmInformation.annotations != null)
739 ? (endRes < hmmInformation.annotations.length
740 ? hmmInformation.annotations.length : endRes + 1)
742 hmmInformation.annotations = null;
743 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
745 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
746 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
747 endRes + 1, nseq, 0f);
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";
1204 * Creates the Hidden Markov Model annotation for this group
1206 void createInformationAnnotation()
1208 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1209 6.25f, AlignmentAnnotation.BAR_GRAPH);
1210 hmmInformation.hasText = true;
1211 hmmInformation.autoCalculated = false;
1212 hmmInformation.groupRef = this;
1213 hmmInformation.label = getName();
1214 hmmInformation.description = MessageManager
1215 .getString("label.information_description");
1216 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1220 * set this alignmentAnnotation object as the one used to render consensus
1225 public void setConservationRow(AlignmentAnnotation aan)
1227 if (conservation == null)
1234 * get the conservation annotation row for this group
1236 * @return autoCalculated annotation row
1238 public AlignmentAnnotation getConservationRow()
1240 if (conservation == null)
1242 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1243 11f, AlignmentAnnotation.BAR_GRAPH);
1246 conservation.hasText = true;
1247 conservation.autoCalculated = true;
1248 conservation.groupRef = this;
1249 conservation.label = "Conservation for " + getName();
1250 conservation.description = "Conservation for group " + getName()
1251 + " less than " + consPercGaps + "% gaps";
1252 return conservation;
1257 * @return true if annotation rows have been instantiated for this group
1259 public boolean hasAnnotationRows()
1261 return consensus != null || conservation != null;
1264 public SequenceI getConsensusSeq()
1267 StringBuffer seqs = new StringBuffer();
1268 for (int i = 0; i < consensus.annotations.length; i++)
1270 if (consensus.annotations[i] != null)
1272 String desc = consensus.annotations[i].description;
1273 if (desc.length() > 1 && desc.charAt(0) == '[')
1275 seqs.append(desc.charAt(1));
1279 seqs.append(consensus.annotations[i].displayCharacter);
1284 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1286 sq.setDescription("Percentage Identity Consensus "
1287 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1291 public void setIgnoreGapsConsensus(boolean state)
1293 if (this.ignoreGapsInConsensus != state && consensus != null)
1295 ignoreGapsInConsensus = state;
1296 recalcConservation();
1298 ignoreGapsInConsensus = state;
1301 public boolean isIgnoreGapsConsensus()
1303 return ignoreGapsInConsensus;
1306 public void setIgnoreBelowBackground(boolean state)
1308 hmmIgnoreBelowBackground = state;
1311 public boolean isIgnoreBelowBackground()
1313 return hmmIgnoreBelowBackground;
1316 public void setInfoLetterHeight(boolean state)
1318 hmmUseInfoLetterHeight = state;
1321 public boolean isUseInfoLetterHeight()
1323 return hmmUseInfoLetterHeight;
1327 * @param showSequenceLogo
1328 * indicates if a sequence logo is shown for consensus annotation
1330 public void setshowSequenceLogo(boolean showSequenceLogo)
1332 // TODO: decouple calculation from settings update
1333 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1335 this.showSequenceLogo = showSequenceLogo;
1336 recalcConservation();
1338 this.showSequenceLogo = showSequenceLogo;
1343 * @param showConsHist
1344 * flag indicating if the consensus histogram for this group should
1347 public void setShowConsensusHistogram(boolean showConsHist)
1350 if (showConsensusHistogram != showConsHist && consensus != null)
1352 this.showConsensusHistogram = showConsHist;
1353 recalcConservation();
1355 this.showConsensusHistogram = showConsHist;
1359 * @return the showConsensusHistogram
1361 public boolean isShowConsensusHistogram()
1363 return showConsensusHistogram;
1367 * set flag indicating if logo should be normalised when rendered
1371 public void setNormaliseSequenceLogo(boolean norm)
1373 normaliseSequenceLogo = norm;
1376 public boolean isNormaliseSequenceLogo()
1378 return normaliseSequenceLogo;
1383 * returns a new array with all annotation involving this group
1385 public AlignmentAnnotation[] getAlignmentAnnotation()
1387 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1389 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1390 synchronized (sequences)
1392 for (SequenceI seq : sequences)
1394 AlignmentAnnotation[] aa = seq.getAnnotation();
1397 for (AlignmentAnnotation al : aa)
1399 if (al.groupRef == this)
1406 if (consensus != null)
1408 annot.add(consensus);
1410 if (conservation != null)
1412 annot.add(conservation);
1415 return annot.toArray(new AlignmentAnnotation[0]);
1419 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1421 return AlignmentAnnotation.findAnnotation(
1422 Arrays.asList(getAlignmentAnnotation()), calcId);
1426 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1427 String calcId, String label)
1429 return AlignmentAnnotation.findAnnotations(
1430 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1434 * Answer true if any annotation matches the calcId passed in (if not null).
1439 public boolean hasAnnotation(String calcId)
1441 return AlignmentAnnotation
1442 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1446 * Remove all sequences from the group (leaving other properties unchanged).
1450 synchronized (sequences)
1452 int before = sequences.size();
1454 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1460 * Sets the alignment or group context for this group, and whether it is
1461 * defined as a group
1464 * the context for the group
1466 * whether the group is defined on the alignment or is just a
1468 * @throws IllegalArgumentException
1469 * if setting the context would result in a circular reference chain
1471 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1474 this.isDefined = defined;
1478 * Sets the alignment or group context for this group
1481 * the context for the group
1482 * @throws IllegalArgumentException
1483 * if setting the context would result in a circular reference chain
1485 public void setContext(AnnotatedCollectionI ctx)
1487 AnnotatedCollectionI ref = ctx;
1490 if (ref == this || ref.getContext() == ctx)
1492 throw new IllegalArgumentException(
1493 "Circular reference in SequenceGroup.context");
1495 ref = ref.getContext();
1503 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1506 public AnnotatedCollectionI getContext()
1511 public boolean isDefined()
1516 public void setColourScheme(ColourSchemeI scheme)
1520 cs = new ResidueShader();
1522 cs.setColourScheme(scheme);
1525 public void setGroupColourScheme(ResidueShaderI scheme)
1530 public ColourSchemeI getColourScheme()
1532 return cs == null ? null : cs.getColourScheme();
1535 public ResidueShaderI getGroupColourScheme()
1541 public boolean isNucleotide()
1543 if (context != null)
1545 return context.isNucleotide();
1552 * @return true if seq is a member of the group
1555 public boolean contains(SequenceI seq1)
1557 return sequences.contains(seq1);
1563 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1565 public boolean contains(SequenceI seq, int apos)
1567 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1570 public boolean isShowInformationHistogram()
1572 return hmmShowHistogram;
1575 public void setShowInformationHistogram(boolean state)
1577 if (hmmShowHistogram != state && hmmInformation != null)
1579 this.hmmShowHistogram = state;
1580 // recalcConservation(); TODO don't know what to do here next
1582 this.hmmShowHistogram = state;
1586 public boolean isShowHMMSequenceLogo()
1588 return showHMMSequenceLogo;
1591 public void setshowHMMSequenceLogo(boolean state)
1593 showHMMSequenceLogo = state;
1597 public boolean isNormaliseHMMSequenceLogo()
1599 return hmmNormaliseSequenceLogo;
1602 public void setNormaliseHMMSequenceLogo(boolean state)
1604 normaliseSequenceLogo = state;
1608 public SequenceI getHmmConsensus()
1610 return hmmConsensus;
1614 public void setHmmConsensus(SequenceI hmmSeq)
1616 this.hmmConsensus = hmmSeq;
1619 public ProfilesI getConsensusData()
1621 return consensusProfiles;
1624 public ProfilesI getHmmProfiles()
1629 public void setHmmProfiles(ProfilesI hmmProfiles)
1631 this.hmmProfiles = hmmProfiles;