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;
30 import java.awt.Color;
31 import java.util.ArrayList;
32 import java.util.List;
36 * Collects a set contiguous ranges on a set of sequences
41 public class SequenceGroup implements AnnotatedCollectionI
47 Conservation conserve;
49 boolean displayBoxes = true;
51 boolean displayText = true;
53 boolean colourText = false;
56 * True if the group is defined as a group on the alignment, false if it is
59 boolean isDefined = false;
62 * after Olivier's non-conserved only character display
64 boolean showNonconserved = false;
69 private List<SequenceI> sequences = new ArrayList<>();
72 * representative sequence for this group (if any)
74 private SequenceI seqrep = null;
79 * Colourscheme applied to group if any
81 public ResidueShaderI cs;
83 // start column (base 0)
86 // end column (base 0)
89 public Color outlineColour = Color.black;
91 public Color idColour = null;
93 public int thresholdTextColour = 0;
95 public Color textColour = Color.black;
97 public Color textColour2 = Color.white;
100 * consensus calculation property
102 private boolean ignoreGapsInConsensus = true;
104 private boolean ignoreBelowBackground = true;
106 private boolean infoLetterHeight = false;
109 * consensus calculation property
111 private boolean showSequenceLogo = false;
114 * flag indicating if logo should be rendered normalised
116 private boolean normaliseSequenceLogo;
119 * visibility of rows or represented rows covered by group
121 private boolean hidereps = false;
124 * visibility of columns intersecting this group
126 private boolean hidecols = false;
128 AlignmentAnnotation consensus = null;
130 AlignmentAnnotation conservation = null;
132 AlignmentAnnotation information = null;
134 private boolean showConsensusHistogram;
136 private AnnotatedCollectionI context;
138 private boolean showHMMSequenceLogo;
140 private boolean normaliseHMMSequenceLogo;
142 private boolean showInformationHistogram;
145 * Creates a new SequenceGroup object.
147 public SequenceGroup()
149 groupName = "JGroup:" + this.hashCode();
150 cs = new ResidueShader();
154 * Creates a new SequenceGroup object.
159 * @param displayBoxes
163 * first column of group
165 * last column of group
167 public SequenceGroup(List<SequenceI> sequences, String groupName,
168 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
169 boolean colourText, int start, int end)
172 this.sequences = sequences;
173 this.groupName = groupName;
174 this.displayBoxes = displayBoxes;
175 this.displayText = displayText;
176 this.colourText = colourText;
177 this.cs = new ResidueShader(scheme);
180 recalcConservation();
188 public SequenceGroup(SequenceGroup seqsel)
193 sequences = new ArrayList<>();
194 sequences.addAll(seqsel.sequences);
195 if (seqsel.groupName != null)
197 groupName = new String(seqsel.groupName);
199 displayBoxes = seqsel.displayBoxes;
200 displayText = seqsel.displayText;
201 colourText = seqsel.colourText;
202 startRes = seqsel.startRes;
203 endRes = seqsel.endRes;
204 cs = new ResidueShader((ResidueShader) seqsel.cs);
205 if (seqsel.description != null)
207 description = new String(seqsel.description);
209 hidecols = seqsel.hidecols;
210 hidereps = seqsel.hidereps;
211 showNonconserved = seqsel.showNonconserved;
212 showSequenceLogo = seqsel.showSequenceLogo;
213 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
214 showConsensusHistogram = seqsel.showConsensusHistogram;
215 showHMMSequenceLogo = seqsel.showHMMSequenceLogo;
216 normaliseHMMSequenceLogo = seqsel.normaliseHMMSequenceLogo;
217 showInformationHistogram = seqsel.showInformationHistogram;
218 idColour = seqsel.idColour;
219 outlineColour = seqsel.outlineColour;
220 seqrep = seqsel.seqrep;
221 textColour = seqsel.textColour;
222 textColour2 = seqsel.textColour2;
223 thresholdTextColour = seqsel.thresholdTextColour;
224 width = seqsel.width;
225 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
226 ignoreBelowBackground = seqsel.ignoreBelowBackground;
227 infoLetterHeight = seqsel.infoLetterHeight;
228 if (seqsel.conserve != null)
230 recalcConservation(); // safer than
231 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
236 public boolean isShowSequenceLogo()
238 return showSequenceLogo;
241 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
243 int iSize = sequences.size();
244 SequenceI[] seqs = new SequenceI[iSize];
245 SequenceI[] inorder = getSequencesInOrder(align);
247 for (int i = 0, ipos = 0; i < inorder.length; i++)
249 SequenceI seq = inorder[i];
251 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
252 if (seqs[ipos] != null)
254 seqs[ipos].setDescription(seq.getDescription());
255 seqs[ipos].setDBRefs(seq.getDBRefs());
256 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
257 if (seq.getDatasetSequence() != null)
259 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
262 if (seq.getAnnotation() != null)
264 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
265 // Only copy annotation that is either a score or referenced by the
266 // alignment's annotation vector
267 for (int a = 0; a < seq.getAnnotation().length; a++)
269 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
272 boolean found = false;
273 for (int pos = 0; pos < alann.length; pos++)
275 if (alann[pos] == tocopy)
286 AlignmentAnnotation newannot = new AlignmentAnnotation(
287 seq.getAnnotation()[a]);
288 newannot.restrict(startRes, endRes);
289 newannot.setSequenceRef(seqs[ipos]);
290 newannot.adjustForAlignment();
291 seqs[ipos].addAlignmentAnnotation(newannot);
301 if (iSize != inorder.length)
303 SequenceI[] nseqs = new SequenceI[iSize];
304 System.arraycopy(seqs, 0, nseqs, 0, iSize);
312 * If sequence ends in gaps, the end residue can be correctly calculated here
318 public int findEndRes(SequenceI seq)
323 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
325 ch = seq.getCharAt(j);
326 if (!jalview.util.Comparison.isGap((ch)))
334 eres += seq.getStart() - 1;
341 public List<SequenceI> getSequences()
347 public List<SequenceI> getSequences(
348 Map<SequenceI, SequenceCollectionI> hiddenReps)
350 if (hiddenReps == null)
352 // TODO: need a synchronizedCollection here ?
357 List<SequenceI> allSequences = new ArrayList<>();
358 for (SequenceI seq : sequences)
360 allSequences.add(seq);
361 if (hiddenReps.containsKey(seq))
363 SequenceCollectionI hsg = hiddenReps.get(seq);
364 for (SequenceI seq2 : hsg.getSequences())
366 if (seq2 != seq && !allSequences.contains(seq2))
368 allSequences.add(seq2);
378 public SequenceI[] getSequencesAsArray(
379 Map<SequenceI, SequenceCollectionI> map)
381 List<SequenceI> tmp = getSequences(map);
386 return tmp.toArray(new SequenceI[tmp.size()]);
395 * @return DOCUMENT ME!
397 public boolean adjustForRemoveLeft(int col)
399 // return value is true if the group still exists
402 startRes = startRes - col;
407 endRes = endRes - col;
409 if (startRes > endRes)
416 // must delete this group!!
429 * @return DOCUMENT ME!
431 public boolean adjustForRemoveRight(int col)
450 * @return DOCUMENT ME!
452 public String getName()
457 public String getDescription()
468 public void setName(String name)
471 // TODO: URGENT: update dependent objects (annotation row)
474 public void setDescription(String desc)
482 * @return DOCUMENT ME!
484 public Conservation getConservation()
495 public void setConservation(Conservation c)
501 * Add s to this sequence group. If aligment sequence is already contained in
502 * group, it will not be added again, but recalculation may happen if the flag
506 * alignment sequence to be added
508 * true means Group's conservation should be recalculated
510 public void addSequence(SequenceI s, boolean recalc)
512 synchronized (sequences)
514 if (s != null && !sequences.contains(s))
521 recalcConservation();
527 * Max Gaps Threshold (percent) for performing a conservation calculation
529 private int consPercGaps = 25;
532 * @return Max Gaps Threshold for performing a conservation calculation
534 public int getConsPercGaps()
540 * set Max Gaps Threshold (percent) for performing a conservation calculation
542 * @param consPercGaps
544 public void setConsPercGaps(int consPercGaps)
546 this.consPercGaps = consPercGaps;
550 * calculate residue conservation and colourschemes for group - but only if
551 * necessary. returns true if the calculation resulted in a visible change to
554 public boolean recalcConservation()
556 return recalcConservation(false);
560 * calculate residue conservation for group - but only if necessary. returns
561 * true if the calculation resulted in a visible change to group
564 * when set, colourschemes for this group are not refreshed after
567 public boolean recalcConservation(boolean defer)
569 if (cs == null && consensus == null && conservation == null
570 && information == null)
574 // TODO: try harder to detect changes in state in order to minimise
575 // recalculation effort
579 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
580 endRes + 1, showSequenceLogo);
581 if (information != null)
583 HiddenMarkovModel hmm = information.sequenceRef.getHMM();
585 ProfilesI info = AAFrequency.calculateHMMProfiles(hmm,
586 (endRes + 1) - startRes, startRes, endRes + 1,
587 showHMMSequenceLogo, ignoreBelowBackground,
589 _updateInformationRow(info, sequences.size());
592 if (consensus != null)
594 _updateConsensusRow(cnsns, sequences.size());
599 cs.setConsensus(cnsns);
603 if ((conservation != null)
604 || (cs != null && cs.conservationApplied()))
606 Conservation c = new Conservation(groupName, sequences, startRes,
609 c.verdict(false, consPercGaps);
610 if (conservation != null)
612 _updateConservationRow(c);
616 if (cs.conservationApplied())
618 cs.setConservation(c);
621 // eager update - will cause a refresh of overview regardless
624 if (cs != null && !defer)
626 // TODO: JAL-2034 should cs.alignmentChanged modify return state
627 cs.alignmentChanged(context != null ? context : this, null);
634 } catch (java.lang.OutOfMemoryError err)
637 System.out.println("Out of memory loading groups: " + err);
642 private void _updateConservationRow(Conservation c)
644 if (conservation == null)
649 conservation.label = "Conservation for " + getName();
650 conservation.description = "Conservation for group " + getName()
651 + " less than " + consPercGaps + "% gaps";
652 // preserve width if already set
653 int aWidth = (conservation.annotations != null)
654 ? (endRes < conservation.annotations.length
655 ? conservation.annotations.length
658 conservation.annotations = null;
659 conservation.annotations = new Annotation[aWidth]; // should be alignment
661 c.completeAnnotations(conservation, null, startRes, endRes + 1);
664 public ProfilesI consensusData = null;
666 public ProfilesI informationData = null;
668 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
670 if (consensus == null)
674 consensus.label = "Consensus for " + getName();
675 consensus.description = "Percent Identity";
676 consensusData = cnsns;
677 // preserve width if already set
678 int aWidth = (consensus.annotations != null)
679 ? (endRes < consensus.annotations.length
680 ? consensus.annotations.length
683 consensus.annotations = null;
684 consensus.annotations = new Annotation[aWidth]; // should be alignment width
686 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
687 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
690 // ignoreGapsInConsensusCalculation);
694 * Recalculates the information content on the HMM annotation.
699 private void _updateInformationRow(ProfilesI cnsns, long nseq)
701 if (information == null)
705 information.description = MessageManager
706 .getString("label.information_description");
707 informationData = cnsns;
708 // preserve width if already set
709 int aWidth = (information.annotations != null)
710 ? (endRes < information.annotations.length
711 ? information.annotations.length : endRes + 1)
713 information.annotations = null;
714 information.annotations = new Annotation[aWidth]; // should be alignment
716 information.calcId = "HMM";
717 AAFrequency.completeInformation(information, cnsns, startRes,
718 endRes + 1, nseq, 0f); // TODO:
722 // ignoreGapsInInformationCalculation);
727 * sequence to either add or remove from group
729 * flag passed to delete/addSequence to indicate if group properties
730 * should be recalculated
732 public void addOrRemove(SequenceI s, boolean recalc)
734 synchronized (sequences)
736 if (sequences.contains(s))
738 deleteSequence(s, recalc);
742 addSequence(s, recalc);
753 * true means recalculate conservation
755 public void deleteSequence(SequenceI s, boolean recalc)
757 synchronized (sequences)
763 recalcConservation();
771 * @return the first column selected by this group. Runs from 0<=i<N_cols
774 public int getStartRes()
781 * @return the groups last selected column. Runs from 0<=i<N_cols
784 public int getEndRes()
790 * Set the first column selected by this group. Runs from 0<=i<N_cols
794 public void setStartRes(int i)
800 * Set the groups last selected column. Runs from 0<=i<N_cols
804 public void setEndRes(int i)
810 * @return number of sequences in group
814 return sequences.size();
819 * @return the ith sequence
821 public SequenceI getSequenceAt(int i)
823 return sequences.get(i);
830 public void setColourText(boolean state)
838 * @return DOCUMENT ME!
840 public boolean getColourText()
851 public void setDisplayText(boolean state)
859 * @return DOCUMENT ME!
861 public boolean getDisplayText()
872 public void setDisplayBoxes(boolean state)
874 displayBoxes = state;
880 * @return DOCUMENT ME!
882 public boolean getDisplayBoxes()
888 * computes the width of current set of sequences and returns it
890 * @return DOCUMENT ME!
893 public int getWidth()
895 synchronized (sequences)
897 // MC This needs to get reset when characters are inserted and deleted
898 boolean first = true;
899 for (SequenceI seq : sequences)
901 if (first || seq.getLength() > width)
903 width = seq.getLength();
917 public void setOutlineColour(Color c)
925 * @return DOCUMENT ME!
927 public Color getOutlineColour()
929 return outlineColour;
934 * returns the sequences in the group ordered by the ordering given by al.
935 * this used to return an array with null entries regardless, new behaviour is
936 * below. TODO: verify that this does not affect use in applet or application
940 * @return SequenceI[] intersection of sequences in group with al, ordered by
941 * al, or null if group does not intersect with al
943 public SequenceI[] getSequencesInOrder(AlignmentI al)
945 return getSequencesInOrder(al, true);
949 * return an array representing the intersection of the group with al,
950 * optionally returning an array the size of al.getHeight() where nulls mark
951 * the non-intersected sequences
955 * @return null or array
957 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
959 synchronized (sequences)
961 int sSize = sequences.size();
962 int alHeight = al.getHeight();
964 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
967 for (int i = 0; i < alHeight && index < sSize; i++)
969 if (sequences.contains(al.getSequenceAt(i)))
971 seqs[(trim) ? index : i] = al.getSequenceAt(i);
983 if (index < seqs.length)
985 SequenceI[] dummy = seqs;
986 seqs = new SequenceI[index];
989 seqs[index] = dummy[index];
998 * @return the idColour
1000 public Color getIdColour()
1007 * the idColour to set
1009 public void setIdColour(Color idColour)
1011 this.idColour = idColour;
1015 * @return the representative sequence for this group
1018 public SequenceI getSeqrep()
1024 * set the representative sequence for this group. Note - this affects the
1025 * interpretation of the Hidereps attribute.
1028 * the seqrep to set (null means no sequence representative)
1031 public void setSeqrep(SequenceI seqrep)
1033 this.seqrep = seqrep;
1038 * @return true if group has a sequence representative
1041 public boolean hasSeqrep()
1043 return seqrep != null;
1047 * set visibility of sequences covered by (if no sequence representative is
1048 * defined) or represented by this group.
1052 public void setHidereps(boolean visibility)
1054 hidereps = visibility;
1059 * @return true if sequences represented (or covered) by this group should be
1062 public boolean isHidereps()
1068 * set intended visibility of columns covered by this group
1072 public void setHideCols(boolean visibility)
1074 hidecols = visibility;
1079 * @return true if columns covered by group should be hidden
1081 public boolean isHideCols()
1087 * create a new sequence group from the intersection of this group with an
1088 * alignment Hashtable of hidden representatives
1094 * @return new group containing sequences common to this group and alignment
1096 public SequenceGroup intersect(AlignmentI alignment,
1097 Map<SequenceI, SequenceCollectionI> map)
1099 SequenceGroup sgroup = new SequenceGroup(this);
1100 SequenceI[] insect = getSequencesInOrder(alignment);
1101 sgroup.sequences = new ArrayList<>();
1102 for (int s = 0; insect != null && s < insect.length; s++)
1104 if (map == null || map.containsKey(insect[s]))
1106 sgroup.sequences.add(insect[s]);
1113 * @return the showUnconserved
1115 public boolean getShowNonconserved()
1117 return showNonconserved;
1121 * @param showNonconserved
1122 * the showUnconserved to set
1124 public void setShowNonconserved(boolean displayNonconserved)
1126 this.showNonconserved = displayNonconserved;
1130 * set this alignmentAnnotation object as the one used to render consensus
1135 public void setConsensus(AlignmentAnnotation aan)
1137 if (consensus == null)
1145 * @return automatically calculated consensus row note: the row is a stub if a
1146 * consensus calculation has not yet been performed on the group
1148 public AlignmentAnnotation getConsensus()
1150 // TODO get or calculate and get consensus annotation row for this group
1151 int aWidth = this.getWidth();
1159 if (consensus == null)
1161 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1162 100f, AlignmentAnnotation.BAR_GRAPH);
1163 consensus.hasText = true;
1164 consensus.autoCalculated = true;
1165 consensus.groupRef = this;
1166 consensus.label = "Consensus for " + getName();
1167 consensus.description = "Percent Identity";
1174 * @return information content annotation.
1176 public AlignmentAnnotation getInformation()
1178 // TODO get or calculate and get information annotation row for this group
1179 int aWidth = this.getWidth();
1187 if (information == null)
1189 information = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1190 6.25f, AlignmentAnnotation.BAR_GRAPH);
1191 information.hasText = true;
1192 information.autoCalculated = false;
1193 information.groupRef = this;
1194 information.label = getName();
1195 information.description = "Information content, measured in bits";
1196 information.calcId = "HMM";
1202 * set this alignmentAnnotation object as the one used to render consensus
1207 public void setConservationRow(AlignmentAnnotation aan)
1209 if (conservation == null)
1216 * get the conservation annotation row for this group
1218 * @return autoCalculated annotation row
1220 public AlignmentAnnotation getConservationRow()
1222 if (conservation == null)
1224 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1225 11f, AlignmentAnnotation.BAR_GRAPH);
1228 conservation.hasText = true;
1229 conservation.autoCalculated = true;
1230 conservation.groupRef = this;
1231 conservation.label = "Conservation for " + getName();
1232 conservation.description = "Conservation for group " + getName()
1233 + " less than " + consPercGaps + "% gaps";
1234 return conservation;
1239 * @return true if annotation rows have been instantiated for this group
1241 public boolean hasAnnotationRows()
1243 return consensus != null || conservation != null;
1246 public SequenceI getConsensusSeq()
1249 StringBuffer seqs = new StringBuffer();
1250 for (int i = 0; i < consensus.annotations.length; i++)
1252 if (consensus.annotations[i] != null)
1254 if (consensus.annotations[i].description.charAt(0) == '[')
1256 seqs.append(consensus.annotations[i].description.charAt(1));
1260 seqs.append(consensus.annotations[i].displayCharacter);
1265 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1267 sq.setDescription("Percentage Identity Consensus "
1268 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1272 public void setIgnoreGapsConsensus(boolean state)
1274 if (this.ignoreGapsInConsensus != state && consensus != null)
1276 ignoreGapsInConsensus = state;
1277 recalcConservation();
1279 ignoreGapsInConsensus = state;
1282 public boolean getIgnoreGapsConsensus()
1284 return ignoreGapsInConsensus;
1287 public void setIgnoreBelowBackground(boolean state)
1289 if (this.ignoreBelowBackground != state)
1291 ignoreBelowBackground = state;
1293 ignoreBelowBackground = state;
1296 public boolean getIgnoreBelowBackground()
1298 return ignoreBelowBackground;
1301 public void setInfoLetterHeight(boolean state)
1303 if (this.infoLetterHeight != state)
1305 infoLetterHeight = state;
1307 infoLetterHeight = state;
1310 public boolean getInfoLetterHeight()
1312 return infoLetterHeight;
1316 * @param showSequenceLogo
1317 * indicates if a sequence logo is shown for consensus annotation
1319 public void setshowSequenceLogo(boolean showSequenceLogo)
1321 // TODO: decouple calculation from settings update
1322 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1324 this.showSequenceLogo = showSequenceLogo;
1325 recalcConservation();
1327 this.showSequenceLogo = showSequenceLogo;
1332 * @param showConsHist
1333 * flag indicating if the consensus histogram for this group should
1336 public void setShowConsensusHistogram(boolean showConsHist)
1339 if (showConsensusHistogram != showConsHist && consensus != null)
1341 this.showConsensusHistogram = showConsHist;
1342 recalcConservation();
1344 this.showConsensusHistogram = showConsHist;
1348 * @return the showConsensusHistogram
1350 public boolean isShowConsensusHistogram()
1352 return showConsensusHistogram;
1356 * set flag indicating if logo should be normalised when rendered
1360 public void setNormaliseSequenceLogo(boolean norm)
1362 normaliseSequenceLogo = norm;
1365 public boolean isNormaliseSequenceLogo()
1367 return normaliseSequenceLogo;
1372 * returns a new array with all annotation involving this group
1374 public AlignmentAnnotation[] getAlignmentAnnotation()
1376 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1378 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1379 synchronized (sequences)
1381 for (SequenceI seq : sequences)
1383 AlignmentAnnotation[] aa = seq.getAnnotation();
1386 for (AlignmentAnnotation al : aa)
1388 if (al.groupRef == this)
1395 if (consensus != null)
1397 annot.add(consensus);
1399 if (conservation != null)
1401 annot.add(conservation);
1404 return annot.toArray(new AlignmentAnnotation[0]);
1408 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1410 List<AlignmentAnnotation> aa = new ArrayList<>();
1415 for (AlignmentAnnotation a : getAlignmentAnnotation())
1417 if (calcId.equals(a.getCalcId()))
1426 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1427 String calcId, String label)
1429 ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
1430 for (AlignmentAnnotation ann : getAlignmentAnnotation())
1432 if ((calcId == null || (ann.getCalcId() != null
1433 && ann.getCalcId().equals(calcId)))
1434 && (seq == null || (ann.sequenceRef != null
1435 && ann.sequenceRef == seq))
1437 || (ann.label != null && ann.label.equals(label))))
1446 * Answer true if any annotation matches the calcId passed in (if not null).
1451 public boolean hasAnnotation(String calcId)
1453 if (calcId != null && !"".equals(calcId))
1455 for (AlignmentAnnotation a : getAlignmentAnnotation())
1457 if (a.getCalcId() == calcId)
1467 * Remove all sequences from the group (leaving other properties unchanged).
1471 synchronized (sequences)
1478 * Sets the alignment or group context for this group, and whether it is
1479 * defined as a group
1482 * the context for the group
1484 * whether the group is defined on the alignment or is just a
1486 * @throws IllegalArgumentException
1487 * if setting the context would result in a circular reference chain
1489 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1492 this.isDefined = defined;
1496 * Sets the alignment or group context for this group
1499 * the context for the group
1500 * @throws IllegalArgumentException
1501 * if setting the context would result in a circular reference chain
1503 public void setContext(AnnotatedCollectionI ctx)
1505 AnnotatedCollectionI ref = ctx;
1508 if (ref == this || ref.getContext() == ctx)
1510 throw new IllegalArgumentException(
1511 "Circular reference in SequenceGroup.context");
1513 ref = ref.getContext();
1521 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1524 public AnnotatedCollectionI getContext()
1529 public boolean isDefined()
1534 public void setColourScheme(ColourSchemeI scheme)
1538 cs = new ResidueShader();
1540 cs.setColourScheme(scheme);
1543 public void setGroupColourScheme(ResidueShaderI scheme)
1548 public ColourSchemeI getColourScheme()
1550 return cs == null ? null : cs.getColourScheme();
1553 public ResidueShaderI getGroupColourScheme()
1559 public boolean isNucleotide()
1561 if (context != null)
1563 return context.isNucleotide();
1570 * @return true if seq is a member of the group
1573 public boolean contains(SequenceI seq1)
1575 return sequences.contains(seq1);
1581 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1583 public boolean contains(SequenceI seq, int apos)
1585 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1588 public boolean isShowInformationHistogram()
1590 return showInformationHistogram;
1593 public void setShowInformationHistogram(boolean state)
1595 if (showInformationHistogram != state && information != null)
1597 this.showInformationHistogram = state;
1598 // recalcConservation(); TODO don't know what to do here next
1600 this.showInformationHistogram = state;
1604 public boolean isShowHMMSequenceLogo()
1606 // TODO Auto-generated method stub
1607 return showHMMSequenceLogo;
1610 public void setshowHMMSequenceLogo(boolean state)
1612 showHMMSequenceLogo = state;
1616 public boolean isNormaliseHMMSequenceLogo()
1618 // TODO Auto-generated method stub
1619 return normaliseHMMSequenceLogo;
1622 public void setNormaliseHMMSequenceLogo(boolean state)
1624 normaliseSequenceLogo = state;
1628 * Returns all HMM consensus sequences. This will not return real sequences
1629 * with HMMs. If remove is set to true, the consensus sequences will be
1630 * removed from the alignment.
1632 @Override // TODO make this more efficient.
1633 public List<SequenceI> getHMMConsensusSequences(boolean remove)
1635 List<SequenceI> seqs = new ArrayList<>();
1637 int seqsRemoved = 0;
1638 boolean endReached = false;
1642 SequenceI seq = sequences.get(position);
1643 if (seq.isHMMConsensusSequence())
1647 sequences.remove(position);
1649 seq.setPreviousPosition(seqsRemoved + position - 1);
1662 if (position >= sequences.size())