X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=23c1d003cdcb2a327b363b39496a7c56ddc19057;hb=940b13e266be76ac186330c615c39989cce654c7;hp=58dba9d0d605f6f6511411e1e9687fa3164760d9;hpb=4389a166735bf1203894abdf3cf7dd57c4856dbc;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 58dba9d..23c1d00 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -68,6 +68,7 @@ import java.util.BitSet; import java.util.Deque; import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -97,47 +98,22 @@ public abstract class AlignmentViewport protected Deque redoList = new ArrayDeque<>(); - protected String sequenceSetID; - + /** + * alignment displayed in the viewport. Please use get/setter + */ + protected AlignmentI alignment; + /* * probably unused indicator that view is of a dataset rather than an * alignment */ - protected boolean isDataset = false; - - private Map hiddenRepSequences; - - protected ColumnSelection colSel = new ColumnSelection(); - - public boolean autoCalculateConsensus = true; - - protected boolean autoCalculateStrucConsensus = true; - - protected boolean ignoreGapsInConsensusCalculation = false; protected boolean ignoreBelowBackGroundFrequencyCalculation = false; protected boolean infoLetterHeight = false; - protected ResidueShaderI residueShading = new ResidueShader(); - - protected AlignmentAnnotation consensus; - - protected AlignmentAnnotation complementConsensus; - protected AlignmentAnnotation occupancy; - - protected AlignmentAnnotation strucConsensus; - - protected AlignmentAnnotation conservation; - - protected AlignmentAnnotation quality; - - /** - * alignment displayed in the viewport - */ - private AlignmentI alignment; - + /** * results of alignment consensus analysis for visible portion of view */ @@ -148,19 +124,6 @@ public abstract class AlignmentViewport */ protected ProfilesI hmmProfiles; - /** - * results of cDNA complement consensus visible portion of view - */ - protected Hashtable[] hcomplementConsensus; - - /** - * results of secondary structure base pair consensus for visible portion of - * view - */ - protected Hashtable[] hStrucConsensus; - - protected Conservation hconservation; - public AlignmentViewport(AlignmentI al) { setAlignment(al); @@ -640,6 +603,14 @@ public abstract class AlignmentViewport return alignment.getGapCharacter(); } + protected String sequenceSetID; + + /** + * probably unused indicator that view is of a dataset rather than an + * alignment + */ + protected boolean isDataset = false; + public void setDataset(boolean b) { isDataset = b; @@ -650,6 +621,18 @@ public abstract class AlignmentViewport return isDataset; } + private Map hiddenRepSequences; + + protected ColumnSelection colSel = new ColumnSelection(); + + public boolean autoCalculateConsensus = true; + + protected boolean autoCalculateStrucConsensus = true; + + protected boolean ignoreGapsInConsensusCalculation = false; + + protected ResidueShaderI residueShading = new ResidueShader(); + @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -701,7 +684,8 @@ public abstract class AlignmentViewport * retain any colour thresholds per group while * changing choice of colour scheme (JAL-2386) */ - sg.setColourScheme(cs); + sg.setColourScheme( + cs == null ? null : cs.getInstance(this, sg)); if (cs != null) { sg.getGroupColourScheme().alignmentChanged(sg, @@ -722,6 +706,41 @@ public abstract class AlignmentViewport { return residueShading; } + + protected AlignmentAnnotation consensus; + + protected AlignmentAnnotation complementConsensus; + + protected AlignmentAnnotation gapcounts; + + 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) { @@ -741,9 +760,9 @@ public abstract class AlignmentViewport } @Override - public void setConsensusProfiles(ProfilesI hconsensus) + public void setSequenceConsensusHash(ProfilesI hconsensus) { - this.consensusProfiles = hconsensus; + this.hconsensus = hconsensus; } @Override @@ -753,9 +772,9 @@ public abstract class AlignmentViewport } @Override - public ProfilesI getConsensusProfiles() + public ProfilesI getSequenceConsensusHash() { - return consensusProfiles; + return hconsensus; } @Override @@ -808,9 +827,9 @@ public abstract class AlignmentViewport } @Override - public AlignmentAnnotation getOccupancyAnnotation() + public AlignmentAnnotation getAlignmentGapAnnotation() { - return occupancy; + return gapcounts; } @Override @@ -899,18 +918,14 @@ public abstract class AlignmentViewport } } - /** - * trigger update of information annotation - */ @Override - public void updateInformation(final AlignmentViewPanel ap) + public void initInformationWorker(final AlignmentViewPanel ap) { if (calculator .getRegisteredWorkersOfClass(InformationThread.class) == null) { calculator.registerWorker(new InformationThread(this, ap)); } - } // --------START Structure Conservation @@ -977,9 +992,12 @@ public abstract class AlignmentViewport conservation = null; quality = null; consensusProfiles = null; + groupConsensus = null; + groupConservation = null; + hconsensus = null; hconservation = null; hcomplementConsensus = null; - occupancy = null; + gapcounts = null; calculator = null; residueShading = null; // may hold a reference to Consensus changeSupport = null; @@ -1031,17 +1049,17 @@ public abstract class AlignmentViewport /** * should hmm profile be rendered by default */ - protected boolean showHMMSequenceLogo = false; + protected boolean hmmShowSequenceLogo = false; /** * should hmm profile be rendered normalised to row height */ - protected boolean normaliseHMMSequenceLogo = false; + protected boolean hmmNormaliseSequenceLogo = false; /** * should information histograms be rendered by default */ - protected boolean showInformationHistogram = true; + protected boolean hmmShowHistogram = true; /** * @return the showConsensusProfile @@ -1058,7 +1076,7 @@ public abstract class AlignmentViewport @Override public boolean isShowHMMSequenceLogo() { - return showHMMSequenceLogo; + return hmmShowSequenceLogo; } /** @@ -1081,12 +1099,14 @@ public abstract class AlignmentViewport public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo) { - if (showHMMSequenceLogo != this.showHMMSequenceLogo) + if (showHMMSequenceLogo != this.hmmShowSequenceLogo) { - this.showHMMSequenceLogo = showHMMSequenceLogo; - calculator.updateAnnotationFor(InformationThread.class); + this.hmmShowSequenceLogo = showHMMSequenceLogo; + // TODO: updateAnnotation if description (tooltip) will show + // profile in place of information content? + // calculator.updateAnnotationFor(InformationThread.class); } - this.showHMMSequenceLogo = showHMMSequenceLogo; + this.hmmShowSequenceLogo = showHMMSequenceLogo; } /** @@ -1100,11 +1120,10 @@ public abstract class AlignmentViewport /** * @param showInformationHistogram - * the showInformationHistogram to set */ public void setShowInformationHistogram(boolean showInformationHistogram) { - this.showInformationHistogram = showInformationHistogram; + this.hmmShowHistogram = showInformationHistogram; } /** @@ -1160,7 +1179,7 @@ public abstract class AlignmentViewport @Override public boolean isShowInformationHistogram() { - return this.showInformationHistogram; + return this.hmmShowHistogram; } /** @@ -1323,22 +1342,12 @@ public abstract class AlignmentViewport public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) { - boolean was = ignoreBelowBackGroundFrequencyCalculation; ignoreBelowBackGroundFrequencyCalculation = b; - if (ap != null && was != b) - { - updateInformation(ap); - } } public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap) { - boolean was = infoLetterHeight; infoLetterHeight = b; - if (ap != null && was != b) - { - updateInformation(ap); - } } private long sgrouphash = -1, colselhash = -1; @@ -1749,6 +1758,7 @@ public abstract class AlignmentViewport public void invertColumnSelection() { colSel.invertColumnSelection(0, alignment.getWidth(), alignment); + isColSelChanged(true); } @Override @@ -1854,8 +1864,12 @@ public abstract class AlignmentViewport if (alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = alignment.getHiddenColumns() - .getVisibleSequenceStrings(start, end, seqs); + for (i = 0; i < iSize; i++) + { + Iterator blocks = alignment.getHiddenColumns() + .getVisContigsIterator(start, end + 1, false); + selection[i] = seqs[i].getSequenceStringFromIterator(blocks); + } } else { @@ -1882,10 +1896,10 @@ public abstract class AlignmentViewport { if (start == 0) { - start = hidden.adjustForHiddenColumns(start); + start = hidden.visibleToAbsoluteColumn(start); } - end = hidden.getHiddenBoundaryRight(start); + end = hidden.getNextHiddenBoundary(false, start); if (start == end) { end = max; @@ -1900,8 +1914,8 @@ public abstract class AlignmentViewport if (hidden != null && hidden.hasHiddenColumns()) { - start = hidden.adjustForHiddenColumns(end); - start = hidden.getHiddenBoundaryLeft(start) + 1; + start = hidden.visibleToAbsoluteColumn(end); + start = hidden.getNextHiddenBoundary(true, start) + 1; } } while (end < max); @@ -1923,13 +1937,13 @@ public abstract class AlignmentViewport AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - alignment.getHiddenColumns().makeVisibleAnnotation( + clone.makeVisibleAnnotation( selectionGroup.getStartRes(), selectionGroup.getEndRes(), - clone); + alignment.getHiddenColumns()); } else { - alignment.getHiddenColumns().makeVisibleAnnotation(clone); + clone.makeVisibleAnnotation(alignment.getHiddenColumns()); } ala.add(clone); } @@ -1966,7 +1980,7 @@ public abstract class AlignmentViewport { updateConsensus(ap); } - if (consensusProfiles != null && autoCalculateConsensus) + if (hconsensus != null && autoCalculateConsensus) { updateConservation(ap); } @@ -1974,8 +1988,6 @@ public abstract class AlignmentViewport { updateStrucConsensus(ap); } - // initInformation(); - updateInformation(ap); // Reset endRes of groups if beyond alignment width int alWidth = alignment.getWidth(); @@ -1998,7 +2010,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -2011,7 +2022,7 @@ public abstract class AlignmentViewport { rs.alignmentChanged(alignment, hiddenRepSequences); - rs.setConsensus(consensusProfiles); + rs.setConsensus(hconsensus); if (rs.conservationApplied()) { rs.setConservation(Conservation.calculateConservation("All", @@ -2036,7 +2047,7 @@ public abstract class AlignmentViewport // depending on if the user wants to see the annotation or not in a // specific alignment - if (consensusProfiles == null && !isDataset) + if (hconsensus == null && !isDataset) { if (!alignment.isNucleotide()) { @@ -2052,7 +2063,7 @@ public abstract class AlignmentViewport new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); - initOccupancy(); + initGapCounts(); initComplementConsensus(); } @@ -2111,20 +2122,20 @@ public abstract class AlignmentViewport // these should be extracted from the view model - style and settings for // derived annotation - private void initOccupancy() + private void initGapCounts() { if (showOccupancy) { - occupancy = new AlignmentAnnotation("Occupancy", + gapcounts = new AlignmentAnnotation("Occupancy", MessageManager.getString("label.occupancy_descr"), new Annotation[1], 0f, alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH); - occupancy.hasText = true; - occupancy.autoCalculated = true; - occupancy.scaleColLabel = true; - occupancy.graph = AlignmentAnnotation.BAR_GRAPH; + gapcounts.hasText = true; + gapcounts.autoCalculated = true; + gapcounts.scaleColLabel = true; + gapcounts.graph = AlignmentAnnotation.BAR_GRAPH; - alignment.addAnnotation(occupancy); + alignment.addAnnotation(gapcounts); } } @@ -2298,7 +2309,7 @@ public abstract class AlignmentViewport sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); - sg.setshowHMMSequenceLogo(showHMMPrf); + sg.setShowHMMSequenceLogo(showHMMPrf); sg.setShowInformationHistogram(showInfoHist); sg.setNormaliseHMMSequenceLogo(normHMMLogo); } @@ -2904,7 +2915,7 @@ public abstract class AlignmentViewport int lastSeq = alignment.getHeight() - 1; List seqMappings = null; for (int seqNo = ranges - .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) @@ -3085,4 +3096,90 @@ public abstract class AlignmentViewport { return currentTree; } + + @Override + public boolean isNormaliseSequenceLogo() + { + return normaliseSequenceLogo; + } + + public void setNormaliseSequenceLogo(boolean state) + { + normaliseSequenceLogo = state; + } + + @Override + public boolean isNormaliseHMMSequenceLogo() + { + return hmmNormaliseSequenceLogo; + } + + public void setNormaliseHMMSequenceLogo(boolean state) + { + hmmNormaliseSequenceLogo = state; + } + + /** + * 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); + } + } }