+
+ /**
+ * @return the idColour
+ */
+ public Color getIdColour()
+ {
+ return idColour;
+ }
+
+ /**
+ * @param idColour
+ * the idColour to set
+ */
+ public void setIdColour(Color idColour)
+ {
+ this.idColour = idColour;
+ }
+
+ /**
+ * @return the representative sequence for this group
+ */
+ public SequenceI getSeqrep()
+ {
+ return seqrep;
+ }
+
+ /**
+ * set the representative sequence for this group. Note - this affects the
+ * interpretation of the Hidereps attribute.
+ *
+ * @param seqrep
+ * the seqrep to set (null means no sequence representative)
+ */
+ public void setSeqrep(SequenceI seqrep)
+ {
+ this.seqrep = seqrep;
+ }
+
+ /**
+ *
+ * @return true if group has a sequence representative
+ */
+ public boolean hasSeqrep()
+ {
+ return seqrep != null;
+ }
+
+ /**
+ * visibility of rows or represented rows covered by group
+ */
+ private boolean hidereps = false;
+
+ /**
+ * set visibility of sequences covered by (if no sequence representative is
+ * defined) or represented by this group.
+ *
+ * @param visibility
+ */
+ public void setHidereps(boolean visibility)
+ {
+ hidereps = visibility;
+ }
+
+ /**
+ *
+ * @return true if sequences represented (or covered) by this group should be
+ * hidden
+ */
+ public boolean isHidereps()
+ {
+ return hidereps;
+ }
+
+ /**
+ * visibility of columns intersecting this group
+ */
+ private boolean hidecols = false;
+
+ /**
+ * set intended visibility of columns covered by this group
+ *
+ * @param visibility
+ */
+ public void setHideCols(boolean visibility)
+ {
+ hidecols = visibility;
+ }
+
+ /**
+ *
+ * @return true if columns covered by group should be hidden
+ */
+ public boolean isHideCols()
+ {
+ return hidecols;
+ }
+
+ /**
+ * create a new sequence group from the intersection of this group with an
+ * alignment Hashtable of hidden representatives
+ *
+ * @param alignment
+ * (may not be null)
+ * @param map
+ * (may be null)
+ * @return new group containing sequences common to this group and alignment
+ */
+ public SequenceGroup intersect(AlignmentI alignment,
+ Map<SequenceI, SequenceCollectionI> map)
+ {
+ SequenceGroup sgroup = new SequenceGroup(this);
+ SequenceI[] insect = getSequencesInOrder(alignment);
+ sgroup.sequences = new Vector();
+ for (int s = 0; insect != null && s < insect.length; s++)
+ {
+ if (map == null || map.containsKey(insect[s]))
+ {
+ sgroup.sequences.addElement(insect[s]);
+ }
+ }
+ // Enumeration en =getSequences(hashtable).elements();
+ // while (en.hasMoreElements())
+ // {
+ // SequenceI elem = (SequenceI) en.nextElement();
+ // if (alignment.getSequences().contains(elem))
+ // {
+ // sgroup.addSequence(elem, false);
+ // }
+ // }
+ return sgroup;
+ }
+
+ /**
+ * @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
+ */
+ 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<AlignmentAnnotation>();
+ 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)
+ {
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ for (AlignmentAnnotation a : getAlignmentAnnotation())
+ {
+ if (a.getCalcId() == calcId)
+ {
+ aa.add(a);
+ }
+ }
+ return aa;
+ }
+
+ /**
+ * Returns a list of annotations that match the specified sequenceRef, calcId
+ * and label, ignoring null values.
+ *
+ * @return list of AlignmentAnnotation objects
+ */
+ @Override
+ public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
+ String calcId, String label)
+ {
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ for (AlignmentAnnotation ann : getAlignmentAnnotation())
+ {
+ if (ann.getCalcId() != null && ann.getCalcId().equals(calcId)
+ && ann.sequenceRef != null && ann.sequenceRef == seq
+ && 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;
+ }
+
+ public void clear()
+ {
+ sequences.clear();
+ }
+
+ private AnnotatedCollectionI context;
+
+ /**
+ * set the alignment or group context for this group
+ *
+ * @param context
+ */
+ public void setContext(AnnotatedCollectionI context)
+ {
+ this.context = context;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.datamodel.AnnotatedCollectionI#getContext()
+ */
+ @Override
+ public AnnotatedCollectionI getContext()
+ {
+ return context;
+ }