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);
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
727 private void _updateInformationRow(ProfilesI cnsns)
729 if (hmmInformation == null)
731 createInformationAnnotation();
733 hmmInformation.description = MessageManager
734 .getString("label.information_description");
735 setHmmProfiles(cnsns);
736 // preserve width if already set
737 int aWidth = (hmmInformation.annotations != null)
738 ? (endRes < hmmInformation.annotations.length
739 ? hmmInformation.annotations.length : endRes + 1)
741 hmmInformation.annotations = null;
742 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
744 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
745 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
751 * sequence to either add or remove from group
753 * flag passed to delete/addSequence to indicate if group properties
754 * should be recalculated
756 public void addOrRemove(SequenceI s, boolean recalc)
758 synchronized (sequences)
760 if (sequences.contains(s))
762 deleteSequence(s, recalc);
766 addSequence(s, recalc);
777 * true means recalculate conservation
779 public void deleteSequence(SequenceI s, boolean recalc)
781 synchronized (sequences)
784 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
785 sequences.size() + 1, sequences.size());
789 recalcConservation();
797 * @return the first column selected by this group. Runs from 0<=i<N_cols
800 public int getStartRes()
807 * @return the groups last selected column. Runs from 0<=i<N_cols
810 public int getEndRes()
816 * Set the first column selected by this group. Runs from 0<=i<N_cols
820 public void setStartRes(int i)
822 int before = startRes;
824 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
828 * Set the groups last selected column. Runs from 0<=i<N_cols
832 public void setEndRes(int i)
836 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
840 * @return number of sequences in group
844 return sequences.size();
849 * @return the ith sequence
851 public SequenceI getSequenceAt(int i)
853 return sequences.get(i);
860 public void setColourText(boolean state)
868 * @return DOCUMENT ME!
870 public boolean getColourText()
881 public void setDisplayText(boolean state)
889 * @return DOCUMENT ME!
891 public boolean getDisplayText()
902 public void setDisplayBoxes(boolean state)
904 displayBoxes = state;
910 * @return DOCUMENT ME!
912 public boolean getDisplayBoxes()
918 * computes the width of current set of sequences and returns it
920 * @return DOCUMENT ME!
923 public int getWidth()
925 synchronized (sequences)
927 // MC This needs to get reset when characters are inserted and deleted
928 boolean first = true;
929 for (SequenceI seq : sequences)
931 if (first || seq.getLength() > width)
933 width = seq.getLength();
947 public void setOutlineColour(Color c)
955 * @return DOCUMENT ME!
957 public Color getOutlineColour()
959 return outlineColour;
964 * returns the sequences in the group ordered by the ordering given by al.
965 * this used to return an array with null entries regardless, new behaviour is
966 * below. TODO: verify that this does not affect use in applet or application
970 * @return SequenceI[] intersection of sequences in group with al, ordered by
971 * al, or null if group does not intersect with al
973 public SequenceI[] getSequencesInOrder(AlignmentI al)
975 return getSequencesInOrder(al, true);
979 * return an array representing the intersection of the group with al,
980 * optionally returning an array the size of al.getHeight() where nulls mark
981 * the non-intersected sequences
985 * @return null or array
987 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
989 synchronized (sequences)
991 int sSize = sequences.size();
992 int alHeight = al.getHeight();
994 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
997 for (int i = 0; i < alHeight && index < sSize; i++)
999 if (sequences.contains(al.getSequenceAt(i)))
1001 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1013 if (index < seqs.length)
1015 SequenceI[] dummy = seqs;
1016 seqs = new SequenceI[index];
1017 while (--index >= 0)
1019 seqs[index] = dummy[index];
1020 dummy[index] = null;
1028 * @return the idColour
1030 public Color getIdColour()
1037 * the idColour to set
1039 public void setIdColour(Color idColour)
1041 this.idColour = idColour;
1045 * @return the representative sequence for this group
1048 public SequenceI getSeqrep()
1054 * set the representative sequence for this group. Note - this affects the
1055 * interpretation of the Hidereps attribute.
1058 * the seqrep to set (null means no sequence representative)
1061 public void setSeqrep(SequenceI seqrep)
1063 this.seqrep = seqrep;
1068 * @return true if group has a sequence representative
1071 public boolean hasSeqrep()
1073 return seqrep != null;
1077 * set visibility of sequences covered by (if no sequence representative is
1078 * defined) or represented by this group.
1082 public void setHidereps(boolean visibility)
1084 hidereps = visibility;
1089 * @return true if sequences represented (or covered) by this group should be
1092 public boolean isHidereps()
1098 * set intended visibility of columns covered by this group
1102 public void setHideCols(boolean visibility)
1104 hidecols = visibility;
1109 * @return true if columns covered by group should be hidden
1111 public boolean isHideCols()
1117 * create a new sequence group from the intersection of this group with an
1118 * alignment Hashtable of hidden representatives
1124 * @return new group containing sequences common to this group and alignment
1126 public SequenceGroup intersect(AlignmentI alignment,
1127 Map<SequenceI, SequenceCollectionI> map)
1129 SequenceGroup sgroup = new SequenceGroup(this);
1130 SequenceI[] insect = getSequencesInOrder(alignment);
1131 sgroup.sequences = new ArrayList<>();
1132 for (int s = 0; insect != null && s < insect.length; s++)
1134 if (map == null || map.containsKey(insect[s]))
1136 sgroup.sequences.add(insect[s]);
1143 * @return the showUnconserved
1145 public boolean getShowNonconserved()
1147 return showNonconserved;
1151 * @param showNonconserved
1152 * the showUnconserved to set
1154 public void setShowNonconserved(boolean displayNonconserved)
1156 this.showNonconserved = displayNonconserved;
1160 * set this alignmentAnnotation object as the one used to render consensus
1165 public void setConsensus(AlignmentAnnotation aan)
1167 if (consensus == null)
1175 * @return automatically calculated consensus row note: the row is a stub if a
1176 * consensus calculation has not yet been performed on the group
1178 public AlignmentAnnotation getConsensus()
1180 // TODO get or calculate and get consensus annotation row for this group
1181 int aWidth = this.getWidth();
1189 if (consensus == null)
1191 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1192 100f, AlignmentAnnotation.BAR_GRAPH);
1193 consensus.hasText = true;
1194 consensus.autoCalculated = true;
1195 consensus.groupRef = this;
1196 consensus.label = "Consensus for " + getName();
1197 consensus.description = "Percent Identity";
1203 * Creates the Hidden Markov Model annotation for this group
1205 void createInformationAnnotation()
1207 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1208 6.25f, AlignmentAnnotation.BAR_GRAPH);
1209 hmmInformation.hasText = true;
1210 hmmInformation.autoCalculated = false;
1211 hmmInformation.groupRef = this;
1212 hmmInformation.label = getName();
1213 hmmInformation.description = MessageManager
1214 .getString("label.information_description");
1215 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1219 * set this alignmentAnnotation object as the one used to render consensus
1224 public void setConservationRow(AlignmentAnnotation aan)
1226 if (conservation == null)
1233 * get the conservation annotation row for this group
1235 * @return autoCalculated annotation row
1237 public AlignmentAnnotation getConservationRow()
1239 if (conservation == null)
1241 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1242 11f, AlignmentAnnotation.BAR_GRAPH);
1245 conservation.hasText = true;
1246 conservation.autoCalculated = true;
1247 conservation.groupRef = this;
1248 conservation.label = "Conservation for " + getName();
1249 conservation.description = "Conservation for group " + getName()
1250 + " less than " + consPercGaps + "% gaps";
1251 return conservation;
1256 * @return true if annotation rows have been instantiated for this group
1258 public boolean hasAnnotationRows()
1260 return consensus != null || conservation != null;
1263 public SequenceI getConsensusSeq()
1266 StringBuffer seqs = new StringBuffer();
1267 for (int i = 0; i < consensus.annotations.length; i++)
1269 if (consensus.annotations[i] != null)
1271 String desc = consensus.annotations[i].description;
1272 if (desc.length() > 1 && desc.charAt(0) == '[')
1274 seqs.append(desc.charAt(1));
1278 seqs.append(consensus.annotations[i].displayCharacter);
1283 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1285 sq.setDescription("Percentage Identity Consensus "
1286 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1290 public void setIgnoreGapsConsensus(boolean state)
1292 if (this.ignoreGapsInConsensus != state && consensus != null)
1294 ignoreGapsInConsensus = state;
1295 recalcConservation();
1297 ignoreGapsInConsensus = state;
1300 public boolean isIgnoreGapsConsensus()
1302 return ignoreGapsInConsensus;
1305 public void setIgnoreBelowBackground(boolean state)
1307 hmmIgnoreBelowBackground = state;
1310 public boolean isIgnoreBelowBackground()
1312 return hmmIgnoreBelowBackground;
1315 public void setInfoLetterHeight(boolean state)
1317 hmmUseInfoLetterHeight = state;
1320 public boolean isUseInfoLetterHeight()
1322 return hmmUseInfoLetterHeight;
1326 * @param showSequenceLogo
1327 * indicates if a sequence logo is shown for consensus annotation
1329 public void setshowSequenceLogo(boolean showSequenceLogo)
1331 // TODO: decouple calculation from settings update
1332 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1334 this.showSequenceLogo = showSequenceLogo;
1335 recalcConservation();
1337 this.showSequenceLogo = showSequenceLogo;
1342 * @param showConsHist
1343 * flag indicating if the consensus histogram for this group should
1346 public void setShowConsensusHistogram(boolean showConsHist)
1349 if (showConsensusHistogram != showConsHist && consensus != null)
1351 this.showConsensusHistogram = showConsHist;
1352 recalcConservation();
1354 this.showConsensusHistogram = showConsHist;
1358 * @return the showConsensusHistogram
1360 public boolean isShowConsensusHistogram()
1362 return showConsensusHistogram;
1366 * set flag indicating if logo should be normalised when rendered
1370 public void setNormaliseSequenceLogo(boolean norm)
1372 normaliseSequenceLogo = norm;
1375 public boolean isNormaliseSequenceLogo()
1377 return normaliseSequenceLogo;
1382 * returns a new array with all annotation involving this group
1384 public AlignmentAnnotation[] getAlignmentAnnotation()
1386 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1388 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1389 synchronized (sequences)
1391 for (SequenceI seq : sequences)
1393 AlignmentAnnotation[] aa = seq.getAnnotation();
1396 for (AlignmentAnnotation al : aa)
1398 if (al.groupRef == this)
1405 if (consensus != null)
1407 annot.add(consensus);
1409 if (conservation != null)
1411 annot.add(conservation);
1414 return annot.toArray(new AlignmentAnnotation[0]);
1418 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1420 return AlignmentAnnotation.findAnnotation(
1421 Arrays.asList(getAlignmentAnnotation()), calcId);
1425 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1426 String calcId, String label)
1428 return AlignmentAnnotation.findAnnotations(
1429 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1433 * Answer true if any annotation matches the calcId passed in (if not null).
1438 public boolean hasAnnotation(String calcId)
1440 return AlignmentAnnotation
1441 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1445 * Remove all sequences from the group (leaving other properties unchanged).
1449 synchronized (sequences)
1451 int before = sequences.size();
1453 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1459 * Sets the alignment or group context for this group, and whether it is
1460 * defined as a group
1463 * the context for the group
1465 * whether the group is defined on the alignment or is just a
1467 * @throws IllegalArgumentException
1468 * if setting the context would result in a circular reference chain
1470 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1473 this.isDefined = defined;
1477 * Sets the alignment or group context for this group
1480 * the context for the group
1481 * @throws IllegalArgumentException
1482 * if setting the context would result in a circular reference chain
1484 public void setContext(AnnotatedCollectionI ctx)
1486 AnnotatedCollectionI ref = ctx;
1489 if (ref == this || ref.getContext() == ctx)
1491 throw new IllegalArgumentException(
1492 "Circular reference in SequenceGroup.context");
1494 ref = ref.getContext();
1502 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1505 public AnnotatedCollectionI getContext()
1510 public boolean isDefined()
1515 public void setColourScheme(ColourSchemeI scheme)
1519 cs = new ResidueShader();
1521 cs.setColourScheme(scheme);
1524 public void setGroupColourScheme(ResidueShaderI scheme)
1529 public ColourSchemeI getColourScheme()
1531 return cs == null ? null : cs.getColourScheme();
1534 public ResidueShaderI getGroupColourScheme()
1540 public boolean isNucleotide()
1542 if (context != null)
1544 return context.isNucleotide();
1551 * @return true if seq is a member of the group
1554 public boolean contains(SequenceI seq1)
1556 return sequences.contains(seq1);
1562 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1564 public boolean contains(SequenceI seq, int apos)
1566 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1569 public boolean isShowInformationHistogram()
1571 return hmmShowHistogram;
1574 public void setShowInformationHistogram(boolean state)
1576 if (hmmShowHistogram != state && hmmInformation != null)
1578 this.hmmShowHistogram = state;
1579 // recalcConservation(); TODO don't know what to do here next
1581 this.hmmShowHistogram = state;
1585 public boolean isShowHMMSequenceLogo()
1587 return showHMMSequenceLogo;
1590 public void setshowHMMSequenceLogo(boolean state)
1592 showHMMSequenceLogo = state;
1596 public boolean isNormaliseHMMSequenceLogo()
1598 return hmmNormaliseSequenceLogo;
1601 public void setNormaliseHMMSequenceLogo(boolean state)
1603 normaliseSequenceLogo = state;
1607 public SequenceI getHmmConsensus()
1609 return hmmConsensus;
1613 public void setHmmConsensus(SequenceI hmmSeq)
1615 this.hmmConsensus = hmmSeq;
1618 public ProfilesI getConsensusData()
1620 return consensusProfiles;
1623 public ProfilesI getHmmProfiles()
1628 public void setHmmProfiles(ProfilesI hmmProfiles)
1630 this.hmmProfiles = hmmProfiles;