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 if (seq.getDatasetSequence() != null)
288 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
291 if (seq.getAnnotation() != null)
293 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
294 // Only copy annotation that is either a score or referenced by the
295 // alignment's annotation vector
296 for (int a = 0; a < seq.getAnnotation().length; a++)
298 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
301 boolean found = false;
302 for (int pos = 0; pos < alann.length; pos++)
304 if (alann[pos] == tocopy)
315 AlignmentAnnotation newannot = new AlignmentAnnotation(
316 seq.getAnnotation()[a]);
317 newannot.restrict(startRes, endRes);
318 newannot.setSequenceRef(seqs[ipos]);
319 newannot.adjustForAlignment();
320 seqs[ipos].addAlignmentAnnotation(newannot);
330 if (iSize != inorder.length)
332 SequenceI[] nseqs = new SequenceI[iSize];
333 System.arraycopy(seqs, 0, nseqs, 0, iSize);
341 * If sequence ends in gaps, the end residue can be correctly calculated here
347 public int findEndRes(SequenceI seq)
352 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
354 ch = seq.getCharAt(j);
355 if (!jalview.util.Comparison.isGap((ch)))
363 eres += seq.getStart() - 1;
370 public List<SequenceI> getSequences()
376 public List<SequenceI> getSequences(
377 Map<SequenceI, SequenceCollectionI> hiddenReps)
379 if (hiddenReps == null)
381 // TODO: need a synchronizedCollection here ?
386 List<SequenceI> allSequences = new ArrayList<>();
387 for (SequenceI seq : sequences)
389 allSequences.add(seq);
390 if (hiddenReps.containsKey(seq))
392 SequenceCollectionI hsg = hiddenReps.get(seq);
393 for (SequenceI seq2 : hsg.getSequences())
395 if (seq2 != seq && !allSequences.contains(seq2))
397 allSequences.add(seq2);
407 public SequenceI[] getSequencesAsArray(
408 Map<SequenceI, SequenceCollectionI> map)
410 List<SequenceI> tmp = getSequences(map);
415 return tmp.toArray(new SequenceI[tmp.size()]);
424 * @return DOCUMENT ME!
426 public boolean adjustForRemoveLeft(int col)
428 // return value is true if the group still exists
431 startRes = startRes - col;
436 endRes = endRes - col;
438 if (startRes > endRes)
445 // must delete this group!!
458 * @return DOCUMENT ME!
460 public boolean adjustForRemoveRight(int col)
479 * @return DOCUMENT ME!
481 public String getName()
486 public String getDescription()
497 public void setName(String name)
500 // TODO: URGENT: update dependent objects (annotation row)
503 public void setDescription(String desc)
511 * @return DOCUMENT ME!
513 public Conservation getConservation()
515 return conservationData;
524 public void setConservation(Conservation c)
526 conservationData = c;
530 * Add s to this sequence group. If aligment sequence is already contained in
531 * group, it will not be added again, but recalculation may happen if the flag
535 * alignment sequence to be added
537 * true means Group's conservation should be recalculated
539 public void addSequence(SequenceI s, boolean recalc)
541 synchronized (sequences)
543 if (s != null && !sequences.contains(s))
546 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
547 sequences.size() - 1, sequences.size());
552 recalcConservation();
558 * Max Gaps Threshold (percent) for performing a conservation calculation
560 private int consPercGaps = 25;
563 * @return Max Gaps Threshold for performing a conservation calculation
565 public int getConsPercGaps()
571 * set Max Gaps Threshold (percent) for performing a conservation calculation
573 * @param consPercGaps
575 public void setConsPercGaps(int consPercGaps)
577 this.consPercGaps = consPercGaps;
581 * calculate residue conservation and colourschemes for group - but only if
582 * necessary. returns true if the calculation resulted in a visible change to
585 public boolean recalcConservation()
587 return recalcAnnotations(false);
591 * Recalculates column consensus, conservation, and HMM annotation for the
592 * group (as applicable). Returns true if the calculation resulted in a
593 * visible change to group.
596 * when set, colourschemes for this group are not refreshed after
599 public boolean recalcAnnotations(boolean defer)
601 if (cs == null && consensus == null && conservation == null
602 && hmmInformation == null)
606 // TODO: try harder to detect changes in state in order to minimise
607 // recalculation effort
611 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
612 endRes + 1, showSequenceLogo);
613 if (hmmInformation != null)
615 HiddenMarkovModel hmm = hmmInformation.sequenceRef.getHMM();
617 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
618 (endRes + 1) - startRes, startRes, endRes + 1,
619 hmmIgnoreBelowBackground, hmmUseInfoLetterHeight);
620 _updateInformationRow(info);
623 if (consensus != null)
625 _updateConsensusRow(cnsns, sequences.size());
630 cs.setConsensus(cnsns);
634 if ((conservation != null)
635 || (cs != null && cs.conservationApplied()))
637 Conservation c = new Conservation(groupName, sequences, startRes,
640 c.verdict(false, consPercGaps);
641 if (conservation != null)
643 _updateConservationRow(c);
647 if (cs.conservationApplied())
649 cs.setConservation(c);
652 // eager update - will cause a refresh of overview regardless
655 if (cs != null && !defer)
657 // TODO: JAL-2034 should cs.alignmentChanged modify return state
658 cs.alignmentChanged(context != null ? context : this, null);
665 } catch (java.lang.OutOfMemoryError err)
668 System.out.println("Out of memory loading groups: " + err);
673 private void _updateConservationRow(Conservation c)
675 if (conservation == null)
680 conservation.label = "Conservation for " + getName();
681 conservation.description = "Conservation for group " + getName()
682 + " less than " + consPercGaps + "% gaps";
683 // preserve width if already set
684 int aWidth = (conservation.annotations != null)
685 ? (endRes < conservation.annotations.length
686 ? conservation.annotations.length
689 conservation.annotations = null;
690 conservation.annotations = new Annotation[aWidth]; // should be alignment
692 c.completeAnnotations(conservation, null, startRes, endRes + 1);
695 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
697 if (consensus == null)
701 consensus.label = "Consensus for " + getName();
702 consensus.description = "Percent Identity";
703 consensusProfiles = cnsns;
704 // preserve width if already set
705 int aWidth = (consensus.annotations != null)
706 ? (endRes < consensus.annotations.length
707 ? consensus.annotations.length
710 consensus.annotations = null;
711 consensus.annotations = new Annotation[aWidth]; // should be alignment width
713 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
714 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
717 // ignoreGapsInConsensusCalculation);
721 * Recalculates the information content on the HMM annotation
725 private void _updateInformationRow(ProfilesI cnsns)
727 if (hmmInformation == null)
729 createInformationAnnotation();
731 hmmInformation.description = MessageManager
732 .getString("label.information_description");
733 setHmmProfiles(cnsns);
734 // preserve width if already set
735 int aWidth = (hmmInformation.annotations != null)
736 ? (endRes < hmmInformation.annotations.length
737 ? hmmInformation.annotations.length : endRes + 1)
739 hmmInformation.annotations = null;
740 hmmInformation.annotations = new Annotation[aWidth]; // should be alignment
742 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
743 AAFrequency.completeInformation(hmmInformation, cnsns, startRes,
749 * sequence to either add or remove from group
751 * flag passed to delete/addSequence to indicate if group properties
752 * should be recalculated
754 public void addOrRemove(SequenceI s, boolean recalc)
756 synchronized (sequences)
758 if (sequences.contains(s))
760 deleteSequence(s, recalc);
764 addSequence(s, recalc);
775 * true means recalculate conservation
777 public void deleteSequence(SequenceI s, boolean recalc)
779 synchronized (sequences)
782 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
783 sequences.size() + 1, sequences.size());
787 recalcConservation();
795 * @return the first column selected by this group. Runs from 0<=i<N_cols
798 public int getStartRes()
805 * @return the groups last selected column. Runs from 0<=i<N_cols
808 public int getEndRes()
814 * Set the first column selected by this group. Runs from 0<=i<N_cols
818 public void setStartRes(int i)
820 int before = startRes;
822 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
826 * Set the groups last selected column. Runs from 0<=i<N_cols
830 public void setEndRes(int i)
834 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
838 * @return number of sequences in group
842 return sequences.size();
847 * @return the ith sequence
849 public SequenceI getSequenceAt(int i)
851 return sequences.get(i);
858 public void setColourText(boolean state)
866 * @return DOCUMENT ME!
868 public boolean getColourText()
879 public void setDisplayText(boolean state)
887 * @return DOCUMENT ME!
889 public boolean getDisplayText()
900 public void setDisplayBoxes(boolean state)
902 displayBoxes = state;
908 * @return DOCUMENT ME!
910 public boolean getDisplayBoxes()
916 * computes the width of current set of sequences and returns it
918 * @return DOCUMENT ME!
921 public int getWidth()
923 synchronized (sequences)
925 // MC This needs to get reset when characters are inserted and deleted
926 boolean first = true;
927 for (SequenceI seq : sequences)
929 if (first || seq.getLength() > width)
931 width = seq.getLength();
945 public void setOutlineColour(Color c)
953 * @return DOCUMENT ME!
955 public Color getOutlineColour()
957 return outlineColour;
962 * returns the sequences in the group ordered by the ordering given by al.
963 * this used to return an array with null entries regardless, new behaviour is
964 * below. TODO: verify that this does not affect use in applet or application
968 * @return SequenceI[] intersection of sequences in group with al, ordered by
969 * al, or null if group does not intersect with al
971 public SequenceI[] getSequencesInOrder(AlignmentI al)
973 return getSequencesInOrder(al, true);
977 * return an array representing the intersection of the group with al,
978 * optionally returning an array the size of al.getHeight() where nulls mark
979 * the non-intersected sequences
983 * @return null or array
985 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
987 synchronized (sequences)
989 int sSize = sequences.size();
990 int alHeight = al.getHeight();
992 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
995 for (int i = 0; i < alHeight && index < sSize; i++)
997 if (sequences.contains(al.getSequenceAt(i)))
999 seqs[(trim) ? index : i] = al.getSequenceAt(i);
1011 if (index < seqs.length)
1013 SequenceI[] dummy = seqs;
1014 seqs = new SequenceI[index];
1015 while (--index >= 0)
1017 seqs[index] = dummy[index];
1018 dummy[index] = null;
1026 * @return the idColour
1028 public Color getIdColour()
1035 * the idColour to set
1037 public void setIdColour(Color idColour)
1039 this.idColour = idColour;
1043 * @return the representative sequence for this group
1046 public SequenceI getSeqrep()
1052 * set the representative sequence for this group. Note - this affects the
1053 * interpretation of the Hidereps attribute.
1056 * the seqrep to set (null means no sequence representative)
1059 public void setSeqrep(SequenceI seqrep)
1061 this.seqrep = seqrep;
1066 * @return true if group has a sequence representative
1069 public boolean hasSeqrep()
1071 return seqrep != null;
1075 * set visibility of sequences covered by (if no sequence representative is
1076 * defined) or represented by this group.
1080 public void setHidereps(boolean visibility)
1082 hidereps = visibility;
1087 * @return true if sequences represented (or covered) by this group should be
1090 public boolean isHidereps()
1096 * set intended visibility of columns covered by this group
1100 public void setHideCols(boolean visibility)
1102 hidecols = visibility;
1107 * @return true if columns covered by group should be hidden
1109 public boolean isHideCols()
1115 * create a new sequence group from the intersection of this group with an
1116 * alignment Hashtable of hidden representatives
1122 * @return new group containing sequences common to this group and alignment
1124 public SequenceGroup intersect(AlignmentI alignment,
1125 Map<SequenceI, SequenceCollectionI> map)
1127 SequenceGroup sgroup = new SequenceGroup(this);
1128 SequenceI[] insect = getSequencesInOrder(alignment);
1129 sgroup.sequences = new ArrayList<>();
1130 for (int s = 0; insect != null && s < insect.length; s++)
1132 if (map == null || map.containsKey(insect[s]))
1134 sgroup.sequences.add(insect[s]);
1141 * @return the showUnconserved
1143 public boolean getShowNonconserved()
1145 return showNonconserved;
1149 * @param showNonconserved
1150 * the showUnconserved to set
1152 public void setShowNonconserved(boolean displayNonconserved)
1154 this.showNonconserved = displayNonconserved;
1158 * set this alignmentAnnotation object as the one used to render consensus
1163 public void setConsensus(AlignmentAnnotation aan)
1165 if (consensus == null)
1173 * @return automatically calculated consensus row note: the row is a stub if a
1174 * consensus calculation has not yet been performed on the group
1176 public AlignmentAnnotation getConsensus()
1178 // TODO get or calculate and get consensus annotation row for this group
1179 int aWidth = this.getWidth();
1187 if (consensus == null)
1189 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1190 100f, AlignmentAnnotation.BAR_GRAPH);
1191 consensus.hasText = true;
1192 consensus.autoCalculated = true;
1193 consensus.groupRef = this;
1194 consensus.label = "Consensus for " + getName();
1195 consensus.description = "Percent Identity";
1201 * Creates the Hidden Markov Model annotation for this group
1203 void createInformationAnnotation()
1205 hmmInformation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1206 6.25f, AlignmentAnnotation.BAR_GRAPH);
1207 hmmInformation.hasText = true;
1208 hmmInformation.autoCalculated = false;
1209 hmmInformation.groupRef = this;
1210 hmmInformation.label = getName();
1211 hmmInformation.description = MessageManager
1212 .getString("label.information_description");
1213 hmmInformation.setCalcId(InformationThread.HMM_CALC_ID);
1217 * set this alignmentAnnotation object as the one used to render consensus
1222 public void setConservationRow(AlignmentAnnotation aan)
1224 if (conservation == null)
1231 * get the conservation annotation row for this group
1233 * @return autoCalculated annotation row
1235 public AlignmentAnnotation getConservationRow()
1237 if (conservation == null)
1239 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1240 11f, AlignmentAnnotation.BAR_GRAPH);
1243 conservation.hasText = true;
1244 conservation.autoCalculated = true;
1245 conservation.groupRef = this;
1246 conservation.label = "Conservation for " + getName();
1247 conservation.description = "Conservation for group " + getName()
1248 + " less than " + consPercGaps + "% gaps";
1249 return conservation;
1254 * @return true if annotation rows have been instantiated for this group
1256 public boolean hasAnnotationRows()
1258 return consensus != null || conservation != null;
1261 public SequenceI getConsensusSeq()
1264 StringBuffer seqs = new StringBuffer();
1265 for (int i = 0; i < consensus.annotations.length; i++)
1267 if (consensus.annotations[i] != null)
1269 String desc = consensus.annotations[i].description;
1270 if (desc.length() > 1 && desc.charAt(0) == '[')
1272 seqs.append(desc.charAt(1));
1276 seqs.append(consensus.annotations[i].displayCharacter);
1281 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1283 sq.setDescription("Percentage Identity Consensus "
1284 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1288 public void setIgnoreGapsConsensus(boolean state)
1290 if (this.ignoreGapsInConsensus != state && consensus != null)
1292 ignoreGapsInConsensus = state;
1293 recalcConservation();
1295 ignoreGapsInConsensus = state;
1298 public boolean isIgnoreGapsConsensus()
1300 return ignoreGapsInConsensus;
1303 public void setIgnoreBelowBackground(boolean state)
1305 hmmIgnoreBelowBackground = state;
1308 public boolean isIgnoreBelowBackground()
1310 return hmmIgnoreBelowBackground;
1313 public void setInfoLetterHeight(boolean state)
1315 hmmUseInfoLetterHeight = state;
1318 public boolean isUseInfoLetterHeight()
1320 return hmmUseInfoLetterHeight;
1324 * @param showSequenceLogo
1325 * indicates if a sequence logo is shown for consensus annotation
1327 public void setshowSequenceLogo(boolean showSequenceLogo)
1329 // TODO: decouple calculation from settings update
1330 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1332 this.showSequenceLogo = showSequenceLogo;
1333 recalcConservation();
1335 this.showSequenceLogo = showSequenceLogo;
1340 * @param showConsHist
1341 * flag indicating if the consensus histogram for this group should
1344 public void setShowConsensusHistogram(boolean showConsHist)
1347 if (showConsensusHistogram != showConsHist && consensus != null)
1349 this.showConsensusHistogram = showConsHist;
1350 recalcConservation();
1352 this.showConsensusHistogram = showConsHist;
1356 * @return the showConsensusHistogram
1358 public boolean isShowConsensusHistogram()
1360 return showConsensusHistogram;
1364 * set flag indicating if logo should be normalised when rendered
1368 public void setNormaliseSequenceLogo(boolean norm)
1370 normaliseSequenceLogo = norm;
1373 public boolean isNormaliseSequenceLogo()
1375 return normaliseSequenceLogo;
1380 * returns a new array with all annotation involving this group
1382 public AlignmentAnnotation[] getAlignmentAnnotation()
1384 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1386 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1387 synchronized (sequences)
1389 for (SequenceI seq : sequences)
1391 AlignmentAnnotation[] aa = seq.getAnnotation();
1394 for (AlignmentAnnotation al : aa)
1396 if (al.groupRef == this)
1403 if (consensus != null)
1405 annot.add(consensus);
1407 if (conservation != null)
1409 annot.add(conservation);
1412 return annot.toArray(new AlignmentAnnotation[0]);
1416 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1418 return AlignmentAnnotation.findAnnotation(
1419 Arrays.asList(getAlignmentAnnotation()), calcId);
1423 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1424 String calcId, String label)
1426 return AlignmentAnnotation.findAnnotations(
1427 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1431 * Answer true if any annotation matches the calcId passed in (if not null).
1436 public boolean hasAnnotation(String calcId)
1438 return AlignmentAnnotation
1439 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1443 * Remove all sequences from the group (leaving other properties unchanged).
1447 synchronized (sequences)
1449 int before = sequences.size();
1451 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1457 * Sets the alignment or group context for this group, and whether it is
1458 * defined as a group
1461 * the context for the group
1463 * whether the group is defined on the alignment or is just a
1465 * @throws IllegalArgumentException
1466 * if setting the context would result in a circular reference chain
1468 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1471 this.isDefined = defined;
1475 * Sets the alignment or group context for this group
1478 * the context for the group
1479 * @throws IllegalArgumentException
1480 * if setting the context would result in a circular reference chain
1482 public void setContext(AnnotatedCollectionI ctx)
1484 AnnotatedCollectionI ref = ctx;
1487 if (ref == this || ref.getContext() == ctx)
1489 throw new IllegalArgumentException(
1490 "Circular reference in SequenceGroup.context");
1492 ref = ref.getContext();
1500 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1503 public AnnotatedCollectionI getContext()
1508 public boolean isDefined()
1513 public void setColourScheme(ColourSchemeI scheme)
1517 cs = new ResidueShader();
1519 cs.setColourScheme(scheme);
1522 public void setGroupColourScheme(ResidueShaderI scheme)
1527 public ColourSchemeI getColourScheme()
1529 return cs == null ? null : cs.getColourScheme();
1532 public ResidueShaderI getGroupColourScheme()
1538 public boolean isNucleotide()
1540 if (context != null)
1542 return context.isNucleotide();
1549 * @return true if seq is a member of the group
1552 public boolean contains(SequenceI seq1)
1554 return sequences.contains(seq1);
1560 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1562 public boolean contains(SequenceI seq, int apos)
1564 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1567 public boolean isShowInformationHistogram()
1569 return hmmShowHistogram;
1572 public void setShowInformationHistogram(boolean state)
1574 if (hmmShowHistogram != state && hmmInformation != null)
1576 this.hmmShowHistogram = state;
1577 // recalcConservation(); TODO don't know what to do here next
1579 this.hmmShowHistogram = state;
1582 public boolean isShowHMMSequenceLogo()
1584 return hmmShowSequenceLogo;
1587 public void setShowHMMSequenceLogo(boolean state)
1589 hmmShowSequenceLogo = state;
1592 public boolean isNormaliseHMMSequenceLogo()
1594 return hmmNormaliseSequenceLogo;
1597 public void setNormaliseHMMSequenceLogo(boolean state)
1599 hmmNormaliseSequenceLogo = state;
1603 public SequenceI getHmmConsensus()
1605 return hmmConsensus;
1609 public void setHmmConsensus(SequenceI hmmSeq)
1611 this.hmmConsensus = hmmSeq;
1614 public ProfilesI getConsensusData()
1616 return consensusProfiles;
1619 public ProfilesI getHmmProfiles()
1624 public void setHmmProfiles(ProfilesI hmmProfiles)
1626 this.hmmProfiles = hmmProfiles;