+ else
+ {
+ cs.setThreshold(0, ignoreGapsInConsensusCalculation);
+ }
+ if (recalc)
+ {
+ cs.setConsensus(hconsensus);
+ cs.setConservation(hconservation);
+ }
+ cs.setConservationApplied(getConservationSelected());
+ cs.alignmentChanged(alignment, hiddenRepSequences);
+ }
+ if (getColourAppliesToAllGroups())
+ {
+ for (SequenceGroup sg : getAlignment().getGroups())
+ {
+ if (cs == null)
+ {
+ sg.cs = null;
+ continue;
+ }
+ sg.cs = cs.applyTo(sg, getHiddenRepSequences());
+ sg.setConsPercGaps(ConsPercGaps);
+ if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
+ || cs instanceof Blosum62ColourScheme)
+ {
+ sg.cs.setThreshold(viewStyle.getThreshold(),
+ isIgnoreGapsConsensus());
+ recalc = true;
+ }
+ else
+ {
+ sg.cs.setThreshold(0, isIgnoreGapsConsensus());
+ }
+
+ if (getConservationSelected())
+ {
+ sg.cs.setConservationApplied(true);
+ recalc = true;
+ }
+ else
+ {
+ sg.cs.setConservation(null);
+ // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
+ }
+ if (recalc)
+ {
+ sg.recalcConservation();
+ }
+ else
+ {
+ sg.cs.alignmentChanged(sg, hiddenRepSequences);
+ }
+ }
+ }
+ }
+
+ @Override
+ public ColourSchemeI getGlobalColourScheme()
+ {
+ return globalColourScheme;
+ }
+
+ protected AlignmentAnnotation consensus;
+
+ protected AlignmentAnnotation complementConsensus;
+
+ protected AlignmentAnnotation strucConsensus;
+
+ protected AlignmentAnnotation conservation;
+
+ protected AlignmentAnnotation quality;
+
+ protected AlignmentAnnotation[] groupConsensus;
+
+ protected AlignmentAnnotation[] groupConservation;
+
+ /**
+ * results of alignment consensus analysis for visible portion of view
+ */
+ protected ProfilesI hconsensus = null;
+
+ /**
+ * results of cDNA complement consensus visible portion of view
+ */
+ protected Hashtable[] hcomplementConsensus = null;
+
+ /**
+ * results of secondary structure base pair consensus for visible portion of
+ * view
+ */
+ protected Hashtable[] hStrucConsensus = null;
+
+ protected Conservation hconservation = null;
+
+ @Override
+ public void setConservation(Conservation cons)
+ {
+ hconservation = cons;
+ }
+
+ /**
+ * percentage gaps allowed in a column before all amino acid properties should
+ * be considered unconserved
+ */
+ int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
+
+ @Override
+ public int getConsPercGaps()
+ {
+ return ConsPercGaps;
+ }
+
+ @Override
+ public void setSequenceConsensusHash(ProfilesI hconsensus)
+ {
+ this.hconsensus = hconsensus;
+ }
+
+ @Override
+ public void setComplementConsensusHash(Hashtable[] hconsensus)
+ {
+ this.hcomplementConsensus = hconsensus;
+ }
+
+ @Override
+ public ProfilesI getSequenceConsensusHash()
+ {
+ return hconsensus;
+ }
+
+ @Override
+ public Hashtable[] getComplementConsensusHash()
+ {
+ return hcomplementConsensus;
+ }
+
+ @Override
+ public Hashtable[] getRnaStructureConsensusHash()
+ {
+ return hStrucConsensus;
+ }
+
+ @Override
+ public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
+ {
+ this.hStrucConsensus = hStrucConsensus;
+
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentQualityAnnot()
+ {
+ return quality;
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentConservationAnnotation()
+ {
+ return conservation;
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentConsensusAnnotation()
+ {
+ return consensus;
+ }
+
+ @Override
+ public AlignmentAnnotation getComplementConsensusAnnotation()
+ {
+ return complementConsensus;
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
+ {
+ return strucConsensus;
+ }
+
+ protected AlignCalcManagerI calculator = new AlignCalcManager();
+
+ /**
+ * trigger update of conservation annotation
+ */
+ public void updateConservation(final AlignmentViewPanel ap)
+ {
+ // see note in mantis : issue number 8585
+ if (alignment.isNucleotide()
+ || (conservation == null && quality == null)
+ || !autoCalculateConsensus)
+ {
+ return;
+ }
+ if (calculator
+ .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
+ {
+ calculator.registerWorker(new jalview.workers.ConservationThread(
+ this, ap));
+ }
+ }
+
+ /**
+ * trigger update of consensus annotation
+ */
+ public void updateConsensus(final AlignmentViewPanel ap)
+ {
+ // see note in mantis : issue number 8585
+ if (consensus == null || !autoCalculateConsensus)
+ {
+ return;
+ }
+ if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
+ {
+ calculator.registerWorker(new ConsensusThread(this, ap));
+ }
+
+ /*
+ * A separate thread to compute cDNA consensus for a protein alignment
+ * which has mapping to cDNA
+ */
+ final AlignmentI al = this.getAlignment();
+ if (!al.isNucleotide() && al.getCodonFrames() != null
+ && !al.getCodonFrames().isEmpty())
+ {
+ /*
+ * fudge - check first for protein-to-nucleotide mappings
+ * (we don't want to do this for protein-to-protein)
+ */
+ boolean doConsensus = false;
+ for (AlignedCodonFrame mapping : al.getCodonFrames())
+ {
+ // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
+ MapList[] mapLists = mapping.getdnaToProt();
+ // mapLists can be empty if project load has not finished resolving seqs
+ if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
+ {
+ doConsensus = true;
+ break;
+ }
+ }
+ if (doConsensus)
+ {
+ if (calculator
+ .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
+ {
+ calculator
+ .registerWorker(new ComplementConsensusThread(this, ap));
+ }
+ }
+ }
+ }
+
+ // --------START Structure Conservation
+ public void updateStrucConsensus(final AlignmentViewPanel ap)
+ {
+ if (autoCalculateStrucConsensus && strucConsensus == null
+ && alignment.isNucleotide() && alignment.hasRNAStructure())
+ {
+ // secondary structure has been added - so init the consensus line
+ initRNAStructure();
+ }
+
+ // see note in mantis : issue number 8585
+ if (strucConsensus == null || !autoCalculateStrucConsensus)
+ {
+ return;
+ }
+ if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
+ {
+ calculator.registerWorker(new StrucConsensusThread(this, ap));
+ }
+ }
+
+ public boolean isCalcInProgress()
+ {
+ return calculator.isWorking();
+ }
+
+ @Override
+ public boolean isCalculationInProgress(
+ AlignmentAnnotation alignmentAnnotation)
+ {
+ if (!alignmentAnnotation.autoCalculated)
+ {
+ return false;
+ }
+ if (calculator.workingInvolvedWith(alignmentAnnotation))
+ {
+ // System.err.println("grey out ("+alignmentAnnotation.label+")");
+ return true;
+ }
+ return false;
+ }
+
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ /**
+ * Clean up references when this viewport is closed
+ */
+ @Override
+ public void dispose()
+ {
+ /*
+ * defensively null out references to large objects in case
+ * this object is not garbage collected (as if!)
+ */
+ consensus = null;
+ complementConsensus = null;
+ strucConsensus = null;
+ conservation = null;
+ quality = null;
+ groupConsensus = null;
+ groupConservation = null;
+ hconsensus = null;
+ hcomplementConsensus = null;
+ // colour scheme may hold reference to consensus
+ globalColourScheme = null;
+ // TODO remove listeners from changeSupport?
+ changeSupport = null;
+ setAlignment(null);
+ }
+
+ @Override
+ public boolean isClosed()
+ {
+ // TODO: check that this isClosed is only true after panel is closed, not
+ // before it is fully constructed.
+ return alignment == null;
+ }
+
+ @Override
+ public AlignCalcManagerI getCalcManager()
+ {
+ return calculator;
+ }
+
+ /**
+ * should conservation rows be shown for groups
+ */
+ protected boolean showGroupConservation = false;
+
+ /**
+ * should consensus rows be shown for groups
+ */
+ protected boolean showGroupConsensus = false;
+
+ /**
+ * should consensus profile be rendered by default
+ */
+ protected boolean showSequenceLogo = false;
+
+ /**
+ * should consensus profile be rendered normalised to row height
+ */
+ protected boolean normaliseSequenceLogo = false;
+
+ /**
+ * should consensus histograms be rendered by default
+ */
+ protected boolean showConsensusHistogram = true;
+
+ /**
+ * @return the showConsensusProfile
+ */
+ @Override
+ public boolean isShowSequenceLogo()
+ {
+ return showSequenceLogo;
+ }
+
+ /**
+ * @param showSequenceLogo
+ * the new value
+ */
+ public void setShowSequenceLogo(boolean showSequenceLogo)
+ {
+ if (showSequenceLogo != this.showSequenceLogo)
+ {
+ // TODO: decouple settings setting from calculation when refactoring
+ // annotation update method from alignframe to viewport
+ this.showSequenceLogo = showSequenceLogo;
+ calculator.updateAnnotationFor(ConsensusThread.class);
+ calculator.updateAnnotationFor(ComplementConsensusThread.class);
+ calculator.updateAnnotationFor(StrucConsensusThread.class);
+ }
+ this.showSequenceLogo = showSequenceLogo;
+ }
+
+ /**
+ * @param showConsensusHistogram
+ * the showConsensusHistogram to set
+ */
+ public void setShowConsensusHistogram(boolean showConsensusHistogram)
+ {
+ this.showConsensusHistogram = showConsensusHistogram;
+ }
+
+ /**
+ * @return the showGroupConservation
+ */
+ public boolean isShowGroupConservation()
+ {
+ return showGroupConservation;
+ }
+
+ /**
+ * @param showGroupConservation
+ * the showGroupConservation to set
+ */
+ public void setShowGroupConservation(boolean showGroupConservation)
+ {
+ this.showGroupConservation = showGroupConservation;
+ }
+
+ /**
+ * @return the showGroupConsensus
+ */
+ public boolean isShowGroupConsensus()
+ {
+ return showGroupConsensus;
+ }
+
+ /**
+ * @param showGroupConsensus
+ * the showGroupConsensus to set
+ */
+ public void setShowGroupConsensus(boolean showGroupConsensus)
+ {
+ this.showGroupConsensus = showGroupConsensus;
+ }
+
+ /**
+ *
+ * @return flag to indicate if the consensus histogram should be rendered by
+ * default
+ */
+ @Override
+ public boolean isShowConsensusHistogram()
+ {
+ return this.showConsensusHistogram;
+ }
+
+ /**
+ * when set, updateAlignment will always ensure sequences are of equal length
+ */
+ private boolean padGaps = false;
+
+ /**
+ * when set, alignment should be reordered according to a newly opened tree
+ */
+ public boolean sortByTree = false;
+
+ /**
+ *
+ *
+ * @return null or the currently selected sequence region
+ */
+ @Override
+ public SequenceGroup getSelectionGroup()
+ {
+ return selectionGroup;
+ }
+
+ /**
+ * Set the selection group for this window.
+ *
+ * @param sg
+ * - group holding references to sequences in this alignment view
+ *
+ */
+ @Override
+ public void setSelectionGroup(SequenceGroup sg)
+ {
+ selectionGroup = sg;
+ }
+
+ public void setHiddenColumns(ColumnSelection colsel)
+ {
+ this.colSel = colsel;
+ }
+
+ @Override
+ public ColumnSelection getColumnSelection()
+ {
+ return colSel;
+ }
+
+ @Override
+ public void setColumnSelection(ColumnSelection colSel)
+ {
+ this.colSel = colSel;
+ if (colSel != null)
+ {
+ updateHiddenColumns();
+ }
+ isColSelChanged(true);
+ }
+
+ /**
+ *
+ * @return
+ */
+ @Override
+ public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
+ {
+ return hiddenRepSequences;
+ }
+
+ @Override
+ public void setHiddenRepSequences(
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+ this.hiddenRepSequences = hiddenRepSequences;
+ }
+
+ @Override
+ public boolean hasSelectedColumns()
+ {
+ ColumnSelection columnSelection = getColumnSelection();
+ return columnSelection != null && columnSelection.hasSelectedColumns();
+ }
+
+ @Override
+ public boolean hasHiddenColumns()
+ {
+ return colSel != null && colSel.hasHiddenColumns();
+ }
+
+ public void updateHiddenColumns()
+ {
+ // this method doesn't really do anything now. But - it could, since a
+ // column Selection could be in the process of modification
+ // hasHiddenColumns = colSel.hasHiddenColumns();
+ }
+
+ @Override
+ public boolean hasHiddenRows()
+ {
+ return alignment.getHiddenSequences().getSize() > 0;
+ }
+
+ protected SequenceGroup selectionGroup;
+
+ public void setSequenceSetId(String newid)
+ {
+ if (sequenceSetID != null)
+ {
+ System.err
+ .println("Warning - overwriting a sequenceSetId for a viewport!");
+ }
+ sequenceSetID = new String(newid);
+ }
+
+ @Override
+ public String getSequenceSetId()
+ {
+ if (sequenceSetID == null)
+ {
+ sequenceSetID = alignment.hashCode() + "";
+ }
+
+ return sequenceSetID;
+ }
+
+ /**
+ * unique viewId for synchronizing state (e.g. with stored Jalview Project)
+ *
+ */
+ protected String viewId = null;
+
+ @Override
+ public String getViewId()
+ {
+ if (viewId == null)
+ {
+ viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
+ }
+ return viewId;
+ }
+
+ public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
+ {
+ ignoreGapsInConsensusCalculation = b;
+ if (ap != null)
+ {
+ updateConsensus(ap);
+ if (globalColourScheme != null)
+ {
+ globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
+ ignoreGapsInConsensusCalculation);
+ }
+ }
+
+ }
+
+ private long sgrouphash = -1, colselhash = -1;
+
+ /**
+ * checks current SelectionGroup against record of last hash value, and
+ * updates record.
+ *
+ * @param b
+ * update the record of last hash value
+ *
+ * @return true if SelectionGroup changed since last call (when b is true)
+ */
+ public boolean isSelectionGroupChanged(boolean b)
+ {
+ int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
+ : selectionGroup.hashCode();
+ if (hc != -1 && hc != sgrouphash)
+ {
+ if (b)
+ {
+ sgrouphash = hc;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * checks current colsel against record of last hash value, and optionally
+ * updates record.
+ *
+ * @param b
+ * update the record of last hash value
+ * @return true if colsel changed since last call (when b is true)
+ */
+ public boolean isColSelChanged(boolean b)
+ {
+ int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
+ if (hc != -1 && hc != colselhash)
+ {
+ if (b)
+ {
+ colselhash = hc;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensusCalculation;
+ }
+
+ // property change stuff
+ // JBPNote Prolly only need this in the applet version.
+ private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
+ this);
+
+ protected boolean showConservation = true;
+
+ protected boolean showQuality = true;
+
+ protected boolean showConsensus = true;
+
+ private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+
+ protected SequenceAnnotationOrder sortAnnotationsBy = null;
+
+ protected boolean showAutocalculatedAbove;
+
+ /**
+ * when set, view will scroll to show the highlighted position
+ */
+ private boolean followHighlight = true;
+
+ // TODO private with getters and setters?
+ public int startRes;
+
+ public int endRes;
+
+ public int startSeq;
+
+ public int endSeq;
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param listener
+ * DOCUMENT ME!
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener
+ * DOCUMENT ME!
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param prop
+ * DOCUMENT ME!
+ * @param oldvalue
+ * DOCUMENT ME!
+ * @param newvalue
+ * DOCUMENT ME!
+ */
+ public void firePropertyChange(String prop, Object oldvalue,
+ Object newvalue)
+ {
+ changeSupport.firePropertyChange(prop, oldvalue, newvalue);
+ }
+
+ // common hide/show column stuff
+
+ public void hideSelectedColumns()
+ {
+ if (colSel.isEmpty())
+ {
+ return;
+ }
+
+ colSel.hideSelectedColumns();
+ setSelectionGroup(null);
+ isColSelChanged(true);
+ }
+
+ public void hideColumns(int start, int end)
+ {
+ if (start == end)
+ {
+ colSel.hideColumns(start);
+ }
+ else
+ {
+ colSel.hideColumns(start, end);
+ }
+ isColSelChanged(true);
+ }
+
+ public void showColumn(int col)
+ {
+ colSel.revealHiddenColumns(col);
+ isColSelChanged(true);
+ }
+
+ public void showAllHiddenColumns()
+ {
+ colSel.revealAllHiddenColumns();
+ isColSelChanged(true);
+ }
+
+ // common hide/show seq stuff
+ public void showAllHiddenSeqs()
+ {
+ if (alignment.getHiddenSequences().getSize() > 0)
+ {
+ if (selectionGroup == null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth() - 1);
+ }
+ List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
+ hiddenRepSequences);
+ for (SequenceI seq : tmp)
+ {
+ selectionGroup.addSequence(seq, false);
+ setSequenceAnnotationsVisible(seq, true);
+ }
+
+ hiddenRepSequences = null;
+
+ firePropertyChange("alignment", null, alignment.getSequences());
+ // used to set hasHiddenRows/hiddenRepSequences here, after the property
+ // changed event
+ sendSelection();
+ }
+ }
+
+ public void showSequence(int index)
+ {
+ List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
+ index, hiddenRepSequences);
+ if (tmp.size() > 0)
+ {
+ if (selectionGroup == null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth() - 1);
+ }
+
+ for (SequenceI seq : tmp)
+ {
+ selectionGroup.addSequence(seq, false);
+ setSequenceAnnotationsVisible(seq, true);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ sendSelection();
+ }
+ }
+
+ public void hideAllSelectedSeqs()
+ {
+ if (selectionGroup == null || selectionGroup.getSize() < 1)
+ {
+ return;
+ }
+
+ SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
+
+ hideSequence(seqs);
+
+ setSelectionGroup(null);
+ }
+
+ public void hideSequence(SequenceI[] seq)
+ {
+ if (seq != null)
+ {
+ for (int i = 0; i < seq.length; i++)
+ {
+ alignment.getHiddenSequences().hideSequence(seq[i]);
+ setSequenceAnnotationsVisible(seq[i], false);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+ }
+
+ /**
+ * Hides the specified sequence, or the sequences it represents
+ *
+ * @param sequence
+ * the sequence to hide, or keep as representative
+ * @param representGroup
+ * if true, hide the current selection group except for the
+ * representative sequence
+ */
+ public void hideSequences(SequenceI sequence, boolean representGroup)
+ {
+ if (selectionGroup == null || selectionGroup.getSize() < 1)
+ {
+ hideSequence(new SequenceI[] { sequence });
+ return;
+ }
+
+ if (representGroup)
+ {
+ hideRepSequences(sequence, selectionGroup);
+ setSelectionGroup(null);
+ return;
+ }
+
+ int gsize = selectionGroup.getSize();
+ SequenceI[] hseqs = selectionGroup.getSequences().toArray(
+ new SequenceI[gsize]);
+
+ hideSequence(hseqs);
+ setSelectionGroup(null);
+ sendSelection();
+ }
+
+ /**
+ * Set visibility for any annotations for the given sequence.
+ *
+ * @param sequenceI
+ */
+ protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
+ boolean visible)
+ {
+ AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
+ if (anns != null)
+ {
+ for (AlignmentAnnotation ann : anns)
+ {
+ if (ann.sequenceRef == sequenceI)
+ {
+ ann.visible = visible;
+ }
+ }
+ }
+ }
+
+ public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
+ {
+ int sSize = sg.getSize();
+ if (sSize < 2)
+ {
+ return;
+ }
+
+ if (hiddenRepSequences == null)
+ {
+ hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ }
+
+ hiddenRepSequences.put(repSequence, sg);
+
+ // Hide all sequences except the repSequence
+ SequenceI[] seqs = new SequenceI[sSize - 1];
+ int index = 0;
+ for (int i = 0; i < sSize; i++)
+ {
+ if (sg.getSequenceAt(i) != repSequence)
+ {
+ if (index == sSize - 1)
+ {
+ return;
+ }
+
+ seqs[index++] = sg.getSequenceAt(i);
+ }
+ }
+ sg.setSeqrep(repSequence); // note: not done in 2.7applet
+ sg.setHidereps(true); // note: not done in 2.7applet
+ hideSequence(seqs);
+
+ }
+
+ /**
+ *
+ * @return null or the current reference sequence
+ */
+ public SequenceI getReferenceSeq()
+ {
+ return alignment.getSeqrep();
+ }
+
+ /**
+ * @param seq
+ * @return true iff seq is the reference for the alignment
+ */
+ public boolean isReferenceSeq(SequenceI seq)
+ {
+ return alignment.getSeqrep() == seq;
+ }
+
+ /**
+ *
+ * @param seq
+ * @return true if there are sequences represented by this sequence that are
+ * currently hidden
+ */
+ public boolean isHiddenRepSequence(SequenceI seq)
+ {
+ return (hiddenRepSequences != null && hiddenRepSequences
+ .containsKey(seq));
+ }
+
+ /**
+ *
+ * @param seq
+ * @return null or a sequence group containing the sequences that seq
+ * represents
+ */
+ public SequenceGroup getRepresentedSequences(SequenceI seq)
+ {
+ return (SequenceGroup) (hiddenRepSequences == null ? null
+ : hiddenRepSequences.get(seq));
+ }
+
+ @Override
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ return alignment.getHiddenSequences().adjustForHiddenSeqs(
+ alignmentIndex);
+ }
+
+ @Override
+ public void invertColumnSelection()
+ {
+ colSel.invertColumnSelection(0, alignment.getWidth());
+ }
+
+ @Override
+ public SequenceI[] getSelectionAsNewSequence()
+ {
+ SequenceI[] sequences;
+ // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
+ // this was the only caller in the applet for this method
+ // JBPNote: in applet, this method returned references to the alignment
+ // sequences, and it did not honour the presence/absence of annotation
+ // attached to the alignment (probably!)
+ if (selectionGroup == null || selectionGroup.getSize() == 0)
+ {
+ sequences = alignment.getSequencesArray();
+ AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
+ for (int i = 0; i < sequences.length; i++)
+ {
+ // construct new sequence with subset of visible annotation
+ sequences[i] = new Sequence(sequences[i], annots);
+ }
+ }
+ else
+ {
+ sequences = selectionGroup.getSelectionAsNewSequences(alignment);
+ }
+
+ return sequences;
+ }
+
+ @Override
+ public SequenceI[] getSequenceSelection()
+ {
+ SequenceI[] sequences = null;
+ if (selectionGroup != null)
+ {
+ sequences = selectionGroup.getSequencesInOrder(alignment);
+ }
+ if (sequences == null)
+ {
+ sequences = alignment.getSequencesArray();
+ }
+ return sequences;
+ }
+
+ @Override
+ public CigarArray getViewAsCigars(boolean selectedRegionOnly)
+ {
+ return new CigarArray(alignment, colSel,
+ (selectedRegionOnly ? selectionGroup : null));
+ }
+
+ @Override
+ public jalview.datamodel.AlignmentView getAlignmentView(
+ boolean selectedOnly)
+ {
+ return getAlignmentView(selectedOnly, false);
+ }
+
+ @Override
+ public jalview.datamodel.AlignmentView getAlignmentView(
+ boolean selectedOnly, boolean markGroups)
+ {
+ return new AlignmentView(alignment, colSel, selectionGroup,
+ colSel != null && colSel.hasHiddenColumns(), selectedOnly,
+ markGroups);
+ }
+
+ @Override
+ public String[] getViewAsString(boolean selectedRegionOnly)
+ {
+ return getViewAsString(selectedRegionOnly, true);
+ }
+
+ @Override
+ public String[] getViewAsString(boolean selectedRegionOnly,
+ boolean exportHiddenSeqs)
+ {
+ String[] selection = null;
+ SequenceI[] seqs = null;
+ int i, iSize;
+ int start = 0, end = 0;
+ if (selectedRegionOnly && selectionGroup != null)
+ {
+ iSize = selectionGroup.getSize();
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes() + 1;
+ }
+ else
+ {
+ if (hasHiddenRows() && exportHiddenSeqs)
+ {
+ AlignmentI fullAlignment = alignment.getHiddenSequences()
+ .getFullAlignment();
+ iSize = fullAlignment.getHeight();
+ seqs = fullAlignment.getSequencesArray();
+ end = fullAlignment.getWidth();
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth();
+ }
+ }
+
+ selection = new String[iSize];
+ if (colSel != null && colSel.hasHiddenColumns())
+ {
+ selection = colSel.getVisibleSequenceStrings(start, end, seqs);
+ }
+ else
+ {
+ for (i = 0; i < iSize; i++)
+ {
+ selection[i] = seqs[i].getSequenceAsString(start, end);
+ }
+
+ }
+ return selection;
+ }
+
+ @Override
+ public List<int[]> getVisibleRegionBoundaries(int min, int max)
+ {
+ ArrayList<int[]> regions = new ArrayList<int[]>();
+ int start = min;
+ int end = max;
+
+ do
+ {
+ if (colSel != null && colSel.hasHiddenColumns())
+ {
+ if (start == 0)
+ {
+ start = colSel.adjustForHiddenColumns(start);
+ }
+
+ end = colSel.getHiddenBoundaryRight(start);
+ if (start == end)
+ {
+ end = max;
+ }
+ if (end > max)
+ {
+ end = max;
+ }
+ }
+
+ regions.add(new int[] { start, end });
+
+ if (colSel != null && colSel.hasHiddenColumns())
+ {
+ start = colSel.adjustForHiddenColumns(end);
+ start = colSel.getHiddenBoundaryLeft(start) + 1;
+ }
+ } while (end < max);
+
+ int[][] startEnd = new int[regions.size()][2];
+
+ return regions;
+ }
+
+ @Override
+ public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
+ boolean selectedOnly)
+ {
+ ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+ AlignmentAnnotation[] aa;
+ if ((aa = alignment.getAlignmentAnnotation()) != null)
+ {
+ for (AlignmentAnnotation annot : aa)
+ {
+ AlignmentAnnotation clone = new AlignmentAnnotation(annot);
+ if (selectedOnly && selectionGroup != null)
+ {
+ colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
+ selectionGroup.getEndRes(), clone);
+ }
+ else
+ {
+ colSel.makeVisibleAnnotation(clone);
+ }
+ ala.add(clone);
+ }
+ }
+ return ala;
+ }
+
+ @Override
+ public boolean isPadGaps()
+ {
+ return padGaps;
+ }