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 java.awt.Color;
24 import java.beans.PropertyChangeListener;
25 import java.beans.PropertyChangeSupport;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.List;
32 import jalview.analysis.AAFrequency;
33 import jalview.analysis.Conservation;
34 import jalview.renderer.ResidueShader;
35 import jalview.renderer.ResidueShaderI;
36 import jalview.schemes.ColourSchemeI;
39 * Collects a set contiguous ranges on a set of sequences
44 public class SequenceGroup implements AnnotatedCollectionI
46 // TODO ideally this event notification functionality should be separated into
48 // subclass of ViewportProperties similarly to ViewportRanges. Done here as
49 // quick fix for JAL-2665
50 public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
52 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
55 public void addPropertyChangeListener(PropertyChangeListener listener)
57 changeSupport.addPropertyChangeListener(listener);
60 public void removePropertyChangeListener(PropertyChangeListener listener)
62 changeSupport.removePropertyChangeListener(listener);
64 // end of event notification functionality initialisation
70 Conservation conserve;
72 boolean displayBoxes = true;
74 boolean displayText = true;
76 boolean colourText = false;
79 * True if the group is defined as a group on the alignment, false if it is
82 boolean isDefined = false;
85 * after Olivier's non-conserved only character display
87 boolean showNonconserved = false;
92 private List<SequenceI> sequences;
95 * representative sequence for this group (if any)
97 private SequenceI seqrep = null;
102 * Colourscheme applied to group if any
104 public ResidueShaderI cs;
107 * start column (base 0)
109 private int startRes = 0;
112 * end column (base 0)
114 private int endRes = 0;
116 public Color outlineColour = Color.black;
118 public Color idColour = null;
120 public int thresholdTextColour = 0;
122 public Color textColour = Color.black;
124 public Color textColour2 = Color.white;
127 * consensus calculation property
129 private boolean ignoreGapsInConsensus = true;
132 * consensus calculation property
134 private boolean showSequenceLogo = false;
137 * flag indicating if logo should be rendered normalised
139 private boolean normaliseSequenceLogo;
142 * visibility of rows or represented rows covered by group
144 private boolean hidereps = false;
147 * visibility of columns intersecting this group
149 private boolean hidecols = false;
151 AlignmentAnnotation consensus = null;
153 AlignmentAnnotation conservation = null;
155 private boolean showConsensusHistogram;
157 private AnnotatedCollectionI context;
160 * Creates a new SequenceGroup object.
162 public SequenceGroup()
164 groupName = "JGroup:" + this.hashCode();
165 cs = new ResidueShader();
166 sequences = new ArrayList<>();
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;
219 startRes = seqsel.startRes;
220 endRes = seqsel.endRes;
221 cs = new ResidueShader((ResidueShader) seqsel.cs);
222 if (seqsel.description != null)
224 description = new String(seqsel.description);
226 hidecols = seqsel.hidecols;
227 hidereps = seqsel.hidereps;
228 showNonconserved = seqsel.showNonconserved;
229 showSequenceLogo = seqsel.showSequenceLogo;
230 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
231 showConsensusHistogram = seqsel.showConsensusHistogram;
232 idColour = seqsel.idColour;
233 outlineColour = seqsel.outlineColour;
234 seqrep = seqsel.seqrep;
235 textColour = seqsel.textColour;
236 textColour2 = seqsel.textColour2;
237 thresholdTextColour = seqsel.thresholdTextColour;
238 width = seqsel.width;
239 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
240 if (seqsel.conserve != null)
242 recalcConservation(); // safer than
243 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
249 * Constructor that copies the given list of sequences
253 public SequenceGroup(List<SequenceI> seqs)
256 this.sequences.addAll(seqs);
259 public boolean isShowSequenceLogo()
261 return showSequenceLogo;
264 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
266 int iSize = sequences.size();
267 SequenceI[] seqs = new SequenceI[iSize];
268 SequenceI[] inorder = getSequencesInOrder(align);
270 for (int i = 0, ipos = 0; i < inorder.length; i++)
272 SequenceI seq = inorder[i];
273 SequenceI seqipos = seqs[ipos] = seq.getSubSequence(startRes,
277 seqipos.setDescription(seq.getDescription());
278 seqipos.setDBRefs(seq.getDBRefs());
279 seqipos.setSequenceFeatures(seq.getSequenceFeatures());
280 if (seq.getDatasetSequence() != null)
282 seqipos.setDatasetSequence(seq.getDatasetSequence());
285 if (seq.getAnnotation() != null)
287 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
288 // Only copy annotation that is either a score or referenced by the
289 // alignment's annotation vector
290 for (int a = 0; a < seq.getAnnotation().length; a++)
292 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
295 boolean found = false;
296 for (int pos = 0, np = alann.length; pos < np; pos++)
298 if (alann[pos] == tocopy)
309 AlignmentAnnotation newannot = new AlignmentAnnotation(
310 seq.getAnnotation()[a]);
311 newannot.restrict(startRes, endRes);
312 newannot.setSequenceRef(seqs[ipos]);
313 newannot.adjustForAlignment();
314 ContactMatrixI cm = seq.getContactMatrixFor(seq.getAnnotation()[a]);
317 seqs[ipos].addContactListFor(newannot, cm);
319 seqipos.addAlignmentAnnotation(newannot);
329 if (iSize != inorder.length)
331 SequenceI[] nseqs = new SequenceI[iSize];
332 System.arraycopy(seqs, 0, nseqs, 0, iSize);
340 * If sequence ends in gaps, the end residue can be correctly calculated here
346 public int findEndRes(SequenceI seq)
351 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
353 ch = seq.getCharAt(j);
354 if (!jalview.util.Comparison.isGap((ch)))
362 eres += seq.getStart() - 1;
369 public List<SequenceI> getSequences()
375 public List<SequenceI> getSequences(
376 Map<SequenceI, SequenceCollectionI> hiddenReps)
378 if (hiddenReps == null)
380 // TODO: need a synchronizedCollection here ?
385 List<SequenceI> allSequences = new ArrayList<>();
386 for (SequenceI seq : sequences)
388 allSequences.add(seq);
389 if (hiddenReps.containsKey(seq))
391 SequenceCollectionI hsg = hiddenReps.get(seq);
392 for (SequenceI seq2 : hsg.getSequences())
394 if (seq2 != seq && !allSequences.contains(seq2))
396 allSequences.add(seq2);
406 public SequenceI[] getSequencesAsArray(
407 Map<SequenceI, SequenceCollectionI> map)
409 List<SequenceI> tmp = getSequences(map);
414 return tmp.toArray(new SequenceI[tmp.size()]);
423 * @return DOCUMENT ME!
425 public boolean adjustForRemoveLeft(int col)
427 // return value is true if the group still exists
430 startRes = startRes - col;
435 endRes = endRes - col;
437 if (startRes > endRes)
444 // must delete this group!!
457 * @return DOCUMENT ME!
459 public boolean adjustForRemoveRight(int col)
478 * @return DOCUMENT ME!
480 public String getName()
485 public String getDescription()
496 public void setName(String name)
499 // TODO: URGENT: update dependent objects (annotation row)
502 public void setDescription(String desc)
510 * @return DOCUMENT ME!
512 public Conservation getConservation()
523 public void setConservation(Conservation c)
529 * Add s to this sequence group. If aligment sequence is already contained in
530 * group, it will not be added again, but recalculation may happen if the flag
534 * alignment sequence to be added
536 * true means Group's conservation should be recalculated
538 public void addSequence(SequenceI s, boolean recalc)
540 synchronized (sequences)
542 if (s != null && !sequences.contains(s))
545 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
546 sequences.size() - 1, sequences.size());
551 recalcConservation();
557 * Max Gaps Threshold (percent) for performing a conservation calculation
559 private int consPercGaps = 25;
562 * @return Max Gaps Threshold for performing a conservation calculation
564 public int getConsPercGaps()
570 * set Max Gaps Threshold (percent) for performing a conservation calculation
572 * @param consPercGaps
574 public void setConsPercGaps(int consPercGaps)
576 this.consPercGaps = consPercGaps;
580 * calculate residue conservation and colourschemes for group - but only if
581 * necessary. returns true if the calculation resulted in a visible change to
584 public boolean recalcConservation()
586 return recalcConservation(false);
590 * calculate residue conservation for group - but only if necessary. returns
591 * true if the calculation resulted in a visible change to group
594 * when set, colourschemes for this group are not refreshed after
597 public boolean recalcConservation(boolean defer)
599 if (cs == null && consensus == null && conservation == null)
603 // TODO: try harder to detect changes in state in order to minimise
604 // recalculation effort
608 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
609 endRes + 1, showSequenceLogo);
610 if (consensus != null)
612 _updateConsensusRow(cnsns, sequences.size());
617 cs.setConsensus(cnsns);
621 if ((conservation != null)
622 || (cs != null && cs.conservationApplied()))
624 Conservation c = new Conservation(groupName, sequences, startRes,
627 c.verdict(false, consPercGaps);
628 if (conservation != null)
630 _updateConservationRow(c);
634 if (cs.conservationApplied())
636 cs.setConservation(c);
639 // eager update - will cause a refresh of overview regardless
642 if (cs != null && !defer)
644 // TODO: JAL-2034 should cs.alignmentChanged modify return state
645 cs.alignmentChanged(context != null ? context : this, null);
652 } catch (java.lang.OutOfMemoryError err)
655 System.out.println("Out of memory loading groups: " + err);
660 private void _updateConservationRow(Conservation c)
662 if (conservation == null)
667 conservation.label = "Conservation for " + getName();
668 conservation.description = "Conservation for group " + getName()
669 + " less than " + consPercGaps + "% gaps";
670 // preserve width if already set
671 int aWidth = (conservation.annotations != null)
672 ? (endRes < conservation.annotations.length
673 ? conservation.annotations.length
676 conservation.annotations = null;
677 conservation.annotations = new Annotation[aWidth]; // should be alignment
679 c.completeAnnotations(conservation, null, startRes, endRes + 1);
682 public ProfilesI consensusData = null;
684 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
686 if (consensus == null)
690 consensus.label = "Consensus for " + getName();
691 consensus.description = "Percent Identity";
692 consensusData = cnsns;
693 // preserve width if already set
694 int aWidth = (consensus.annotations != null)
695 ? (endRes < consensus.annotations.length
696 ? consensus.annotations.length
699 consensus.annotations = null;
700 consensus.annotations = new Annotation[aWidth]; // should be alignment width
702 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
703 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
706 // ignoreGapsInConsensusCalculation);
711 * sequence to either add or remove from group
713 * flag passed to delete/addSequence to indicate if group properties
714 * should be recalculated
716 public void addOrRemove(SequenceI s, boolean recalc)
718 synchronized (sequences)
720 if (sequences.contains(s))
722 deleteSequence(s, recalc);
726 addSequence(s, recalc);
737 * true means recalculate conservation
739 public void deleteSequence(SequenceI s, boolean recalc)
741 synchronized (sequences)
744 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED,
745 sequences.size() + 1, sequences.size());
749 recalcConservation();
757 * @return the first column selected by this group. Runs from 0<=i<N_cols
760 public int getStartRes()
767 * @return the groups last selected column. Runs from 0<=i<N_cols
770 public int getEndRes()
776 * Set the first column selected by this group. Runs from 0<=i<N_cols
780 public void setStartRes(int newStart)
782 int before = startRes;
783 startRes = Math.max(0, newStart); // sanity check for negative start column
785 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
790 * Set the groups last selected column. Runs from 0<=i<N_cols
794 public void setEndRes(int i)
798 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
802 * @return number of sequences in group
806 return sequences.size();
811 * @return the ith sequence
813 public SequenceI getSequenceAt(int i)
815 return sequences.get(i);
822 public void setColourText(boolean state)
830 * @return DOCUMENT ME!
832 public boolean getColourText()
843 public void setDisplayText(boolean state)
851 * @return DOCUMENT ME!
853 public boolean getDisplayText()
864 public void setDisplayBoxes(boolean state)
866 displayBoxes = state;
872 * @return DOCUMENT ME!
874 public boolean getDisplayBoxes()
880 * computes the width of current set of sequences and returns it
882 * @return DOCUMENT ME!
885 public int getWidth()
887 synchronized (sequences)
889 // MC This needs to get reset when characters are inserted and deleted
890 boolean first = true;
891 for (SequenceI seq : sequences)
893 if (first || seq.getLength() > width)
895 width = seq.getLength();
909 public void setOutlineColour(Color c)
917 * @return DOCUMENT ME!
919 public Color getOutlineColour()
921 return outlineColour;
926 * returns the sequences in the group ordered by the ordering given by al.
927 * this used to return an array with null entries regardless, new behaviour is
928 * below. TODO: verify that this does not affect use in applet or application
932 * @return SequenceI[] intersection of sequences in group with al, ordered by
933 * al, or null if group does not intersect with al
935 public SequenceI[] getSequencesInOrder(AlignmentI al)
937 return getSequencesInOrder(al, true);
941 * return an array representing the intersection of the group with al,
942 * optionally returning an array the size of al.getHeight() where nulls mark
943 * the non-intersected sequences
947 * @return null or array
949 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
951 synchronized (sequences)
953 int sSize = sequences.size();
954 int alHeight = al.getHeight();
956 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
959 for (int i = 0; i < alHeight && index < sSize; i++)
961 if (sequences.contains(al.getSequenceAt(i)))
963 seqs[(trim) ? index : i] = al.getSequenceAt(i);
975 if (index < seqs.length)
977 SequenceI[] dummy = seqs;
978 seqs = new SequenceI[index];
981 seqs[index] = dummy[index];
990 * @return the idColour
992 public Color getIdColour()
999 * the idColour to set
1001 public void setIdColour(Color idColour)
1003 this.idColour = idColour;
1007 * @return the representative sequence for this group
1010 public SequenceI getSeqrep()
1016 * set the representative sequence for this group. Note - this affects the
1017 * interpretation of the Hidereps attribute.
1020 * the seqrep to set (null means no sequence representative)
1023 public void setSeqrep(SequenceI seqrep)
1025 this.seqrep = seqrep;
1030 * @return true if group has a sequence representative
1033 public boolean hasSeqrep()
1035 return seqrep != null;
1039 * set visibility of sequences covered by (if no sequence representative is
1040 * defined) or represented by this group.
1044 public void setHidereps(boolean visibility)
1046 hidereps = visibility;
1051 * @return true if sequences represented (or covered) by this group should be
1054 public boolean isHidereps()
1060 * set intended visibility of columns covered by this group
1064 public void setHideCols(boolean visibility)
1066 hidecols = visibility;
1071 * @return true if columns covered by group should be hidden
1073 public boolean isHideCols()
1079 * create a new sequence group from the intersection of this group with an
1080 * alignment Hashtable of hidden representatives
1086 * @return new group containing sequences common to this group and alignment
1088 public SequenceGroup intersect(AlignmentI alignment,
1089 Map<SequenceI, SequenceCollectionI> map)
1091 SequenceGroup sgroup = new SequenceGroup(this);
1092 SequenceI[] insect = getSequencesInOrder(alignment);
1093 sgroup.sequences = new ArrayList<>();
1094 for (int s = 0; insect != null && s < insect.length; s++)
1096 if (map == null || map.containsKey(insect[s]))
1098 sgroup.sequences.add(insect[s]);
1105 * @return the showUnconserved
1107 public boolean getShowNonconserved()
1109 return showNonconserved;
1113 * @param showNonconserved
1114 * the showUnconserved to set
1116 public void setShowNonconserved(boolean displayNonconserved)
1118 this.showNonconserved = displayNonconserved;
1122 * set this alignmentAnnotation object as the one used to render consensus
1127 public void setConsensus(AlignmentAnnotation aan)
1129 if (consensus == null)
1137 * @return automatically calculated consensus row note: the row is a stub if a
1138 * consensus calculation has not yet been performed on the group
1140 public AlignmentAnnotation getConsensus()
1142 // TODO get or calculate and get consensus annotation row for this group
1143 int aWidth = this.getWidth();
1151 if (consensus == null)
1153 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1154 100f, AlignmentAnnotation.BAR_GRAPH);
1155 consensus.hasText = true;
1156 consensus.autoCalculated = true;
1157 consensus.groupRef = this;
1158 consensus.label = "Consensus for " + getName();
1159 consensus.description = "Percent Identity";
1165 * set this alignmentAnnotation object as the one used to render consensus
1170 public void setConservationRow(AlignmentAnnotation aan)
1172 if (conservation == null)
1179 * get the conservation annotation row for this group
1181 * @return autoCalculated annotation row
1183 public AlignmentAnnotation getConservationRow()
1185 if (conservation == null)
1187 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1188 11f, AlignmentAnnotation.BAR_GRAPH);
1191 conservation.hasText = true;
1192 conservation.autoCalculated = true;
1193 conservation.groupRef = this;
1194 conservation.label = "Conservation for " + getName();
1195 conservation.description = "Conservation for group " + getName()
1196 + " less than " + consPercGaps + "% gaps";
1197 return conservation;
1202 * @return true if annotation rows have been instantiated for this group
1204 public boolean hasAnnotationRows()
1206 return consensus != null || conservation != null;
1209 public SequenceI getConsensusSeq()
1212 StringBuffer seqs = new StringBuffer();
1213 for (int i = 0; i < consensus.annotations.length; i++)
1215 if (consensus.annotations[i] != null)
1217 String desc = consensus.annotations[i].description;
1218 if (desc.length() > 1 && desc.charAt(0) == '[')
1220 seqs.append(desc.charAt(1));
1224 seqs.append(consensus.annotations[i].displayCharacter);
1229 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1231 sq.setDescription("Percentage Identity Consensus "
1232 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1236 public void setIgnoreGapsConsensus(boolean state)
1238 if (this.ignoreGapsInConsensus != state && consensus != null)
1240 ignoreGapsInConsensus = state;
1241 recalcConservation();
1243 ignoreGapsInConsensus = state;
1246 public boolean getIgnoreGapsConsensus()
1248 return ignoreGapsInConsensus;
1252 * @param showSequenceLogo
1253 * indicates if a sequence logo is shown for consensus annotation
1255 public void setshowSequenceLogo(boolean showSequenceLogo)
1257 // TODO: decouple calculation from settings update
1258 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1260 this.showSequenceLogo = showSequenceLogo;
1261 recalcConservation();
1263 this.showSequenceLogo = showSequenceLogo;
1268 * @param showConsHist
1269 * flag indicating if the consensus histogram for this group should
1272 public void setShowConsensusHistogram(boolean showConsHist)
1275 if (showConsensusHistogram != showConsHist && consensus != null)
1277 this.showConsensusHistogram = showConsHist;
1278 recalcConservation();
1280 this.showConsensusHistogram = showConsHist;
1284 * @return the showConsensusHistogram
1286 public boolean isShowConsensusHistogram()
1288 return showConsensusHistogram;
1292 * set flag indicating if logo should be normalised when rendered
1296 public void setNormaliseSequenceLogo(boolean norm)
1298 normaliseSequenceLogo = norm;
1301 public boolean isNormaliseSequenceLogo()
1303 return normaliseSequenceLogo;
1308 * returns a new array with all annotation involving this group
1310 public AlignmentAnnotation[] getAlignmentAnnotation()
1312 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1314 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1315 synchronized (sequences)
1317 for (SequenceI seq : sequences)
1319 AlignmentAnnotation[] aa = seq.getAnnotation();
1322 for (AlignmentAnnotation al : aa)
1324 if (al.groupRef == this)
1331 if (consensus != null)
1333 annot.add(consensus);
1335 if (conservation != null)
1337 annot.add(conservation);
1340 return annot.toArray(new AlignmentAnnotation[0]);
1344 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1346 return AlignmentAnnotation.findAnnotation(
1347 Arrays.asList(getAlignmentAnnotation()), calcId);
1351 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1352 String calcId, String label)
1354 return AlignmentAnnotation.findAnnotations(
1355 Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
1359 * Answer true if any annotation matches the calcId passed in (if not null).
1364 public boolean hasAnnotation(String calcId)
1366 return AlignmentAnnotation
1367 .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId);
1371 * Remove all sequences from the group (leaving other properties unchanged).
1375 synchronized (sequences)
1377 int before = sequences.size();
1379 changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
1385 * Sets the alignment or group context for this group, and whether it is
1386 * defined as a group
1389 * the context for the group
1391 * whether the group is defined on the alignment or is just a
1393 * @throws IllegalArgumentException
1394 * if setting the context would result in a circular reference chain
1396 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1399 this.isDefined = defined;
1403 * Sets the alignment or group context for this group
1406 * the context for the group
1407 * @throws IllegalArgumentException
1408 * if setting the context would result in a circular reference chain
1410 public void setContext(AnnotatedCollectionI ctx)
1412 AnnotatedCollectionI ref = ctx;
1415 if (ref == this || ref.getContext() == ctx)
1417 throw new IllegalArgumentException(
1418 "Circular reference in SequenceGroup.context");
1420 ref = ref.getContext();
1428 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1431 public AnnotatedCollectionI getContext()
1436 public boolean isDefined()
1441 public void setColourScheme(ColourSchemeI scheme)
1445 cs = new ResidueShader();
1447 cs.setColourScheme(scheme);
1450 public void setGroupColourScheme(ResidueShaderI scheme)
1455 public ColourSchemeI getColourScheme()
1457 return cs == null ? null : cs.getColourScheme();
1460 public ResidueShaderI getGroupColourScheme()
1466 public boolean isNucleotide()
1468 if (context != null)
1470 return context.isNucleotide();
1477 * @return true if seq is a member of the group
1480 public boolean contains(SequenceI seq1)
1482 return sequences.contains(seq1);
1488 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1490 public boolean contains(SequenceI seq, int apos)
1492 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
1496 //// Contact Matrix Holder Boilerplate
1498 ContactMapHolder cmholder = new ContactMapHolder();
1501 public Collection<ContactMatrixI> getContactMaps()
1503 return cmholder.getContactMaps();
1507 public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
1509 return cmholder.getContactMatrixFor(ann);
1513 public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
1515 return cmholder.getContactListFor(_aa, column);
1519 public AlignmentAnnotation addContactList(ContactMatrixI cm)
1521 AlignmentAnnotation aa = cmholder.addContactList(cm);
1523 Annotation _aa[] = new Annotation[getWidth()];
1524 Annotation dummy = new Annotation(0.0f);
1525 for (int i = 0; i < _aa.length; _aa[i++] = dummy)
1529 aa.annotations = _aa;
1530 // TODO passing annotations back to context to be added
1535 public void addContactListFor(AlignmentAnnotation annotation,
1538 cmholder.addContactListFor(annotation, cm);