import jalview.datamodel.Annotation;
import jalview.datamodel.CigarArray;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
import jalview.datamodel.HiddenSequences;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.SearchResultsI;
import jalview.util.Comparison;
import jalview.util.MapList;
import jalview.util.MappingUtils;
+import jalview.util.MessageManager;
import jalview.viewmodel.styles.ViewStyle;
import jalview.workers.AlignCalcManager;
import jalview.workers.ComplementConsensusThread;
public abstract class AlignmentViewport implements AlignViewportI,
CommandListener, VamsasSource
{
- protected ViewportPositionProps posProps;
+ final protected ViewportRanges ranges;
protected ViewStyleI viewStyle = new ViewStyle();
FeaturesDisplayedI featuresDisplayed = null;
- protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> historyList = new ArrayDeque<>();
- protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> redoList = new ArrayDeque<>();
+
+ /**
+ * alignment displayed in the viewport. Please use get/setter
+ */
+ protected AlignmentI alignment;
+
+ public AlignmentViewport(AlignmentI al)
+ {
+ setAlignment(al);
+ ranges = new ViewportRanges(al);
+ }
/**
* @param name
viewStyle.setSeqNameItalics(default1);
}
- /**
- * alignment displayed in the viewport. Please use get/setter
- */
- protected AlignmentI alignment;
+
@Override
public AlignmentI getAlignment()
return isDataset;
}
+ private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
-
- // protected ColumnSelection colSel = new ColumnSelection();
+ protected ColumnSelection colSel = new ColumnSelection();
public boolean autoCalculateConsensus = true;
protected boolean ignoreGapsInConsensusCalculation = false;
- protected ResidueShaderI residueShading;
+ protected ResidueShaderI residueShading = new ResidueShader();
@Override
public void setGlobalColourScheme(ColourSchemeI cs)
{
residueShading.setConservation(hconservation);
}
- residueShading.alignmentChanged(alignment, getHiddenRepSequences());
+ residueShading.alignmentChanged(alignment, hiddenRepSequences);
}
/*
if (cs != null)
{
sg.getGroupColourScheme()
-.alignmentChanged(sg,
- getHiddenRepSequences());
+ .alignmentChanged(sg, hiddenRepSequences);
}
}
}
protected AlignmentAnnotation complementConsensus;
+ protected AlignmentAnnotation gapcounts;
+
protected AlignmentAnnotation strucConsensus;
protected AlignmentAnnotation conservation;
}
@Override
+ public AlignmentAnnotation getAlignmentGapAnnotation()
+ {
+ return gapcounts;
+ }
+
+ @Override
public AlignmentAnnotation getComplementConsensusAnnotation()
{
return complementConsensus;
}
}
- public void setHiddenColumns(ColumnSelection colsel)
+ public void setHiddenColumns(HiddenColumns hidden)
{
- posProps.setHiddenColumns(colsel);
- // this.colSel = colsel;
+ this.alignment.setHiddenColumns(hidden);
}
@Override
public ColumnSelection getColumnSelection()
{
- return posProps.getColumnSelection();
- // return colSel;
+ return colSel;
}
@Override
public void setColumnSelection(ColumnSelection colSel)
{
- posProps.setColumnSelection(colSel);
- /*this.colSel = colSel;
+ this.colSel = colSel;
if (colSel != null)
{
updateHiddenColumns();
}
- isColSelChanged(true);*/
+ isColSelChanged(true);
}
/**
@Override
public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
{
- return posProps.getHiddenRepSequences();
+ return hiddenRepSequences;
}
@Override
public void setHiddenRepSequences(
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- posProps.getHiddenRepSequences();
+ this.hiddenRepSequences = hiddenRepSequences;
}
@Override
@Override
public boolean hasHiddenColumns()
{
- return posProps.hasHiddenColumns();
- // return colSel != null && colSel.hasHiddenColumns();
+ return colSel != null
+ && alignment.getHiddenColumns().hasHiddenColumns();
}
public void updateHiddenColumns()
}
- private long sgrouphash = -1;
+ private long sgrouphash = -1, colselhash = -1;
/**
* checks current SelectionGroup against record of last hash value, and
*/
public boolean isColSelChanged(boolean b)
{
- return posProps.isColSelChanged(b);
- /*int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
+ int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
if (hc != -1 && hc != colselhash)
{
if (b)
}
return true;
}
- return false;*/
+ return false;
}
@Override
protected boolean showConsensus = true;
- private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+ protected boolean showOccupancy = true;
+
+ private Map<SequenceI, Color> sequenceColours = new HashMap<>();
protected SequenceAnnotationOrder sortAnnotationsBy = null;
*/
private boolean followHighlight = true;
- /*private int startRes;
-
- private int endRes;
-
- private int startSeq;
-
- private int endSeq;*/
-
/**
* Property change listener for changes in alignment
*
// common hide/show column stuff
- public void hideColumns(int start, int end)
- {
- posProps.hideColumns(start, end);
- }
-
- public void showColumn(int col)
- {
- posProps.showColumn(col);
- }
-
- public void showAllHiddenColumns()
- {
- posProps.showAllHiddenColumns();
- }
-
public void hideSelectedColumns()
{
if (colSel.isEmpty())
return;
}
- colSel.hideSelectedColumns();
+ colSel.hideSelectedColumns(alignment);
setSelectionGroup(null);
isColSelChanged(true);
}
+ public void hideColumns(int start, int end)
+ {
+ if (start == end)
+ {
+ colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
+ }
+ else
+ {
+ alignment.getHiddenColumns().hideColumns(start, end);
+ }
+ isColSelChanged(true);
+ }
+
+ public void showColumn(int col)
+ {
+ alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
+ isColSelChanged(true);
+ }
+ public void showAllHiddenColumns()
+ {
+ alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
+ isColSelChanged(true);
+ }
// common hide/show seq stuff
public void showAllHiddenSeqs()
{
- selectionGroup = posProps.showAllHiddenSeqs(selectionGroup);
-
- /* 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);
- }
+ 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;
+ hiddenRepSequences = null;
- firePropertyChange("alignment", null, alignment.getSequences());
- // used to set hasHiddenRows/hiddenRepSequences here, after the property
- // changed event
- sendSelection();
- }*/
+ firePropertyChange("alignment", null, alignment.getSequences());
+ // used to set hasHiddenRows/hiddenRepSequences here, after the property
+ // changed event
+ sendSelection();
+ }
}
public void showSequence(int index)
{
- posProps.showSequence(index, selectionGroup);
- /*List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
+ List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
index, hiddenRepSequences);
if (tmp.size() > 0)
{
}
firePropertyChange("alignment", null, alignment.getSequences());
sendSelection();
- }*/
+ }
}
public void hideAllSelectedSeqs()
{
- posProps.hideAllSelectedSeqs(selectionGroup);
- /*if (selectionGroup == null || selectionGroup.getSize() < 1)
+ if (selectionGroup == null || selectionGroup.getSize() < 1)
{
return;
}
hideSequence(seqs);
- setSelectionGroup(null);*/
+ setSelectionGroup(null);
}
public void hideSequence(SequenceI[] seq)
{
- posProps.hideSequence(seq);
- /*if (seq != null)
+ if (seq != null)
{
for (int i = 0; i < seq.length; i++)
{
setSequenceAnnotationsVisible(seq[i], false);
}
firePropertyChange("alignment", null, alignment.getSequences());
- }*/
+ }
}
/**
*/
public void hideSequences(SequenceI sequence, boolean representGroup)
{
- posProps.hideSequences(sequence, representGroup, selectionGroup);
- /*if (selectionGroup == null || selectionGroup.getSize() < 1)
+ if (selectionGroup == null || selectionGroup.getSize() < 1)
{
hideSequence(new SequenceI[] { sequence });
return;
hideSequence(hseqs);
setSelectionGroup(null);
- sendSelection();*/
+ 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)
{
- posProps.hideRepSequences(repSequence, sg);
- /*int sSize = sg.getSize();
+ int sSize = sg.getSize();
if (sSize < 2)
{
return;
if (hiddenRepSequences == null)
{
- hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ hiddenRepSequences = new Hashtable<>();
}
hiddenRepSequences.put(repSequence, sg);
}
sg.setSeqrep(repSequence); // note: not done in 2.7applet
sg.setHidereps(true); // note: not done in 2.7applet
- hideSequence(seqs);*/
+ hideSequence(seqs);
}
*/
public boolean isHiddenRepSequence(SequenceI seq)
{
- return posProps.isHiddenRepSequence(seq);
- // return (hiddenRepSequences != null && hiddenRepSequences
- // .containsKey(seq));
+ return (hiddenRepSequences != null && hiddenRepSequences
+ .containsKey(seq));
}
/**
*/
public SequenceGroup getRepresentedSequences(SequenceI seq)
{
- return posProps.getRepresentedSequences(seq);
- // return (SequenceGroup) (hiddenRepSequences == null ? null
- // : hiddenRepSequences.get(seq));
+ return (SequenceGroup) (hiddenRepSequences == null ? null
+ : hiddenRepSequences.get(seq));
}
@Override
public int adjustForHiddenSeqs(int alignmentIndex)
{
- return posProps.adjustForHiddenSeqs(alignmentIndex);
- // return alignment.getHiddenSequences().adjustForHiddenSeqs(
- // alignmentIndex);
+ return alignment.getHiddenSequences().adjustForHiddenSeqs(
+ alignmentIndex);
}
@Override
public void invertColumnSelection()
{
- posProps.invertColumnSelection();
- // colSel.invertColumnSelection(0, alignment.getWidth());
+ colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
}
@Override
@Override
public CigarArray getViewAsCigars(boolean selectedRegionOnly)
{
- return new CigarArray(alignment, posProps.getColumnSelection(),
+ return new CigarArray(alignment, alignment.getHiddenColumns(),
(selectedRegionOnly ? selectionGroup : null));
}
public jalview.datamodel.AlignmentView getAlignmentView(
boolean selectedOnly, boolean markGroups)
{
- return new AlignmentView(alignment, posProps.getColumnSelection(),
- selectionGroup, posProps.hasHiddenColumns(), selectedOnly,
+ return new AlignmentView(alignment, alignment.getHiddenColumns(),
+ selectionGroup, alignment.getHiddenColumns() != null
+ && alignment.getHiddenColumns().hasHiddenColumns(),
+ selectedOnly,
markGroups);
}
}
selection = new String[iSize];
- if (posProps.hasHiddenColumns())
+ if (alignment.getHiddenColumns() != null
+ && alignment.getHiddenColumns().hasHiddenColumns())
{
- selection = posProps.getVisibleSequenceStrings(start, end, seqs);
+ selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
+ start, end, seqs);
}
else
{
@Override
public List<int[]> getVisibleRegionBoundaries(int min, int max)
{
- return posProps.getVisibleRegionBoundaries(min, max);
- /* ArrayList<int[]> regions = new ArrayList<int[]>();
- int start = min;
- int end = max;
+ ArrayList<int[]> regions = new ArrayList<>();
+ int start = min;
+ int end = max;
- do
+ do
+ {
+ HiddenColumns hidden = alignment.getHiddenColumns();
+ if (hidden != null && hidden.hasHiddenColumns())
+ {
+ if (start == 0)
{
- 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;
- }
- }
+ start = hidden.adjustForHiddenColumns(start);
+ }
- regions.add(new int[] { start, end });
+ end = hidden.getHiddenBoundaryRight(start);
+ if (start == end)
+ {
+ end = max;
+ }
+ if (end > max)
+ {
+ end = max;
+ }
+ }
- if (posProps.hasHiddenColumns())
- {
- start = colSel.adjustForHiddenColumns(end);
- start = colSel.getHiddenBoundaryLeft(start) + 1;
- }
- } while (end < max);
+ regions.add(new int[] { start, end });
+
+ if (hidden != null && hidden.hasHiddenColumns())
+ {
+ start = hidden.adjustForHiddenColumns(end);
+ start = hidden.getHiddenBoundaryLeft(start) + 1;
+ }
+ } while (end < max);
- int[][] startEnd = new int[regions.size()][2];
+ int[][] startEnd = new int[regions.size()][2];
- return regions;*/
+ return regions;
}
@Override
public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
boolean selectedOnly)
{
- return posProps.getVisibleAlignmentAnnotation(selectedOnly,
- selectionGroup);
- /*ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
AlignmentAnnotation[] aa;
if ((aa = alignment.getAlignmentAnnotation()) != null)
{
AlignmentAnnotation clone = new AlignmentAnnotation(annot);
if (selectedOnly && selectionGroup != null)
{
- colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
+ alignment.getHiddenColumns().makeVisibleAnnotation(
+ selectionGroup.getStartRes(),
selectionGroup.getEndRes(), clone);
}
else
{
- colSel.makeVisibleAnnotation(clone);
+ alignment.getHiddenColumns().makeVisibleAnnotation(clone);
}
ala.add(clone);
}
}
- return ala;*/
+ return ala;
}
@Override
ResidueShaderI rs = residueShading;
if (rs != null)
{
- rs.alignmentChanged(alignment, posProps.getHiddenRepSequences());
+ rs.alignmentChanged(alignment, hiddenRepSequences);
rs.setConsensus(hconsensus);
if (rs.conservationApplied())
{
if (sg.cs != null)
{
- sg.cs.alignmentChanged(sg, posProps.getHiddenRepSequences());
+ sg.cs.alignmentChanged(sg, hiddenRepSequences);
}
sg.recalcConservation();
}
{
initRNAStructure();
}
- consensus = new AlignmentAnnotation("Consensus", "PID",
+ consensus = new AlignmentAnnotation("Consensus",
+ MessageManager.getString("label.consensus_descr"),
new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
initConsensus(consensus);
+ initGapCounts();
initComplementConsensus();
}
}
/**
- * If this is a protein alignment and there are mappings to cDNA, add the cDNA
- * consensus annotation.
+ * If this is a protein alignment and there are mappings to cDNA, adds the
+ * cDNA consensus annotation and returns true, else returns false.
*/
- public void initComplementConsensus()
+ public boolean initComplementConsensus()
{
if (!alignment.isNucleotide())
{
if (doConsensus)
{
complementConsensus = new AlignmentAnnotation("cDNA Consensus",
- "PID for cDNA", new Annotation[1], 0f, 100f,
+ MessageManager
+ .getString("label.complement_consensus_descr"),
+ new Annotation[1], 0f, 100f,
AlignmentAnnotation.BAR_GRAPH);
initConsensus(complementConsensus);
+ return true;
}
}
}
+ return false;
}
private void initConsensus(AlignmentAnnotation aa)
}
}
+ // these should be extracted from the view model - style and settings for
+ // derived annotation
+ private void initGapCounts()
+ {
+ if (showOccupancy)
+ {
+ gapcounts = new AlignmentAnnotation("Occupancy",
+ MessageManager.getString("label.occupancy_descr"),
+ new Annotation[1], 0f,
+ alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
+ gapcounts.hasText = true;
+ gapcounts.autoCalculated = true;
+ gapcounts.scaleColLabel = true;
+ gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
+
+ alignment.addAnnotation(gapcounts);
+ }
+ }
+
private void initConservation()
{
if (showConservation)
if (conservation == null)
{
conservation = new AlignmentAnnotation("Conservation",
- "Conservation of total alignment less than "
- + getConsPercGaps() + "% gaps", new Annotation[1],
+ MessageManager.formatMessage("label.conservation_descr",
+ getConsPercGaps()), new Annotation[1],
0f, 11f, AlignmentAnnotation.BAR_GRAPH);
conservation.hasText = true;
conservation.autoCalculated = true;
if (quality == null)
{
quality = new AlignmentAnnotation("Quality",
- "Alignment Quality based on Blosum62 scores",
+ MessageManager.getString("label.quality_descr"),
new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
quality.hasText = true;
quality.autoCalculated = true;
{
if (alignment.hasRNAStructure() && strucConsensus == null)
{
- strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
+ strucConsensus = new AlignmentAnnotation("StrucConsensus",
+ MessageManager.getString("label.strucconsensus_descr"),
new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
strucConsensus.hasText = true;
strucConsensus.autoCalculated = true;
// intersect alignment annotation with alignment groups
AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
- List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
+ List<SequenceGroup> oldrfs = new ArrayList<>();
if (aan != null)
{
for (int an = 0; an < aan.length; an++)
viewStyle.setScaleProteinAsCdna(b);
}
+ @Override
+ public boolean isProteinFontAsCdna()
+ {
+ return viewStyle.isProteinFontAsCdna();
+ }
+
+ @Override
+ public void setProteinFontAsCdna(boolean b)
+ {
+ viewStyle.setProteinFontAsCdna(b);
+ }
+
/**
* @return true if view should scroll to show the highlighted region of a
* sequence
}
@Override
- public ViewportPositionProps getPosProps()
+ public ViewportRanges getRanges()
{
- return posProps;
- }
-
- @Override
- public int getStartRes()
- {
- return posProps.getStartRes();
- }
-
- @Override
- public int getEndRes()
- {
- return posProps.getEndRes();
- }
-
- @Override
- public int getStartSeq()
- {
- return posProps.getStartSeq();
- }
-
- public void setStartRes(int res)
- {
- posProps.setStartRes(res);
- // this.startRes = res;
- }
-
- public void setStartSeq(int seq)
- {
- posProps.setStartSeq(seq);
- // this.startSeq = seq;
- }
-
- public void setEndRes(int res)
- {
- posProps.setEndRes(res);
- /*if (res > alignment.getWidth() - 1)
- {
- // log.System.out.println(" Corrected res from " + res + " to maximum " +
- // (alignment.getWidth()-1));
- res = alignment.getWidth() - 1;
- }
- if (res < 0)
- {
- res = 0;
- }
- this.endRes = res;*/
- }
-
- public void setEndSeq(int seq)
- {
- posProps.setEndSeq(seq);
- /*if (seq > alignment.getHeight())
- {
- seq = alignment.getHeight();
- }
- if (seq < 0)
- {
- seq = 0;
- }
- this.endSeq = seq;*/
- }
-
- @Override
- public int getEndSeq()
- {
- return posProps.getEndSeq();
- // return endSeq;
+ return ranges;
}
/**
* locate 'middle' column (true middle if an odd number visible, left of
* middle if an even number visible)
*/
- int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
+ int middleColumn = ranges.getStartRes()
+ + (ranges.getEndRes() - ranges.getStartRes()) / 2;
final HiddenSequences hiddenSequences = getAlignment()
.getHiddenSequences();
*/
int lastSeq = alignment.getHeight() - 1;
List<AlignedCodonFrame> seqMappings = null;
- for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
+ for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
{
sequence = getAlignment().getSequenceAt(seqNo);
if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
*/
public void expandColSelection(SequenceGroup sg, boolean wholewidth)
{
- if (!this.hasSelectedColumns())
- {
- posProps.expandColSelection(sg, wholewidth);
- }
- /*int sgs, sge;
+ int sgs, sge;
if (sg != null && (sgs = sg.getStartRes()) >= 0
&& sg.getStartRes() <= (sge = sg.getEndRes())
&& !this.hasSelectedColumns())
{
colSel.addElement(cspos);
}
- }*/
+ }
}
/**
*/
private boolean selectionIsDefinedGroup = false;
-
@Override
public boolean isSelectionDefinedGroup()
{
selectionIsDefinedGroup = gps.contains(selectionGroup);
}
}
- return selectionGroup.getContext() == alignment
- || selectionIsDefinedGroup;
+ return selectionGroup.isDefined() || selectionIsDefinedGroup;
}
/**