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 hmmShowSequenceLogo;
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 hmmShowSequenceLogo = seqsel.hmmShowSequenceLogo;
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 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
621 _updateInformationRow(info);
624 if (consensus != null)
626 _updateConsensusRow(cnsns, sequences.size());
631 cs.setConsensus(cnsns);
635 if ((conservation != null)
636 || (cs != null && cs.conservationApplied()))
638 Conservation c = new Conservation(groupName, sequences, startRes,
641 c.verdict(false, consPercGaps);
642 if (conservation != null)
644 _updateConservationRow(c);
648 if (cs.conservationApplied())
650 cs.setConservation(c);
653 // eager update - will cause a refresh of overview regardless
656 if (cs != null && !defer)
658 // TODO: JAL-2034 should cs.alignmentChanged modify return state
659 cs.alignmentChanged(context != null ? context : this, null);
666 } catch (java.lang.OutOfMemoryError err)
669 System.out.println("Out of memory loading groups: " + err);
674 private void _updateConservationRow(Conservation c)
676 if (conservation == null)
681 conservation.label = "Conservation for " + getName();
682 conservation.description = "Conservation for group " + getName()
683 + " less than " + consPercGaps + "% gaps";
684 // preserve width if already set
685 int aWidth = (conservation.annotations != null)
686 ? (endRes < conservation.annotations.length
687 ? conservation.annotations.length
690 conservation.annotations = null;
691 conservation.annotations = new Annotation[aWidth]; // should be alignment
693 c.completeAnnotations(conservation, null, startRes, endRes + 1);
696 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
698 if (consensus == null)
702 consensus.label = "Consensus for " + getName();
703 consensus.description = "Percent Identity";
704 consensusProfiles = cnsns;
705 // preserve width if already set
706 int aWidth = (consensus.annotations != null)
707 ? (endRes < consensus.annotations.length
708 ? consensus.annotations.length
711 consensus.annotations = null;
712 consensus.annotations = new Annotation[aWidth]; // should be alignment width
714 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
715 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
718 // ignoreGapsInConsensusCalculation);
722 * Recalculates the information content on the HMM annotation
726 private void _updateInformationRow(ProfilesI cnsns)
728 if (hmmInformation == null)
730 createInformationAnnotation();
732 hmmInformation.description = MessageManager
733 .getString("label.information_description");
734 setHmmProfiles(cnsns);
735 // preserve width if already set
736 int aWidth = (hmmInformation.annotations != null)
737 ? (endRes < hmmInformation.annotations.length
738 ? hmmInformation.annotations.length : endRes + 1)
740 hmmInformation.annotations = null;
741 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
743 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
744 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
750 * sequence to either add or remove from group
752 * flag passed to delete/addSequence to indicate if group properties
753 * should be recalculated
755 public void addOrRemove(SequenceI s, boolean recalc)
757 synchronized (sequences)
759 if (sequences.contains(s))
761 deleteSequence(s, recalc);
765 addSequence(s, recalc);
776 * true means recalculate conservation
778 public void deleteSequence(SequenceI s, boolean recalc)
780 synchronized (sequences)
783 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
784 sequences.size() + 1, sequences.size());
788 recalcConservation();
796 * @return the first column selected by this group. Runs from 0<=i<N_cols
799 public int getStartRes()
806 * @return the groups last selected column. Runs from 0<=i<N_cols
809 public int getEndRes()
815 * Set the first column selected by this group. Runs from 0<=i<N_cols
819 public void setStartRes(int i)
821 int before = startRes;
823 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
827 * Set the groups last selected column. Runs from 0<=i<N_cols
831 public void setEndRes(int i)
835 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
839 * @return number of sequences in group
843 return sequences.size();
848 * @return the ith sequence
850 public SequenceI getSequenceAt(int i)
852 return sequences.get(i);
859 public void setColourText(boolean state)
867 * @return DOCUMENT ME!
869 public boolean getColourText()
880 public void setDisplayText(boolean state)
888 * @return DOCUMENT ME!
890 public boolean getDisplayText()
901 public void setDisplayBoxes(boolean state)
903 displayBoxes = state;
909 * @return DOCUMENT ME!
911 public boolean getDisplayBoxes()
917 * computes the width of current set of sequences and returns it
919 * @return DOCUMENT ME!
922 public int getWidth()
924 synchronized (sequences)
926 // MC This needs to get reset when characters are inserted and deleted
927 boolean first = true;
928 for (SequenceI seq : sequences)
930 if (first || seq.getLength() > width)
932 width = seq.getLength();
946 public void setOutlineColour(Color c)
954 * @return DOCUMENT ME!
956 public Color getOutlineColour()
958 return outlineColour;
963 * returns the sequences in the group ordered by the ordering given by al.
964 * this used to return an array with null entries regardless, new behaviour is
965 * below. TODO: verify that this does not affect use in applet or application
969 * @return SequenceI[] intersection of sequences in group with al, ordered by
970 * al, or null if group does not intersect with al
972 public SequenceI[] getSequencesInOrder(AlignmentI al)
974 return getSequencesInOrder(al, true);
978 * return an array representing the intersection of the group with al,
979 * optionally returning an array the size of al.getHeight() where nulls mark
980 * the non-intersected sequences
984 * @return null or array
986 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
988 synchronized (sequences)
990 int sSize = sequences.size();
991 int alHeight = al.getHeight();
993 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
996 for (int i = 0; i < alHeight && index < sSize; i++)
998 if (sequences.contains(al.getSequenceAt(i)))
1000 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1012 if (index < seqs.length)
1014 SequenceI[] dummy = seqs;
1015 seqs = new SequenceI[index];
1016 while (--index >= 0)
1018 seqs[index] = dummy[index];
1019 dummy[index] = null;
1027 * @return the idColour
1029 public Color getIdColour()
1036 * the idColour to set
1038 public void setIdColour(Color idColour)
1040 this.idColour = idColour;
1044 * @return the representative sequence for this group
1047 public SequenceI getSeqrep()
1053 * set the representative sequence for this group. Note - this affects the
1054 * interpretation of the Hidereps attribute.
1057 * the seqrep to set (null means no sequence representative)
1060 public void setSeqrep(SequenceI seqrep)
1062 this.seqrep = seqrep;
1067 * @return true if group has a sequence representative
1070 public boolean hasSeqrep()
1072 return seqrep != null;
1076 * set visibility of sequences covered by (if no sequence representative is
1077 * defined) or represented by this group.
1081 public void setHidereps(boolean visibility)
1083 hidereps = visibility;
1088 * @return true if sequences represented (or covered) by this group should be
1091 public boolean isHidereps()
1097 * set intended visibility of columns covered by this group
1101 public void setHideCols(boolean visibility)
1103 hidecols = visibility;
1108 * @return true if columns covered by group should be hidden
1110 public boolean isHideCols()
1116 * create a new sequence group from the intersection of this group with an
1117 * alignment Hashtable of hidden representatives
1123 * @return new group containing sequences common to this group and alignment
1125 public SequenceGroup intersect(AlignmentI alignment,
1126 Map<SequenceI, SequenceCollectionI> map)
1128 SequenceGroup sgroup = new SequenceGroup(this);
1129 SequenceI[] insect = getSequencesInOrder(alignment);
1130 sgroup.sequences = new ArrayList<>();
1131 for (int s = 0; insect != null && s < insect.length; s++)
1133 if (map == null || map.containsKey(insect[s]))
1135 sgroup.sequences.add(insect[s]);
1142 * @return the showUnconserved
1144 public boolean getShowNonconserved()
1146 return showNonconserved;
1150 * @param showNonconserved
1151 * the showUnconserved to set
1153 public void setShowNonconserved(boolean displayNonconserved)
1155 this.showNonconserved = displayNonconserved;
1159 * set this alignmentAnnotation object as the one used to render consensus
1164 public void setConsensus(AlignmentAnnotation aan)
1166 if (consensus == null)
1174 * @return automatically calculated consensus row note: the row is a stub if a
1175 * consensus calculation has not yet been performed on the group
1177 public AlignmentAnnotation getConsensus()
1179 // TODO get or calculate and get consensus annotation row for this group
1180 int aWidth = this.getWidth();
1188 if (consensus == null)
1190 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1191 100f, AlignmentAnnotation.BAR_GRAPH);
1192 consensus.hasText = true;
1193 consensus.autoCalculated = true;
1194 consensus.groupRef = this;
1195 consensus.label = "Consensus for " + getName();
1196 consensus.description = "Percent Identity";
1202 * Creates the Hidden Markov Model annotation for this group
1204 void createInformationAnnotation()
1206 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1207 6.25f, AlignmentAnnotation.BAR_GRAPH);
1208 hmmInformation.hasText = true;
1209 hmmInformation.autoCalculated = false;
1210 hmmInformation.groupRef = this;
1211 hmmInformation.label = getName();
1212 hmmInformation.description = MessageManager
1213 .getString("label.information_description");
1214 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1218 * set this alignmentAnnotation object as the one used to render consensus
1223 public void setConservationRow(AlignmentAnnotation aan)
1225 if (conservation == null)
1232 * get the conservation annotation row for this group
1234 * @return autoCalculated annotation row
1236 public AlignmentAnnotation getConservationRow()
1238 if (conservation == null)
1240 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1241 11f, AlignmentAnnotation.BAR_GRAPH);
1244 conservation.hasText = true;
1245 conservation.autoCalculated = true;
1246 conservation.groupRef = this;
1247 conservation.label = "Conservation for " + getName();
1248 conservation.description = "Conservation for group " + getName()
1249 + " less than " + consPercGaps + "% gaps";
1250 return conservation;
1255 * @return true if annotation rows have been instantiated for this group
1257 public boolean hasAnnotationRows()
1259 return consensus != null || conservation != null;
1262 public SequenceI getConsensusSeq()
1265 StringBuffer seqs = new StringBuffer();
1266 for (int i = 0; i < consensus.annotations.length; i++)
1268 if (consensus.annotations[i] != null)
1270 String desc = consensus.annotations[i].description;
1271 if (desc.length() > 1 && desc.charAt(0) == '[')
1273 seqs.append(desc.charAt(1));
1277 seqs.append(consensus.annotations[i].displayCharacter);
1282 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1284 sq.setDescription("Percentage Identity Consensus "
1285 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1289 public void setIgnoreGapsConsensus(boolean state)
1291 if (this.ignoreGapsInConsensus != state && consensus != null)
1293 ignoreGapsInConsensus = state;
1294 recalcConservation();
1296 ignoreGapsInConsensus = state;
1299 public boolean isIgnoreGapsConsensus()
1301 return ignoreGapsInConsensus;
1304 public void setIgnoreBelowBackground(boolean state)
1306 hmmIgnoreBelowBackground = state;
1309 public boolean isIgnoreBelowBackground()
1311 return hmmIgnoreBelowBackground;
1314 public void setInfoLetterHeight(boolean state)
1316 hmmUseInfoLetterHeight = state;
1319 public boolean isUseInfoLetterHeight()
1321 return hmmUseInfoLetterHeight;
1325 * @param showSequenceLogo
1326 * indicates if a sequence logo is shown for consensus annotation
1328 public void setshowSequenceLogo(boolean showSequenceLogo)
1330 // TODO: decouple calculation from settings update
1331 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1333 this.showSequenceLogo = showSequenceLogo;
1334 recalcConservation();
1336 this.showSequenceLogo = showSequenceLogo;
1341 * @param showConsHist
1342 * flag indicating if the consensus histogram for this group should
1345 public void setShowConsensusHistogram(boolean showConsHist)
1348 if (showConsensusHistogram != showConsHist && consensus != null)
1350 this.showConsensusHistogram = showConsHist;
1351 recalcConservation();
1353 this.showConsensusHistogram = showConsHist;
1357 * @return the showConsensusHistogram
1359 public boolean isShowConsensusHistogram()
1361 return showConsensusHistogram;
1365 * set flag indicating if logo should be normalised when rendered
1369 public void setNormaliseSequenceLogo(boolean norm)
1371 normaliseSequenceLogo = norm;
1374 public boolean isNormaliseSequenceLogo()
1376 return normaliseSequenceLogo;
1381 * returns a new array with all annotation involving this group
1383 public AlignmentAnnotation[] getAlignmentAnnotation()
1385 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1387 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1388 synchronized (sequences)
1390 for (SequenceI seq : sequences)
1392 AlignmentAnnotation[] aa = seq.getAnnotation();
1395 for (AlignmentAnnotation al : aa)
1397 if (al.groupRef == this)
1404 if (consensus != null)
1406 annot.add(consensus);
1408 if (conservation != null)
1410 annot.add(conservation);
1413 return annot.toArray(new AlignmentAnnotation[0]);
1417 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1419 return AlignmentAnnotation.findAnnotation(
1420 Arrays.asList(getAlignmentAnnotation()), calcId);
1424 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1425 String calcId, String label)
1427 return AlignmentAnnotation.findAnnotations(
1428 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1432 * Answer true if any annotation matches the calcId passed in (if not null).
1437 public boolean hasAnnotation(String calcId)
1439 return AlignmentAnnotation
1440 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1444 * Remove all sequences from the group (leaving other properties unchanged).
1448 synchronized (sequences)
1450 int before = sequences.size();
1452 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1458 * Sets the alignment or group context for this group, and whether it is
1459 * defined as a group
1462 * the context for the group
1464 * whether the group is defined on the alignment or is just a
1466 * @throws IllegalArgumentException
1467 * if setting the context would result in a circular reference chain
1469 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1472 this.isDefined = defined;
1476 * Sets the alignment or group context for this group
1479 * the context for the group
1480 * @throws IllegalArgumentException
1481 * if setting the context would result in a circular reference chain
1483 public void setContext(AnnotatedCollectionI ctx)
1485 AnnotatedCollectionI ref = ctx;
1488 if (ref == this || ref.getContext() == ctx)
1490 throw new IllegalArgumentException(
1491 "Circular reference in SequenceGroup.context");
1493 ref = ref.getContext();
1501 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1504 public AnnotatedCollectionI getContext()
1509 public boolean isDefined()
1514 public void setColourScheme(ColourSchemeI scheme)
1518 cs = new ResidueShader();
1520 cs.setColourScheme(scheme);
1523 public void setGroupColourScheme(ResidueShaderI scheme)
1528 public ColourSchemeI getColourScheme()
1530 return cs == null ? null : cs.getColourScheme();
1533 public ResidueShaderI getGroupColourScheme()
1539 public boolean isNucleotide()
1541 if (context != null)
1543 return context.isNucleotide();
1550 * @return true if seq is a member of the group
1553 public boolean contains(SequenceI seq1)
1555 return sequences.contains(seq1);
1561 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1563 public boolean contains(SequenceI seq, int apos)
1565 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1568 public boolean isShowInformationHistogram()
1570 return hmmShowHistogram;
1573 public void setShowInformationHistogram(boolean state)
1575 if (hmmShowHistogram != state && hmmInformation != null)
1577 this.hmmShowHistogram = state;
1578 // recalcConservation(); TODO don't know what to do here next
1580 this.hmmShowHistogram = state;
1583 public boolean isShowHMMSequenceLogo()
1585 return hmmShowSequenceLogo;
1588 public void setShowHMMSequenceLogo(boolean state)
1590 hmmShowSequenceLogo = state;
1593 public boolean isNormaliseHMMSequenceLogo()
1595 return hmmNormaliseSequenceLogo;
1598 public void setNormaliseHMMSequenceLogo(boolean state)
1600 hmmNormaliseSequenceLogo = state;
1604 public SequenceI getHmmConsensus()
1606 return hmmConsensus;
1610 public void setHmmConsensus(SequenceI hmmSeq)
1612 this.hmmConsensus = hmmSeq;
1615 public ProfilesI getConsensusData()
1617 return consensusProfiles;
1620 public ProfilesI getHmmProfiles()
1625 public void setHmmProfiles(ProfilesI hmmProfiles)
1627 this.hmmProfiles = hmmProfiles;