+
+ /**
+ * synthesize a column selection if none exists so it covers the given
+ * selection group. if wholewidth is false, no column selection is made if the
+ * selection group covers the whole alignment width.
+ *
+ * @param sg
+ * @param wholewidth
+ */
+ public void expandColSelection(SequenceGroup sg, boolean wholewidth)
+ {
+ int sgs, sge;
+ if (sg != null && (sgs = sg.getStartRes()) >= 0
+ && sg.getStartRes() <= (sge = sg.getEndRes())
+ && !this.hasSelectedColumns())
+ {
+ if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
+ {
+ // do nothing
+ return;
+ }
+ if (colSel == null)
+ {
+ colSel = new ColumnSelection();
+ }
+ for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
+ {
+ colSel.addElement(cspos);
+ }
+ }
+ }
+
+ /**
+ * hold status of current selection group - defined on alignment or not.
+ */
+ private boolean selectionIsDefinedGroup = false;
+
+ @Override
+ public boolean isSelectionDefinedGroup()
+ {
+ if (selectionGroup == null)
+ {
+ return false;
+ }
+ if (isSelectionGroupChanged(true))
+ {
+ selectionIsDefinedGroup = false;
+ List<SequenceGroup> gps = alignment.getGroups();
+ if (gps == null || gps.size() == 0)
+ {
+ selectionIsDefinedGroup = false;
+ }
+ else
+ {
+ selectionIsDefinedGroup = gps.contains(selectionGroup);
+ }
+ }
+ return selectionGroup.isDefined() || selectionIsDefinedGroup;
+ }
+
+ /**
+ * null, or currently highlighted results on this view
+ */
+ private SearchResultsI searchResults = null;
+
+ protected TreeModel currentTree = null;
+
+ @Override
+ public boolean hasSearchResults()
+ {
+ return searchResults != null;
+ }
+
+ @Override
+ public void setSearchResults(SearchResultsI results)
+ {
+ searchResults = results;
+ }
+
+ @Override
+ public SearchResultsI getSearchResults()
+ {
+ return searchResults;
+ }
+
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation
+ * row.
+ *
+ * @return consensus sequence as a new sequence object
+ */
+ public SequenceI getConsensusSeq()
+ {
+ if (consensus == null)
+ {
+ updateConsensus(null);
+ }
+ if (consensus == null)
+ {
+ return null;
+ }
+ StringBuffer seqs = new StringBuffer();
+ for (int i = 0; i < consensus.annotations.length; i++)
+ {
+ Annotation annotation = consensus.annotations[i];
+ if (annotation != null)
+ {
+ String description = annotation.description;
+ if (description != null && description.startsWith("["))
+ {
+ // consensus is a tie - just pick the first one
+ seqs.append(description.charAt(1));
+ }
+ else
+ {
+ seqs.append(annotation.displayCharacter);
+ }
+ }
+ }
+
+ SequenceI sq = new Sequence("Consensus", seqs.toString());
+ sq.setDescription("Percentage Identity Consensus "
+ + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+ return sq;
+ }
+
+ @Override
+ public void setCurrentTree(TreeModel tree)
+ {
+ currentTree = tree;
+ }
+
+ @Override
+ public TreeModel getCurrentTree()
+ {
+ return currentTree;
+ }
+
+ /**
+ * flag set to indicate if structure views might be out of sync with sequences
+ * in the alignment
+ */
+
+ private boolean needToUpdateStructureViews = false;
+
+ @Override
+ public boolean isUpdateStructures()
+ {
+ return needToUpdateStructureViews;
+ }
+
+ @Override
+ public void setUpdateStructures(boolean update)
+ {
+ needToUpdateStructureViews = update;
+ }
+
+ @Override
+ public boolean needToUpdateStructureViews()
+ {
+ boolean update = needToUpdateStructureViews;
+ needToUpdateStructureViews = false;
+ return update;
+ }
+
+ @Override
+ public void addSequenceGroup(SequenceGroup sequenceGroup)
+ {
+ alignment.addGroup(sequenceGroup);
+
+ Color col = sequenceGroup.idColour;
+ if (col != null)
+ {
+ col = col.brighter();
+
+ for (SequenceI sq : sequenceGroup.getSequences())
+ {
+ setSequenceColour(sq, col);
+ }
+ }
+
+ if (codingComplement != null)
+ {
+ SequenceGroup mappedGroup = MappingUtils
+ .mapSequenceGroup(sequenceGroup, this, codingComplement);
+ if (mappedGroup.getSequences().size() > 0)
+ {
+ codingComplement.getAlignment().addGroup(mappedGroup);
+
+ if (col != null)
+ {
+ for (SequenceI seq : mappedGroup.getSequences())
+ {
+ codingComplement.setSequenceColour(seq, col);
+ }
+ }
+ }
+ // propagate the structure view update flag according to our own setting
+ codingComplement.setUpdateStructures(needToUpdateStructureViews);
+ }
+ }