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
49 // subclass of ViewportProperties similarly to ViewportRanges. Done here as
50 // quick fix for JAL-2665
51 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
53 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
56 public void addPropertyChangeListener(PropertyChangeListener listener)
58 changeSupport.addPropertyChangeListener(listener);
61 public void removePropertyChangeListener(PropertyChangeListener listener)
63 changeSupport.removePropertyChangeListener(listener);
65 // end of event notification functionality initialisation
71 Conservation conserve;
73 boolean displayBoxes = true;
75 boolean displayText = true;
77 boolean colourText = false;
80 * True if the group is defined as a group on the alignment, false if it is
83 boolean isDefined = false;
86 * after Olivier's non-conserved only character display
88 boolean showNonconserved = false;
93 private List<SequenceI> sequences = new ArrayList<>();
96 * representative sequence for this group (if any)
98 private SequenceI seqrep = null;
103 * Colourscheme applied to group if any
105 public ResidueShaderI cs;
107 // start column (base 0)
110 // end column (base 0)
113 public Color outlineColour = Color.black;
115 public Color idColour = null;
117 public int thresholdTextColour = 0;
119 public Color textColour = Color.black;
121 public Color textColour2 = Color.white;
124 * consensus calculation property
126 private boolean ignoreGapsInConsensus = true;
128 private boolean ignoreBelowBackground = true;
130 private boolean infoLetterHeight = false;
133 * consensus calculation property
135 private boolean showSequenceLogo = false;
138 * flag indicating if logo should be rendered normalised
140 private boolean normaliseSequenceLogo;
143 * visibility of rows or represented rows covered by group
145 private boolean hidereps = false;
148 * visibility of columns intersecting this group
150 private boolean hidecols = false;
152 AlignmentAnnotation consensus = null;
154 AlignmentAnnotation conservation = null;
156 AlignmentAnnotation information = null;
158 private boolean showConsensusHistogram;
160 private AnnotatedCollectionI context;
162 private boolean showHMMSequenceLogo;
164 private boolean normaliseHMMSequenceLogo;
166 private boolean showInformationHistogram;
169 * Creates a new SequenceGroup object.
171 public SequenceGroup()
173 groupName = "JGroup:" + this.hashCode();
174 cs = new ResidueShader();
178 * Creates a new SequenceGroup object.
183 * @param displayBoxes
187 * first column of group
189 * last column of group
191 public SequenceGroup(List<SequenceI> sequences, String groupName,
192 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
193 boolean colourText, int start, int end)
196 this.sequences = sequences;
197 this.groupName = groupName;
198 this.displayBoxes = displayBoxes;
199 this.displayText = displayText;
200 this.colourText = colourText;
201 this.cs = new ResidueShader(scheme);
204 recalcConservation();
212 public SequenceGroup(SequenceGroup seqsel)
217 sequences = new ArrayList<>();
218 sequences.addAll(seqsel.sequences);
219 if (seqsel.groupName != null)
221 groupName = new String(seqsel.groupName);
223 displayBoxes = seqsel.displayBoxes;
224 displayText = seqsel.displayText;
225 colourText = seqsel.colourText;
226 startRes = seqsel.startRes;
227 endRes = seqsel.endRes;
228 cs = new ResidueShader((ResidueShader) seqsel.cs);
229 if (seqsel.description != null)
231 description = new String(seqsel.description);
233 hidecols = seqsel.hidecols;
234 hidereps = seqsel.hidereps;
235 showNonconserved = seqsel.showNonconserved;
236 showSequenceLogo = seqsel.showSequenceLogo;
237 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
238 showConsensusHistogram = seqsel.showConsensusHistogram;
239 showHMMSequenceLogo = seqsel.showHMMSequenceLogo;
240 normaliseHMMSequenceLogo = seqsel.normaliseHMMSequenceLogo;
241 showInformationHistogram = seqsel.showInformationHistogram;
242 idColour = seqsel.idColour;
243 outlineColour = seqsel.outlineColour;
244 seqrep = seqsel.seqrep;
245 textColour = seqsel.textColour;
246 textColour2 = seqsel.textColour2;
247 thresholdTextColour = seqsel.thresholdTextColour;
248 width = seqsel.width;
249 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
250 ignoreBelowBackground = seqsel.ignoreBelowBackground;
251 infoLetterHeight = seqsel.infoLetterHeight;
252 if (seqsel.conserve != null)
254 recalcConservation(); // safer than
255 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
260 public boolean isShowSequenceLogo()
262 return showSequenceLogo;
265 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
267 int iSize = sequences.size();
268 SequenceI[] seqs = new SequenceI[iSize];
269 SequenceI[] inorder = getSequencesInOrder(align);
271 for (int i = 0, ipos = 0; i < inorder.length; i++)
273 SequenceI seq = inorder[i];
275 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
276 if (seqs[ipos] != null)
278 seqs[ipos].setDescription(seq.getDescription());
279 seqs[ipos].setDBRefs(seq.getDBRefs());
280 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
281 seqs[ipos].setIsHMMConsensusSequence(seq.isHMMConsensusSequence());
282 if (seq.getDatasetSequence() != null)
284 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
287 if (seq.getAnnotation() != null)
289 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
290 // Only copy annotation that is either a score or referenced by the
291 // alignment's annotation vector
292 for (int a = 0; a < seq.getAnnotation().length; a++)
294 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
297 boolean found = false;
298 for (int pos = 0; pos < alann.length; pos++)
300 if (alann[pos] == tocopy)
311 AlignmentAnnotation newannot = new AlignmentAnnotation(
312 seq.getAnnotation()[a]);
313 newannot.restrict(startRes, endRes);
314 newannot.setSequenceRef(seqs[ipos]);
315 newannot.adjustForAlignment();
316 seqs[ipos].addAlignmentAnnotation(newannot);
326 if (iSize != inorder.length)
328 SequenceI[] nseqs = new SequenceI[iSize];
329 System.arraycopy(seqs, 0, nseqs, 0, iSize);
337 * If sequence ends in gaps, the end residue can be correctly calculated here
343 public int findEndRes(SequenceI seq)
348 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
350 ch = seq.getCharAt(j);
351 if (!jalview.util.Comparison.isGap((ch)))
359 eres += seq.getStart() - 1;
366 public List<SequenceI> getSequences()
372 public List<SequenceI> getSequences(
373 Map<SequenceI, SequenceCollectionI> hiddenReps)
375 if (hiddenReps == null)
377 // TODO: need a synchronizedCollection here ?
382 List<SequenceI> allSequences = new ArrayList<>();
383 for (SequenceI seq : sequences)
385 allSequences.add(seq);
386 if (hiddenReps.containsKey(seq))
388 SequenceCollectionI hsg = hiddenReps.get(seq);
389 for (SequenceI seq2 : hsg.getSequences())
391 if (seq2 != seq && !allSequences.contains(seq2))
393 allSequences.add(seq2);
403 public SequenceI[] getSequencesAsArray(
404 Map<SequenceI, SequenceCollectionI> map)
406 List<SequenceI> tmp = getSequences(map);
411 return tmp.toArray(new SequenceI[tmp.size()]);
420 * @return DOCUMENT ME!
422 public boolean adjustForRemoveLeft(int col)
424 // return value is true if the group still exists
427 startRes = startRes - col;
432 endRes = endRes - col;
434 if (startRes > endRes)
441 // must delete this group!!
454 * @return DOCUMENT ME!
456 public boolean adjustForRemoveRight(int col)
475 * @return DOCUMENT ME!
477 public String getName()
482 public String getDescription()
493 public void setName(String name)
496 // TODO: URGENT: update dependent objects (annotation row)
499 public void setDescription(String desc)
507 * @return DOCUMENT ME!
509 public Conservation getConservation()
520 public void setConservation(Conservation c)
526 * Add s to this sequence group. If aligment sequence is already contained in
527 * group, it will not be added again, but recalculation may happen if the flag
531 * alignment sequence to be added
533 * true means Group's conservation should be recalculated
535 public void addSequence(SequenceI s, boolean recalc)
537 synchronized (sequences)
539 if (s != null && !sequences.contains(s))
542 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
543 sequences.size() - 1, sequences.size());
548 recalcConservation();
554 * Max Gaps Threshold (percent) for performing a conservation calculation
556 private int consPercGaps = 25;
559 * @return Max Gaps Threshold for performing a conservation calculation
561 public int getConsPercGaps()
567 * set Max Gaps Threshold (percent) for performing a conservation calculation
569 * @param consPercGaps
571 public void setConsPercGaps(int consPercGaps)
573 this.consPercGaps = consPercGaps;
577 * calculate residue conservation and colourschemes for group - but only if
578 * necessary. returns true if the calculation resulted in a visible change to
581 public boolean recalcConservation()
583 return recalcConservation(false);
587 * calculate residue conservation for group - but only if necessary. returns
588 * true if the calculation resulted in a visible change to group
591 * when set, colourschemes for this group are not refreshed after
594 public boolean recalcConservation(boolean defer)
596 if (cs == null && consensus == null && conservation == null
597 && information == null)
601 // TODO: try harder to detect changes in state in order to minimise
602 // recalculation effort
606 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
607 endRes + 1, showSequenceLogo);
608 if (information != null)
610 HiddenMarkovModel hmm = information.sequenceRef.getHMM();
612 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
613 (endRes + 1) - startRes, startRes, endRes + 1,
614 showHMMSequenceLogo, ignoreBelowBackground,
616 _updateInformationRow(info, sequences.size());
619 if (consensus != null)
621 _updateConsensusRow(cnsns, sequences.size());
626 cs.setConsensus(cnsns);
630 if ((conservation != null)
631 || (cs != null && cs.conservationApplied()))
633 Conservation c = new Conservation(groupName, sequences, startRes,
636 c.verdict(false, consPercGaps);
637 if (conservation != null)
639 _updateConservationRow(c);
643 if (cs.conservationApplied())
645 cs.setConservation(c);
648 // eager update - will cause a refresh of overview regardless
651 if (cs != null && !defer)
653 // TODO: JAL-2034 should cs.alignmentChanged modify return state
654 cs.alignmentChanged(context != null ? context : this, null);
661 } catch (java.lang.OutOfMemoryError err)
664 System.out.println("Out of memory loading groups: " + err);
669 private void _updateConservationRow(Conservation c)
671 if (conservation == null)
676 conservation.label = "Conservation for " + getName();
677 conservation.description = "Conservation for group " + getName()
678 + " less than " + consPercGaps + "% gaps";
679 // preserve width if already set
680 int aWidth = (conservation.annotations != null)
681 ? (endRes < conservation.annotations.length
682 ? conservation.annotations.length
685 conservation.annotations = null;
686 conservation.annotations = new Annotation[aWidth]; // should be alignment
688 c.completeAnnotations(conservation, null, startRes, endRes + 1);
691 public ProfilesI consensusData = null;
693 public ProfilesI informationData = null;
695 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
697 if (consensus == null)
701 consensus.label = "Consensus for " + getName();
702 consensus.description = "Percent Identity";
703 consensusData = 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.
726 private void _updateInformationRow(ProfilesI cnsns, long nseq)
728 if (information == null)
732 information.description = MessageManager
733 .getString("label.information_description");
734 informationData = cnsns;
735 // preserve width if already set
736 int aWidth = (information.annotations != null)
737 ? (endRes < information.annotations.length
738 ? information.annotations.length : endRes + 1)
740 information.annotations = null;
741 information.annotations = new Annotation[aWidth]; // should be alignment
743 information.setCalcId(InformationThread.HMM_CALC_ID);
744 AAFrequency.completeInformation(information, cnsns, startRes,
745 endRes + 1, nseq, 0f);
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 * Answers the Hidden Markov Model annotation for this group (creating it if
1207 public AlignmentAnnotation getInformation()
1209 if (information == null)
1211 information = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1212 6.25f, AlignmentAnnotation.BAR_GRAPH);
1213 information.hasText = true;
1214 information.autoCalculated = false;
1215 information.groupRef = this;
1216 information.label = getName();
1217 information.description = MessageManager
1218 .getString("label.information_description");
1219 information.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 if (consensus.annotations[i].description.charAt(0) == '[')
1279 seqs.append(consensus.annotations[i].description.charAt(1));
1283 seqs.append(consensus.annotations[i].displayCharacter);
1288 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1290 sq.setDescription("Percentage Identity Consensus "
1291 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1295 public void setIgnoreGapsConsensus(boolean state)
1297 if (this.ignoreGapsInConsensus != state && consensus != null)
1299 ignoreGapsInConsensus = state;
1300 recalcConservation();
1302 ignoreGapsInConsensus = state;
1305 public boolean getIgnoreGapsConsensus()
1307 return ignoreGapsInConsensus;
1310 public void setIgnoreBelowBackground(boolean state)
1312 if (this.ignoreBelowBackground != state)
1314 ignoreBelowBackground = state;
1316 ignoreBelowBackground = state;
1319 public boolean getIgnoreBelowBackground()
1321 return ignoreBelowBackground;
1324 public void setInfoLetterHeight(boolean state)
1326 if (this.infoLetterHeight != state)
1328 infoLetterHeight = state;
1330 infoLetterHeight = state;
1333 public boolean getInfoLetterHeight()
1335 return infoLetterHeight;
1339 * @param showSequenceLogo
1340 * indicates if a sequence logo is shown for consensus annotation
1342 public void setshowSequenceLogo(boolean showSequenceLogo)
1344 // TODO: decouple calculation from settings update
1345 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1347 this.showSequenceLogo = showSequenceLogo;
1348 recalcConservation();
1350 this.showSequenceLogo = showSequenceLogo;
1355 * @param showConsHist
1356 * flag indicating if the consensus histogram for this group should
1359 public void setShowConsensusHistogram(boolean showConsHist)
1362 if (showConsensusHistogram != showConsHist && consensus != null)
1364 this.showConsensusHistogram = showConsHist;
1365 recalcConservation();
1367 this.showConsensusHistogram = showConsHist;
1371 * @return the showConsensusHistogram
1373 public boolean isShowConsensusHistogram()
1375 return showConsensusHistogram;
1379 * set flag indicating if logo should be normalised when rendered
1383 public void setNormaliseSequenceLogo(boolean norm)
1385 normaliseSequenceLogo = norm;
1388 public boolean isNormaliseSequenceLogo()
1390 return normaliseSequenceLogo;
1395 * returns a new array with all annotation involving this group
1397 public AlignmentAnnotation[] getAlignmentAnnotation()
1399 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1401 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1402 synchronized (sequences)
1404 for (SequenceI seq : sequences)
1406 AlignmentAnnotation[] aa = seq.getAnnotation();
1409 for (AlignmentAnnotation al : aa)
1411 if (al.groupRef == this)
1418 if (consensus != null)
1420 annot.add(consensus);
1422 if (conservation != null)
1424 annot.add(conservation);
1427 return annot.toArray(new AlignmentAnnotation[0]);
1431 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1433 return AlignmentAnnotation.findAnnotation(
1434 Arrays.asList(getAlignmentAnnotation()), calcId);
1438 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1439 String calcId, String label)
1441 return AlignmentAnnotation.findAnnotations(
1442 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1446 * Answer true if any annotation matches the calcId passed in (if not null).
1451 public boolean hasAnnotation(String calcId)
1453 return AlignmentAnnotation
1454 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1458 * Remove all sequences from the group (leaving other properties unchanged).
1462 synchronized (sequences)
1464 int before = sequences.size();
1466 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1472 * Sets the alignment or group context for this group, and whether it is
1473 * defined as a group
1476 * the context for the group
1478 * whether the group is defined on the alignment or is just a
1480 * @throws IllegalArgumentException
1481 * if setting the context would result in a circular reference chain
1483 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1486 this.isDefined = defined;
1490 * Sets the alignment or group context for this group
1493 * the context for the group
1494 * @throws IllegalArgumentException
1495 * if setting the context would result in a circular reference chain
1497 public void setContext(AnnotatedCollectionI ctx)
1499 AnnotatedCollectionI ref = ctx;
1502 if (ref == this || ref.getContext() == ctx)
1504 throw new IllegalArgumentException(
1505 "Circular reference in SequenceGroup.context");
1507 ref = ref.getContext();
1515 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1518 public AnnotatedCollectionI getContext()
1523 public boolean isDefined()
1528 public void setColourScheme(ColourSchemeI scheme)
1532 cs = new ResidueShader();
1534 cs.setColourScheme(scheme);
1537 public void setGroupColourScheme(ResidueShaderI scheme)
1542 public ColourSchemeI getColourScheme()
1544 return cs == null ? null : cs.getColourScheme();
1547 public ResidueShaderI getGroupColourScheme()
1553 public boolean isNucleotide()
1555 if (context != null)
1557 return context.isNucleotide();
1564 * @return true if seq is a member of the group
1567 public boolean contains(SequenceI seq1)
1569 return sequences.contains(seq1);
1575 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1577 public boolean contains(SequenceI seq, int apos)
1579 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1582 public boolean isShowInformationHistogram()
1584 return showInformationHistogram;
1587 public void setShowInformationHistogram(boolean state)
1589 if (showInformationHistogram != state && information != null)
1591 this.showInformationHistogram = state;
1592 // recalcConservation(); TODO don't know what to do here next
1594 this.showInformationHistogram = state;
1598 public boolean isShowHMMSequenceLogo()
1600 return showHMMSequenceLogo;
1603 public void setshowHMMSequenceLogo(boolean state)
1605 showHMMSequenceLogo = state;
1609 public boolean isNormaliseHMMSequenceLogo()
1611 return normaliseHMMSequenceLogo;
1614 public void setNormaliseHMMSequenceLogo(boolean state)
1616 normaliseSequenceLogo = state;
1620 * Returns all HMM consensus sequences. This will not return real sequences
1624 public List<SequenceI> getHMMConsensusSequences()
1626 List<SequenceI> seqs = new ArrayList<>();
1628 for (int position = 0; position < sequences.size(); position++)
1630 SequenceI seq = sequences.get(position);
1631 if (seq.isHMMConsensusSequence())