+ /**
+ * @return the showUnconserved
+ */
+ public boolean getShowNonconserved()
+ {
+ return showNonconserved;
+ }
+
+ /**
+ * @param showNonconserved
+ * the showUnconserved to set
+ */
+ public void setShowNonconserved(boolean displayNonconserved)
+ {
+ this.showNonconserved = displayNonconserved;
+ }
+
+ AlignmentAnnotation consensus = null, conservation = null;
+
+ /**
+ * flag indicating if consensus histogram should be rendered
+ */
+ private boolean showConsensusHistogram;
+
+ /**
+ * set this alignmentAnnotation object as the one used to render consensus
+ * annotation
+ *
+ * @param aan
+ */
+ public void setConsensus(AlignmentAnnotation aan)
+ {
+ if (consensus == null)
+ {
+ consensus = aan;
+ }
+ }
+
+ /**
+ *
+ * @return automatically calculated consensus row note: the row is a stub if a
+ * consensus calculation has not yet been performed on the group
+ */
+ public AlignmentAnnotation getConsensus()
+ {
+ // TODO get or calculate and get consensus annotation row for this group
+ int aWidth = this.getWidth();
+ // pointer
+ // possibility
+ // here.
+ if (aWidth < 0)
+ {
+ return null;
+ }
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
+ 100f, AlignmentAnnotation.BAR_GRAPH);
+ consensus.hasText = true;
+ consensus.autoCalculated = true;
+ consensus.groupRef = this;
+ consensus.label = "Consensus for " + getName();
+ consensus.description = "Percent Identity";
+ }
+ return consensus;
+ }
+
+ /**
+ * set this alignmentAnnotation object as the one used to render consensus
+ * annotation
+ *
+ * @param aan
+ */
+ public void setConservationRow(AlignmentAnnotation aan)
+ {
+ if (conservation == null)
+ {
+ conservation = aan;
+ }
+ }
+
+ /**
+ * get the conservation annotation row for this group
+ *
+ * @return autoCalculated annotation row
+ */
+ public AlignmentAnnotation getConservationRow()
+ {
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
+ 11f, AlignmentAnnotation.BAR_GRAPH);
+ }
+
+ conservation.hasText = true;
+ conservation.autoCalculated = true;
+ conservation.groupRef = this;
+ conservation.label = "Conservation for " + getName();
+ conservation.description = "Conservation for group " + getName()
+ + " less than " + consPercGaps + "% gaps";
+ return conservation;
+ }
+
+ /**
+ *
+ * @return true if annotation rows have been instantiated for this group
+ */
+ public boolean hasAnnotationRows()
+ {
+ return consensus != null || conservation != null;
+ }
+
+ public SequenceI getConsensusSeq()
+ {
+ getConsensus();
+ StringBuffer seqs = new StringBuffer();
+ for (int i = 0; i < consensus.annotations.length; i++)
+ {
+ if (consensus.annotations[i] != null)
+ {
+ if (consensus.annotations[i].description.charAt(0) == '[')
+ {
+ seqs.append(consensus.annotations[i].description.charAt(1));
+ }
+ else
+ {
+ seqs.append(consensus.annotations[i].displayCharacter);
+ }
+ }
+ }
+
+ SequenceI sq = new Sequence("Group" + getName() + " Consensus",
+ seqs.toString());
+ sq.setDescription("Percentage Identity Consensus "
+ + ((ignoreGapsInConsensus) ? " without gaps" : ""));
+ return sq;
+ }
+
+ public void setIgnoreGapsConsensus(boolean state)
+ {
+ if (this.ignoreGapsInConsensus != state && consensus != null)
+ {
+ ignoreGapsInConsensus = state;
+ recalcConservation();
+ }
+ ignoreGapsInConsensus = state;
+ }
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensus;
+ }
+
+ /**
+ * @param showSequenceLogo
+ * indicates if a sequence logo is shown for consensus annotation
+ */
+ public void setshowSequenceLogo(boolean showSequenceLogo)
+ {
+ // TODO: decouple calculation from settings update
+ if (this.showSequenceLogo != showSequenceLogo && consensus != null)
+ {
+ this.showSequenceLogo = showSequenceLogo;
+ recalcConservation();
+ }
+ this.showSequenceLogo = showSequenceLogo;
+ }
+
+ /**
+ *
+ * @param showConsHist
+ * flag indicating if the consensus histogram for this group should
+ * be rendered
+ */
+ public void setShowConsensusHistogram(boolean showConsHist)
+ {
+
+ if (showConsensusHistogram != showConsHist && consensus != null)
+ {
+ this.showConsensusHistogram = showConsHist;
+ recalcConservation();
+ }
+ this.showConsensusHistogram = showConsHist;
+ }
+
+ /**
+ * @return the showConsensusHistogram
+ */
+ public boolean isShowConsensusHistogram()
+ {
+ return showConsensusHistogram;
+ }
+
+ /**
+ * set flag indicating if logo should be normalised when rendered
+ *
+ * @param norm
+ */
+ public void setNormaliseSequenceLogo(boolean norm)
+ {
+ normaliseSequenceLogo = norm;
+ }
+
+ public boolean isNormaliseSequenceLogo()
+ {
+ return normaliseSequenceLogo;
+ }
+
+ @Override
+ /**
+ * returns a new array with all annotation involving this group
+ */
+ public AlignmentAnnotation[] getAlignmentAnnotation()
+ {
+ // TODO add in other methods like 'getAlignmentAnnotation(String label),
+ // etc'
+ ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
+ synchronized (sequences)
+ {
+ for (SequenceI seq : sequences)
+ {
+ AlignmentAnnotation[] aa = seq.getAnnotation();
+ if (aa != null)
+ {
+ for (AlignmentAnnotation al : aa)
+ {
+ if (al.groupRef == this)
+ {
+ annot.add(al);
+ }
+ }
+ }
+ }
+ if (consensus != null)
+ {
+ annot.add(consensus);
+ }
+ if (conservation != null)
+ {
+ annot.add(conservation);
+ }
+ }
+ return annot.toArray(new AlignmentAnnotation[0]);
+ }
+
+ @Override
+ public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
+ {
+ List<AlignmentAnnotation> aa = new ArrayList<>();
+ if (calcId == null)
+ {
+ return aa;
+ }
+ for (AlignmentAnnotation a : getAlignmentAnnotation())
+ {
+ if (calcId.equals(a.getCalcId()))
+ {
+ aa.add(a);
+ }
+ }
+ return aa;
+ }
+
+ @Override
+ public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
+ String calcId, String label)
+ {
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
+ for (AlignmentAnnotation ann : getAlignmentAnnotation())
+ {
+ if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
+ .equals(calcId)))
+ && (seq == null || (ann.sequenceRef != null && ann.sequenceRef == seq))
+ && (label == null || (ann.label != null && ann.label
+ .equals(label))))
+ {
+ aa.add(ann);
+ }
+ }
+ return aa;
+ }
+
+ /**
+ * Answer true if any annotation matches the calcId passed in (if not null).
+ *
+ * @param calcId
+ * @return
+ */
+ public boolean hasAnnotation(String calcId)
+ {
+ if (calcId != null && !"".equals(calcId))
+ {
+ for (AlignmentAnnotation a : getAlignmentAnnotation())
+ {
+ if (a.getCalcId() == calcId)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove all sequences from the group (leaving other properties unchanged).
+ */
+ public void clear()
+ {
+ synchronized (sequences)
+ {
+ sequences.clear();
+ }
+ }
+
+ private AnnotatedCollectionI context;
+
+ /**
+ * Sets the alignment or group context for this group, and whether it is
+ * defined as a group
+ *
+ * @param ctx
+ * the context for the group
+ * @param defined
+ * whether the group is defined on the alignment or is just a
+ * selection
+ * @throws IllegalArgumentException
+ * if setting the context would result in a circular reference chain
+ */
+ public void setContext(AnnotatedCollectionI ctx, boolean defined)
+ {
+ setContext(ctx);
+ this.isDefined = defined;
+ }
+
+ /**
+ * Sets the alignment or group context for this group
+ *
+ * @param ctx
+ * the context for the group
+ * @throws IllegalArgumentException
+ * if setting the context would result in a circular reference chain
+ */
+ public void setContext(AnnotatedCollectionI ctx)
+ {
+ AnnotatedCollectionI ref = ctx;
+ while (ref != null)
+ {
+ if (ref == this || ref.getContext() == ctx)
+ {
+ throw new IllegalArgumentException(
+ "Circular reference in SequenceGroup.context");
+ }
+ ref = ref.getContext();
+ }
+ this.context = ctx;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.datamodel.AnnotatedCollectionI#getContext()
+ */
+ @Override
+ public AnnotatedCollectionI getContext()
+ {
+ return context;
+ }
+
+ public boolean isDefined()
+ {
+ return isDefined;
+ }
+
+ public void setColourScheme(ColourSchemeI scheme)
+ {
+ if (cs == null)
+ {
+ cs = new ResidueShader();
+ }
+ cs.setColourScheme(scheme);
+ }
+
+ public void setGroupColourScheme(ResidueShaderI scheme)
+ {
+ cs = scheme;
+ }
+
+ public ColourSchemeI getColourScheme()
+ {
+ return cs == null ? null : cs.getColourScheme();
+ }
+
+ public ResidueShaderI getGroupColourScheme()
+ {
+ return cs;
+ }
+
+ @Override
+ public boolean isNucleotide()
+ {
+ if (context != null) {
+ return context.isNucleotide();
+ }
+ return false;
+ }
+
+ /**
+ * @param seq
+ * @return true if seq is a member of the group
+ */
+
+ public boolean contains(SequenceI seq1)
+ {
+ return sequences.contains(seq1);
+ }
+
+ /**
+ * @param seq
+ * @param apos
+ * @return true if startRes<=apos and endRes>=apos and seq is in the group
+ */
+ public boolean contains(SequenceI seq, int apos)
+ {
+ return (startRes <= apos && endRes >= apos) && sequences.contains(seq);