X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=8f1fc83d622aa6f897141eb7ce8e0778288e0a83;hb=c794c5033adeee182b03a5ea92c0a7495a29661f;hp=44dfe8d0fe96b969b81b0bdc0329485fca68348f;hpb=62086b8b7a0b9436c445a94bfab5eff253adb6d5;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 44dfe8d..8f1fc83 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -24,6 +24,7 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; import jalview.api.AlignCalcManagerI; +import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeaturesDisplayedI; @@ -31,6 +32,7 @@ import jalview.api.ViewStyleI; import jalview.commands.CommandI; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentExportData; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.Annotation; @@ -57,6 +59,7 @@ import jalview.viewmodel.styles.ViewStyle; import jalview.workers.AlignCalcManager; import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; +import jalview.workers.InformationThread; import jalview.workers.StrucConsensusThread; import java.awt.Color; @@ -67,6 +70,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; @@ -100,6 +104,27 @@ public abstract class AlignmentViewport * 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 ignoreBelowBackGroundFrequencyCalculation = false; + + protected boolean infoLetterHeight = false; + + protected AlignmentAnnotation occupancy; + + /** + * results of alignment consensus analysis for visible portion of view + */ + protected ProfilesI consensusProfiles; + + /** + * HMM profile for the alignment + */ + protected ProfilesI hmmProfiles; public AlignmentViewport(AlignmentI al) { @@ -587,7 +612,7 @@ public abstract class AlignmentViewport * alignment */ protected boolean isDataset = false; - + public void setDataset(boolean b) { isDataset = b; @@ -609,7 +634,7 @@ public abstract class AlignmentViewport protected boolean ignoreGapsInConsensusCalculation = false; protected ResidueShaderI residueShading = new ResidueShader(); - + @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -661,7 +686,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, @@ -682,7 +708,7 @@ public abstract class AlignmentViewport { return residueShading; } - + protected AlignmentAnnotation consensus; protected AlignmentAnnotation complementConsensus; @@ -707,16 +733,16 @@ public abstract class AlignmentViewport /** * results of cDNA complement consensus visible portion of view */ - protected Hashtable[] hcomplementConsensus = null; + protected Hashtable[] hcomplementConsensus = null; /** * results of secondary structure base pair consensus for visible portion of * view */ - protected Hashtable[] hStrucConsensus = null; + protected Hashtable[] hStrucConsensus = null; protected Conservation hconservation = null; - + @Override public void setConservation(Conservation cons) { @@ -742,7 +768,8 @@ public abstract class AlignmentViewport } @Override - public void setComplementConsensusHash(Hashtable[] hconsensus) + public void setComplementConsensusHash( + Hashtable[] hconsensus) { this.hcomplementConsensus = hconsensus; } @@ -754,19 +781,32 @@ public abstract class AlignmentViewport } @Override - public Hashtable[] getComplementConsensusHash() + public void setHmmProfiles(ProfilesI info) + { + hmmProfiles = info; + } + + @Override + public ProfilesI getHmmProfiles() + { + return hmmProfiles; + } + + @Override + public Hashtable[] getComplementConsensusHash() { return hcomplementConsensus; } @Override - public Hashtable[] getRnaStructureConsensusHash() + public Hashtable[] getRnaStructureConsensusHash() { return hStrucConsensus; } @Override - public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus) + public void setRnaStructureConsensusHash( + Hashtable[] hStrucConsensus) { this.hStrucConsensus = hStrucConsensus; @@ -882,6 +922,16 @@ public abstract class AlignmentViewport } } + @Override + public void initInformationWorker(final AlignmentViewPanel ap) + { + if (calculator + .getRegisteredWorkersOfClass(InformationThread.class) == null) + { + calculator.registerWorker(new InformationThread(this, ap)); + } + } + // --------START Structure Conservation public void updateStrucConsensus(final AlignmentViewPanel ap) { @@ -945,6 +995,7 @@ public abstract class AlignmentViewport strucConsensus = null; conservation = null; quality = null; + consensusProfiles = null; groupConsensus = null; groupConservation = null; hconsensus = null; @@ -1000,6 +1051,21 @@ public abstract class AlignmentViewport protected boolean showConsensusHistogram = true; /** + * should hmm profile be rendered by default + */ + protected boolean hmmShowSequenceLogo = false; + + /** + * should hmm profile be rendered normalised to row height + */ + protected boolean hmmNormaliseSequenceLogo = false; + + /** + * should information histograms be rendered by default + */ + protected boolean hmmShowHistogram = true; + + /** * @return the showConsensusProfile */ @Override @@ -1009,6 +1075,15 @@ public abstract class AlignmentViewport } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return hmmShowSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1026,6 +1101,18 @@ public abstract class AlignmentViewport this.showSequenceLogo = showSequenceLogo; } + public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo) + { + if (showHMMSequenceLogo != this.hmmShowSequenceLogo) + { + this.hmmShowSequenceLogo = showHMMSequenceLogo; + // TODO: updateAnnotation if description (tooltip) will show + // profile in place of information content? + // calculator.updateAnnotationFor(InformationThread.class); + } + this.hmmShowSequenceLogo = showHMMSequenceLogo; + } + /** * @param showConsensusHistogram * the showConsensusHistogram to set @@ -1036,6 +1123,14 @@ public abstract class AlignmentViewport } /** + * @param showInformationHistogram + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.hmmShowHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1081,6 +1176,17 @@ public abstract class AlignmentViewport } /** + * + * @return flag to indicate if the information content histogram should be + * rendered by default + */ + @Override + public boolean isShowInformationHistogram() + { + return this.hmmShowHistogram; + } + + /** * when set, updateAlignment will always ensure sequences are of equal length */ private boolean padGaps = false; @@ -1236,7 +1342,16 @@ public abstract class AlignmentViewport ignoreGapsInConsensusCalculation); } } + } + public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) + { + ignoreBelowBackGroundFrequencyCalculation = b; + } + + public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap) + { + infoLetterHeight = b; } private long sgrouphash = -1, colselhash = -1; @@ -1293,6 +1408,18 @@ public abstract class AlignmentViewport return ignoreGapsInConsensusCalculation; } + @Override + public boolean isIgnoreBelowBackground() + { + return ignoreBelowBackGroundFrequencyCalculation; + } + + @Override + public boolean isInfoLetterHeight() + { + return infoLetterHeight; + } + // property change stuff // JBPNote Prolly only need this in the applet version. private PropertyChangeSupport changeSupport = new PropertyChangeSupport( @@ -1635,6 +1762,7 @@ public abstract class AlignmentViewport public void invertColumnSelection() { colSel.invertColumnSelection(0, alignment.getWidth(), alignment); + isColSelChanged(true); } @Override @@ -1740,8 +1868,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 { @@ -1771,7 +1903,7 @@ public abstract class AlignmentViewport start = hidden.visibleToAbsoluteColumn(start); } - end = hidden.getHiddenBoundaryRight(start); + end = hidden.getNextHiddenBoundary(false, start); if (start == end) { end = max; @@ -1787,11 +1919,11 @@ public abstract class AlignmentViewport if (hidden != null && hidden.hasHiddenColumns()) { start = hidden.visibleToAbsoluteColumn(end); - start = hidden.getHiddenBoundaryLeft(start) + 1; + start = hidden.getNextHiddenBoundary(true, start) + 1; } } while (end < max); - int[][] startEnd = new int[regions.size()][2]; + // int[][] startEnd = new int[regions.size()][2]; return regions; } @@ -1882,7 +2014,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -1935,6 +2066,7 @@ public abstract class AlignmentViewport MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); + initGapCounts(); initComplementConsensus(); @@ -2141,12 +2273,15 @@ public abstract class AlignmentViewport boolean showprf = isShowSequenceLogo(); boolean showConsHist = isShowConsensusHistogram(); boolean normLogo = isNormaliseSequenceLogo(); + boolean showHMMPrf = isShowHMMSequenceLogo(); + boolean showInfoHist = isShowInformationHistogram(); + boolean normHMMLogo = isNormaliseHMMSequenceLogo(); /** * TODO reorder the annotation rows according to group/sequence ordering on * alignment */ - boolean sortg = true; + // boolean sortg = true; // remove old automatic annotation // add any new annotation @@ -2178,6 +2313,9 @@ public abstract class AlignmentViewport sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); + sg.setShowHMMSequenceLogo(showHMMPrf); + sg.setShowInformationHistogram(showInfoHist); + sg.setNormaliseHMMSequenceLogo(normHMMLogo); } if (conv) { @@ -2256,7 +2394,7 @@ public abstract class AlignmentViewport public void clearSequenceColours() { sequenceColours.clear(); - }; + } @Override public AlignViewportI getCodingComplement() @@ -2709,6 +2847,30 @@ public abstract class AlignmentViewport viewStyle.setProteinFontAsCdna(b); } + @Override + public void setShowComplementFeatures(boolean b) + { + viewStyle.setShowComplementFeatures(b); + } + + @Override + public boolean isShowComplementFeatures() + { + return viewStyle.isShowComplementFeatures(); + } + + @Override + public void setShowComplementFeaturesOnTop(boolean b) + { + viewStyle.setShowComplementFeaturesOnTop(b); + } + + @Override + public boolean isShowComplementFeaturesOnTop() + { + return viewStyle.isShowComplementFeaturesOnTop(); + } + /** * @return true if view should scroll to show the highlighted region of a * sequence @@ -2781,7 +2943,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)) @@ -2938,6 +3100,19 @@ public abstract class AlignmentViewport return sq; } + public boolean hasReferenceAnnotation() + { + AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation(); + for (AlignmentAnnotation annot : annots) + { + if ("RF".equals(annot.label) || annot.label.contains("Reference")) + { + return true; + } + } + return false; + } + @Override public void setCurrentTree(TreeModel tree) { @@ -2949,4 +3124,161 @@ public abstract class AlignmentViewport { return currentTree; } + + @Override + public AlignmentExportData getAlignExportData(AlignExportSettingsI options) + { + AlignmentI alignmentToExport = null; + String[] omitHidden = null; + alignmentToExport = null; + + if (hasHiddenColumns() && !options.isExportHiddenColumns()) + { + omitHidden = getViewAsString(false, + options.isExportHiddenSequences()); + } + + int[] alignmentStartEnd = new int[2]; + if (hasHiddenRows() && options.isExportHiddenSequences()) + { + alignmentToExport = getAlignment().getHiddenSequences() + .getFullAlignment(); + } + else + { + alignmentToExport = getAlignment(); + } + alignmentStartEnd = getAlignment().getHiddenColumns() + .getVisibleStartAndEndIndex(alignmentToExport.getWidth()); + AlignmentExportData ed = new AlignmentExportData(alignmentToExport, + omitHidden, alignmentStartEnd); + return ed; + } + + @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); + } + } + + /** + * Filters out sequences with an eValue higher than the specified value. The + * filtered sequences are hidden or deleted. Sequences with no eValues are also + * filtered out. + * + * @param eValue + * @param delete + */ + public void filterByEvalue(double eValue) + { + for (SequenceI seq : alignment.getSequencesArray()) + { + if ((seq.getAnnotation("Search Scores") == null + || seq.getAnnotation("Search Scores")[0].getEValue() > eValue) + && seq.getHMM() == null) + { + hideSequence(new SequenceI[] { seq }); + } + } + } + + /** + * Filters out sequences with an score lower than the specified value. The + * filtered sequences are hidden or deleted. + * + * @param score + * @param delete + */ + public void filterByScore(double score) + { + for (SequenceI seq : alignment.getSequencesArray()) + { + if ((seq.getAnnotation("Search Scores") == null + || seq.getAnnotation("Search Scores")[0] + .getBitScore() < score) + && seq.getHMM() == null) + { + hideSequence(new SequenceI[] { seq }); + } + } + } }