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;
91 private int width = -1;
94 * colour scheme applied to group if any
96 public ResidueShaderI cs;
98 // start column (base 0)
101 // end column (base 0)
104 public Color outlineColour = Color.black;
106 public Color idColour;
108 public int thresholdTextColour;
110 public Color textColour = Color.black;
112 public Color textColour2 = Color.white;
115 * properties for consensus annotation
117 private boolean ignoreGapsInConsensus = true;
119 private boolean showSequenceLogo;
121 private boolean normaliseSequenceLogo;
123 private boolean showConsensusHistogram;
126 * properties for HMM information annotation
128 private boolean hmmIgnoreBelowBackground = true;
130 private boolean hmmUseInfoLetterHeight;
132 private boolean hmmShowSequenceLogo;
134 private boolean hmmNormaliseSequenceLogo;
136 private boolean hmmShowHistogram;
139 * visibility of rows or represented rows covered by group
141 private boolean hidereps;
144 * visibility of columns intersecting this group
146 private boolean hidecols;
148 private AlignmentAnnotation consensus;
150 private AlignmentAnnotation conservation;
152 private AlignmentAnnotation hmmInformation;
155 * Constructor, assigning a generated default name of "JGroup:" with object
158 public SequenceGroup()
160 groupName = "JGroup:" + this.hashCode();
161 cs = new ResidueShader();
165 * Creates a new SequenceGroup object.
170 * @param displayBoxes
174 * first column of group
176 * last column of group
178 public SequenceGroup(List<SequenceI> sequences, String groupName,
179 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
180 boolean colourText, int start, int end)
183 this.sequences = sequences;
184 this.groupName = groupName;
185 this.displayBoxes = displayBoxes;
186 this.displayText = displayText;
187 this.colourText = colourText;
188 this.cs = new ResidueShader(scheme);
191 recalcConservation();
199 public SequenceGroup(SequenceGroup seqsel)
208 * @param keepsequences
209 * if false do not add sequences from seqsel to new instance
211 public SequenceGroup(SequenceGroup seqsel, boolean keepsequences)
217 sequences = new ArrayList<>();
220 sequences.addAll(seqsel.sequences);
222 if (seqsel.groupName != null)
224 groupName = new String(seqsel.groupName);
226 displayBoxes = seqsel.displayBoxes;
227 displayText = seqsel.displayText;
228 colourText = seqsel.colourText;
229 startRes = seqsel.startRes;
230 endRes = seqsel.endRes;
231 cs = new ResidueShader((ResidueShader) seqsel.cs);
232 if (seqsel.description != null)
234 description = new String(seqsel.description);
236 hidecols = seqsel.hidecols;
237 hidereps = seqsel.hidereps;
238 showNonconserved = seqsel.showNonconserved;
239 showSequenceLogo = seqsel.showSequenceLogo;
240 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
241 showConsensusHistogram = seqsel.showConsensusHistogram;
242 hmmShowSequenceLogo = seqsel.hmmShowSequenceLogo;
243 hmmNormaliseSequenceLogo = seqsel.hmmNormaliseSequenceLogo;
244 hmmShowHistogram = seqsel.hmmShowHistogram;
245 idColour = seqsel.idColour;
246 outlineColour = seqsel.outlineColour;
247 seqrep = seqsel.seqrep;
248 textColour = seqsel.textColour;
249 textColour2 = seqsel.textColour2;
250 thresholdTextColour = seqsel.thresholdTextColour;
251 width = seqsel.width;
252 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
253 hmmIgnoreBelowBackground = seqsel.hmmIgnoreBelowBackground;
254 hmmUseInfoLetterHeight = seqsel.hmmUseInfoLetterHeight;
255 if (keepsequences && seqsel.conservationData != null)
257 // todo avoid doing this if we don't actually want derived calculations
259 recalcConservation(); // safer than
260 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
265 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
268 public void addPropertyChangeListener(PropertyChangeListener listener)
270 changeSupport.addPropertyChangeListener(listener);
273 public void removePropertyChangeListener(PropertyChangeListener listener)
275 changeSupport.removePropertyChangeListener(listener);
278 public boolean isShowSequenceLogo()
280 return showSequenceLogo;
283 public SequenceI[] getSelectionAsNewSequences(AlignmentI align,
284 boolean copyAnnotation)
286 int iSize = sequences.size();
287 SequenceI[] seqs = new SequenceI[iSize];
288 SequenceI[] inorder = getSequencesInOrder(align);
290 for (int i = 0, ipos = 0; i < inorder.length; i++)
292 SequenceI seq = inorder[i];
294 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
295 if (seqs[ipos] != null)
297 seqs[ipos].setDescription(seq.getDescription());
299 if (seq.getAnnotation() != null && copyAnnotation)
301 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
302 // Only copy annotation that is either a score or referenced by the
303 // alignment's annotation vector
304 for (int a = 0; a < seq.getAnnotation().length; a++)
306 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
309 boolean found = false;
310 for (int pos = 0; pos < alann.length; pos++)
312 if (alann[pos] == tocopy)
323 AlignmentAnnotation newannot = new AlignmentAnnotation(
324 seq.getAnnotation()[a]);
325 newannot.restrict(startRes, endRes);
326 newannot.setSequenceRef(seqs[ipos]);
327 newannot.adjustForAlignment();
328 seqs[ipos].addAlignmentAnnotation(newannot);
338 if (iSize != inorder.length)
340 SequenceI[] nseqs = new SequenceI[iSize];
341 System.arraycopy(seqs, 0, nseqs, 0, iSize);
349 * If sequence ends in gaps, the end residue can be correctly calculated here
355 public int findEndRes(SequenceI seq)
360 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
362 ch = seq.getCharAt(j);
363 if (!jalview.util.Comparison.isGap((ch)))
371 eres += seq.getStart() - 1;
378 public List<SequenceI> getSequences()
384 public List<SequenceI> getSequences(
385 Map<SequenceI, SequenceCollectionI> hiddenReps)
387 if (hiddenReps == null)
389 // TODO: need a synchronizedCollection here ?
394 List<SequenceI> allSequences = new ArrayList<>();
395 for (SequenceI seq : sequences)
397 allSequences.add(seq);
398 if (hiddenReps.containsKey(seq))
400 SequenceCollectionI hsg = hiddenReps.get(seq);
401 for (SequenceI seq2 : hsg.getSequences())
403 if (seq2 != seq && !allSequences.contains(seq2))
405 allSequences.add(seq2);
415 public SequenceI[] getSequencesAsArray(
416 Map<SequenceI, SequenceCollectionI> map)
418 List<SequenceI> tmp = getSequences(map);
423 return tmp.toArray(new SequenceI[tmp.size()]);
432 * @return DOCUMENT ME!
434 public boolean adjustForRemoveLeft(int col)
436 // return value is true if the group still exists
439 startRes = startRes - col;
444 endRes = endRes - col;
446 if (startRes > endRes)
453 // must delete this group!!
466 * @return DOCUMENT ME!
468 public boolean adjustForRemoveRight(int col)
487 * @return DOCUMENT ME!
489 public String getName()
494 public String getDescription()
505 public void setName(String name)
508 // TODO: URGENT: update dependent objects (annotation row)
511 public void setDescription(String desc)
519 * @return DOCUMENT ME!
521 public Conservation getConservation()
523 return conservationData;
532 public void setConservation(Conservation c)
534 conservationData = c;
538 * Add s to this sequence group. If aligment sequence is already contained in
539 * group, it will not be added again, but recalculation may happen if the flag
543 * alignment sequence to be added
545 * true means Group's conservation should be recalculated
547 public void addSequence(SequenceI s, boolean recalc)
549 synchronized (sequences)
551 if (s != null && !sequences.contains(s))
554 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
555 sequences.size() - 1, sequences.size());
560 recalcConservation();
566 * Max Gaps Threshold (percent) for performing a conservation calculation
568 private int consPercGaps = 25;
571 * @return Max Gaps Threshold for performing a conservation calculation
573 public int getConsPercGaps()
579 * set Max Gaps Threshold (percent) for performing a conservation calculation
581 * @param consPercGaps
583 public void setConsPercGaps(int consPercGaps)
585 this.consPercGaps = consPercGaps;
589 * calculate residue conservation and colourschemes for group - but only if
590 * necessary. returns true if the calculation resulted in a visible change to
593 public boolean recalcConservation()
595 return recalcAnnotations(false);
599 * Recalculates column consensus, conservation, and HMM annotation for the
600 * group (as applicable). Returns true if the calculation resulted in a
601 * visible change to group.
604 * when set, colourschemes for this group are not refreshed after
607 public boolean recalcAnnotations(boolean defer)
609 if (cs == null && consensus == null && conservation == null
610 && hmmInformation == null)
614 // TODO: try harder to detect changes in state in order to minimise
615 // recalculation effort
619 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
620 endRes + 1, showSequenceLogo);
621 if (hmmInformation != null)
623 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
625 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
626 (endRes + 1) - startRes, startRes, endRes + 1,
627 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
628 _updateInformationRow(info);
631 if (consensus != null)
633 _updateConsensusRow(cnsns, sequences.size());
638 cs.setConsensus(cnsns);
642 if ((conservation != null)
643 || (cs != null && cs.conservationApplied()))
645 Conservation c = new Conservation(groupName, sequences, startRes,
648 c.verdict(false, consPercGaps);
649 if (conservation != null)
651 _updateConservationRow(c);
655 if (cs.conservationApplied())
657 cs.setConservation(c);
660 // eager update - will cause a refresh of overview regardless
663 if (cs != null && !defer)
665 // TODO: JAL-2034 should cs.alignmentChanged modify return state
666 cs.alignmentChanged(context != null ? context : this, null);
673 } catch (java.lang.OutOfMemoryError err)
676 System.out.println("Out of memory loading groups: " + err);
681 private void _updateConservationRow(Conservation c)
683 if (conservation == null)
688 conservation.label = "Conservation for " + getName();
689 conservation.description = "Conservation for group " + getName()
690 + " less than " + consPercGaps + "% gaps";
691 // preserve width if already set
692 int aWidth = (conservation.annotations != null)
693 ? (endRes < conservation.annotations.length
694 ? conservation.annotations.length
697 conservation.annotations = null;
698 conservation.annotations = new Annotation[aWidth]; // should be alignment
700 c.completeAnnotations(conservation, null, startRes, endRes + 1);
703 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
705 if (consensus == null)
709 consensus.label = "Consensus for " + getName();
710 consensus.description = "Percent Identity";
711 consensusProfiles = cnsns;
712 // preserve width if already set
713 int aWidth = (consensus.annotations != null)
714 ? (endRes < consensus.annotations.length
715 ? consensus.annotations.length
718 consensus.annotations = null;
719 consensus.annotations = new Annotation[aWidth]; // should be alignment width
721 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
722 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
725 // ignoreGapsInConsensusCalculation);
729 * Recalculates the information content on the HMM annotation
733 private void _updateInformationRow(ProfilesI cnsns)
735 if (hmmInformation == null)
737 createInformationAnnotation();
739 hmmInformation.description = MessageManager
740 .getString("label.information_description");
741 setHmmProfiles(cnsns);
742 // preserve width if already set
743 int aWidth = (hmmInformation.annotations != null)
744 ? (endRes < hmmInformation.annotations.length
745 ? hmmInformation.annotations.length : endRes + 1)
747 hmmInformation.annotations = null;
748 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
750 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
751 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
757 * sequence to either add or remove from group
759 * flag passed to delete/addSequence to indicate if group properties
760 * should be recalculated
762 public void addOrRemove(SequenceI s, boolean recalc)
764 synchronized (sequences)
766 if (sequences.contains(s))
768 deleteSequence(s, recalc);
772 addSequence(s, recalc);
783 * true means recalculate conservation
785 public void deleteSequence(SequenceI s, boolean recalc)
787 synchronized (sequences)
790 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
791 sequences.size() + 1, sequences.size());
795 recalcConservation();
803 * @return the first column selected by this group. Runs from 0<=i<N_cols
806 public int getStartRes()
813 * @return the groups last selected column. Runs from 0<=i<N_cols
816 public int getEndRes()
822 * Set the first column selected by this group. Runs from 0<=i<N_cols
826 public void setStartRes(int i)
828 int before = startRes;
830 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
834 * Set the groups last selected column. Runs from 0<=i<N_cols
838 public void setEndRes(int i)
842 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
846 * @return number of sequences in group
850 return sequences.size();
855 * @return the ith sequence
857 public SequenceI getSequenceAt(int i)
859 return sequences.get(i);
866 public void setColourText(boolean state)
874 * @return DOCUMENT ME!
876 public boolean getColourText()
887 public void setDisplayText(boolean state)
895 * @return DOCUMENT ME!
897 public boolean getDisplayText()
908 public void setDisplayBoxes(boolean state)
910 displayBoxes = state;
916 * @return DOCUMENT ME!
918 public boolean getDisplayBoxes()
924 * computes the width of current set of sequences and returns it
926 * @return DOCUMENT ME!
929 public int getWidth()
931 synchronized (sequences)
933 // MC This needs to get reset when characters are inserted and deleted
934 boolean first = true;
935 for (SequenceI seq : sequences)
937 if (first || seq.getLength() > width)
939 width = seq.getLength();
953 public void setOutlineColour(Color c)
961 * @return DOCUMENT ME!
963 public Color getOutlineColour()
965 return outlineColour;
970 * returns the sequences in the group ordered by the ordering given by al.
971 * this used to return an array with null entries regardless, new behaviour is
972 * below. TODO: verify that this does not affect use in applet or application
976 * @return SequenceI[] intersection of sequences in group with al, ordered by
977 * al, or null if group does not intersect with al
979 public SequenceI[] getSequencesInOrder(AlignmentI al)
981 return getSequencesInOrder(al, true);
985 * return an array representing the intersection of the group with al,
986 * optionally returning an array the size of al.getHeight() where nulls mark
987 * the non-intersected sequences
991 * @return null or array
993 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
995 synchronized (sequences)
997 int sSize = sequences.size();
998 int alHeight = al.getHeight();
1000 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
1003 for (int i = 0; i < alHeight && index < sSize; i++)
1005 if (sequences.contains(al.getSequenceAt(i)))
1007 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1019 if (index < seqs.length)
1021 SequenceI[] dummy = seqs;
1022 seqs = new SequenceI[index];
1023 while (--index >= 0)
1025 seqs[index] = dummy[index];
1026 dummy[index] = null;
1034 * @return the idColour
1036 public Color getIdColour()
1043 * the idColour to set
1045 public void setIdColour(Color idColour)
1047 this.idColour = idColour;
1051 * @return the representative sequence for this group
1054 public SequenceI getSeqrep()
1060 * set the representative sequence for this group. Note - this affects the
1061 * interpretation of the Hidereps attribute.
1064 * the seqrep to set (null means no sequence representative)
1067 public void setSeqrep(SequenceI seqrep)
1069 this.seqrep = seqrep;
1074 * @return true if group has a sequence representative
1077 public boolean hasSeqrep()
1079 return seqrep != null;
1083 * set visibility of sequences covered by (if no sequence representative is
1084 * defined) or represented by this group.
1088 public void setHidereps(boolean visibility)
1090 hidereps = visibility;
1095 * @return true if sequences represented (or covered) by this group should be
1098 public boolean isHidereps()
1104 * set intended visibility of columns covered by this group
1108 public void setHideCols(boolean visibility)
1110 hidecols = visibility;
1115 * @return true if columns covered by group should be hidden
1117 public boolean isHideCols()
1123 * create a new sequence group from the intersection of this group with an
1124 * alignment Hashtable of hidden representatives
1130 * @return new group containing sequences common to this group and alignment
1132 public SequenceGroup intersect(AlignmentI alignment,
1133 Map<SequenceI, SequenceCollectionI> map)
1135 SequenceGroup sgroup = new SequenceGroup(this);
1136 SequenceI[] insect = getSequencesInOrder(alignment);
1137 sgroup.sequences = new ArrayList<>();
1138 for (int s = 0; insect != null && s < insect.length; s++)
1140 if (map == null || map.containsKey(insect[s]))
1142 sgroup.sequences.add(insect[s]);
1149 * @return the showUnconserved
1151 public boolean getShowNonconserved()
1153 return showNonconserved;
1157 * @param showNonconserved
1158 * the showUnconserved to set
1160 public void setShowNonconserved(boolean displayNonconserved)
1162 this.showNonconserved = displayNonconserved;
1166 * set this alignmentAnnotation object as the one used to render consensus
1171 public void setConsensus(AlignmentAnnotation aan)
1173 if (consensus == null)
1181 * @return automatically calculated consensus row note: the row is a stub if a
1182 * consensus calculation has not yet been performed on the group
1184 public AlignmentAnnotation getConsensus()
1186 // TODO get or calculate and get consensus annotation row for this group
1187 int aWidth = this.getWidth();
1195 if (consensus == null)
1197 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1198 100f, AlignmentAnnotation.BAR_GRAPH);
1199 consensus.hasText = true;
1200 consensus.autoCalculated = true;
1201 consensus.groupRef = this;
1202 consensus.label = "Consensus for " + getName();
1203 consensus.description = "Percent Identity";
1209 * Creates the Hidden Markov Model annotation for this group
1211 void createInformationAnnotation()
1213 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1214 6.25f, AlignmentAnnotation.BAR_GRAPH);
1215 hmmInformation.hasText = true;
1216 hmmInformation.autoCalculated = false;
1217 hmmInformation.groupRef = this;
1218 hmmInformation.label = getName();
1219 hmmInformation.description = MessageManager
1220 .getString("label.information_description");
1221 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1225 * set this alignmentAnnotation object as the one used to render consensus
1230 public void setConservationRow(AlignmentAnnotation aan)
1232 if (conservation == null)
1239 * get the conservation annotation row for this group
1241 * @return autoCalculated annotation row
1243 public AlignmentAnnotation getConservationRow()
1245 if (conservation == null)
1247 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1248 11f, AlignmentAnnotation.BAR_GRAPH);
1251 conservation.hasText = true;
1252 conservation.autoCalculated = true;
1253 conservation.groupRef = this;
1254 conservation.label = "Conservation for " + getName();
1255 conservation.description = "Conservation for group " + getName()
1256 + " less than " + consPercGaps + "% gaps";
1257 return conservation;
1262 * @return true if annotation rows have been instantiated for this group
1264 public boolean hasAnnotationRows()
1266 return consensus != null || conservation != null;
1269 public SequenceI getConsensusSeq()
1272 StringBuffer seqs = new StringBuffer();
1273 for (int i = 0; i < consensus.annotations.length; i++)
1275 if (consensus.annotations[i] != null)
1277 String desc = consensus.annotations[i].description;
1278 if (desc.length() > 1 && desc.charAt(0) == '[')
1280 seqs.append(desc.charAt(1));
1284 seqs.append(consensus.annotations[i].displayCharacter);
1289 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1291 sq.setDescription("Percentage Identity Consensus "
1292 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1296 public void setIgnoreGapsConsensus(boolean state)
1298 if (this.ignoreGapsInConsensus != state && consensus != null)
1300 ignoreGapsInConsensus = state;
1301 recalcConservation();
1303 ignoreGapsInConsensus = state;
1306 public boolean isIgnoreGapsConsensus()
1308 return ignoreGapsInConsensus;
1311 public void setIgnoreBelowBackground(boolean state)
1313 hmmIgnoreBelowBackground = state;
1316 public boolean isIgnoreBelowBackground()
1318 return hmmIgnoreBelowBackground;
1321 public void setInfoLetterHeight(boolean state)
1323 hmmUseInfoLetterHeight = state;
1326 public boolean isUseInfoLetterHeight()
1328 return hmmUseInfoLetterHeight;
1332 * @param showSequenceLogo
1333 * indicates if a sequence logo is shown for consensus annotation
1335 public void setshowSequenceLogo(boolean showSequenceLogo)
1337 // TODO: decouple calculation from settings update
1338 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1340 this.showSequenceLogo = showSequenceLogo;
1341 recalcConservation();
1343 this.showSequenceLogo = showSequenceLogo;
1348 * @param showConsHist
1349 * flag indicating if the consensus histogram for this group should
1352 public void setShowConsensusHistogram(boolean showConsHist)
1355 if (showConsensusHistogram != showConsHist && consensus != null)
1357 this.showConsensusHistogram = showConsHist;
1358 recalcConservation();
1360 this.showConsensusHistogram = showConsHist;
1364 * @return the showConsensusHistogram
1366 public boolean isShowConsensusHistogram()
1368 return showConsensusHistogram;
1372 * set flag indicating if logo should be normalised when rendered
1376 public void setNormaliseSequenceLogo(boolean norm)
1378 normaliseSequenceLogo = norm;
1381 public boolean isNormaliseSequenceLogo()
1383 return normaliseSequenceLogo;
1388 * returns a new array with all annotation involving this group
1390 public AlignmentAnnotation[] getAlignmentAnnotation()
1392 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1394 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1395 synchronized (sequences)
1397 for (SequenceI seq : sequences)
1399 AlignmentAnnotation[] aa = seq.getAnnotation();
1402 for (AlignmentAnnotation al : aa)
1404 if (al.groupRef == this)
1411 if (consensus != null)
1413 annot.add(consensus);
1415 if (conservation != null)
1417 annot.add(conservation);
1420 return annot.toArray(new AlignmentAnnotation[0]);
1424 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1426 return AlignmentAnnotation.findAnnotation(
1427 Arrays.asList(getAlignmentAnnotation()), calcId);
1431 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1432 String calcId, String label)
1434 return AlignmentAnnotation.findAnnotations(
1435 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1439 * Answer true if any annotation matches the calcId passed in (if not null).
1444 public boolean hasAnnotation(String calcId)
1446 return AlignmentAnnotation
1447 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1451 * Remove all sequences from the group (leaving other properties unchanged).
1455 synchronized (sequences)
1457 int before = sequences.size();
1459 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1465 * Sets the alignment or group context for this group, and whether it is
1466 * defined as a group
1469 * the context for the group
1471 * whether the group is defined on the alignment or is just a
1473 * @throws IllegalArgumentException
1474 * if setting the context would result in a circular reference chain
1476 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1479 this.isDefined = defined;
1483 * Sets the alignment or group context for this group
1486 * the context for the group
1487 * @throws IllegalArgumentException
1488 * if setting the context would result in a circular reference chain
1490 public void setContext(AnnotatedCollectionI ctx)
1492 AnnotatedCollectionI ref = ctx;
1495 if (ref == this || ref.getContext() == ctx)
1497 throw new IllegalArgumentException(
1498 "Circular reference in SequenceGroup.context");
1500 ref = ref.getContext();
1508 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1511 public AnnotatedCollectionI getContext()
1516 public boolean isDefined()
1521 public void setColourScheme(ColourSchemeI scheme)
1525 cs = new ResidueShader();
1527 cs.setColourScheme(scheme);
1530 public void setGroupColourScheme(ResidueShaderI scheme)
1535 public ColourSchemeI getColourScheme()
1537 return cs == null ? null : cs.getColourScheme();
1540 public ResidueShaderI getGroupColourScheme()
1546 public boolean isNucleotide()
1548 if (context != null)
1550 return context.isNucleotide();
1557 * @return true if seq is a member of the group
1560 public boolean contains(SequenceI seq1)
1562 return sequences.contains(seq1);
1568 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1570 public boolean contains(SequenceI seq, int apos)
1572 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1575 public boolean isShowInformationHistogram()
1577 return hmmShowHistogram;
1580 public void setShowInformationHistogram(boolean state)
1582 if (hmmShowHistogram != state && hmmInformation != null)
1584 this.hmmShowHistogram = state;
1585 // recalcConservation(); TODO don't know what to do here next
1587 this.hmmShowHistogram = state;
1590 public boolean isShowHMMSequenceLogo()
1592 return hmmShowSequenceLogo;
1595 public void setShowHMMSequenceLogo(boolean state)
1597 hmmShowSequenceLogo = state;
1600 public boolean isNormaliseHMMSequenceLogo()
1602 return hmmNormaliseSequenceLogo;
1605 public void setNormaliseHMMSequenceLogo(boolean state)
1607 hmmNormaliseSequenceLogo = state;
1610 public ProfilesI getConsensusData()
1612 return consensusProfiles;
1615 public ProfilesI getHmmProfiles()
1620 public void setHmmProfiles(ProfilesI hmmProfiles)
1622 this.hmmProfiles = hmmProfiles;
1626 public List<SequenceI> getHmmSequences()
1628 List<SequenceI> result = new ArrayList<>();
1629 for (int i = 0; i < sequences.size(); i++)
1631 SequenceI seq = sequences.get(i);
1632 if (seq.hasHMMProfile())