X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=179bfa0a3a4658cb30feba6291f759965c084cb9;hb=cc4dc8e354640ad8b2c5b522f7a61a469546fa10;hp=eefad4a2b6ff5a990bbdf457ec829ae80c27b236;hpb=536a4a9c407a4c07b71e86e75135eaa2ba5e8850;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index eefad4a..179bfa0 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -22,7 +22,10 @@ package jalview.viewmodel; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; -import jalview.api.AlignCalcManagerI; +import jalview.analysis.TreeModel; +import jalview.api.AlignCalcManagerI2; +import jalview.api.AlignCalcWorkerI; +import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeaturesDisplayedI; @@ -30,10 +33,10 @@ 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; -import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; @@ -52,11 +55,14 @@ import jalview.structure.VamsasSource; 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.AlignCalcManager2; import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; +import jalview.workers.InformationThread; import jalview.workers.StrucConsensusThread; +import jalview.ws2.WebServiceExecutor; import java.awt.Color; import java.beans.PropertyChangeSupport; @@ -66,6 +72,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; @@ -76,10 +83,13 @@ import java.util.Map; * @author jimp * */ -public abstract class AlignmentViewport implements AlignViewportI, - CommandListener, VamsasSource +public abstract class AlignmentViewport + implements AlignViewportI, CommandListener, VamsasSource { - final protected ViewportRanges ranges; + public static final String PROPERTY_ALIGNMENT = "alignment"; + public static final String PROPERTY_SEQUENCE = "sequence"; + + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -91,14 +101,35 @@ public abstract class AlignmentViewport implements AlignViewportI, FeaturesDisplayedI featuresDisplayed = null; - protected Deque historyList = new ArrayDeque(); + protected Deque historyList = new ArrayDeque<>(); - protected Deque redoList = new ArrayDeque(); + protected Deque redoList = new ArrayDeque<>(); /** * 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) { @@ -404,6 +435,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** @@ -566,8 +598,6 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle.setSeqNameItalics(default1); } - - @Override public AlignmentI getAlignment() { @@ -587,7 +617,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * alignment */ protected boolean isDataset = false; - + public void setDataset(boolean b) { isDataset = b; @@ -602,14 +632,35 @@ public abstract class AlignmentViewport implements AlignViewportI, protected ColumnSelection colSel = new ColumnSelection(); - public boolean autoCalculateConsensus = true; + protected boolean autoCalculateConsensusAndConservation = true; + + public boolean getAutoCalculateConsensusAndConservation() + { // BH 2019.07.24 + return autoCalculateConsensusAndConservation; + } + + public void setAutoCalculateConsensusAndConservation(boolean b) + { + autoCalculateConsensusAndConservation = b; + } protected boolean autoCalculateStrucConsensus = true; - protected boolean ignoreGapsInConsensusCalculation = false; + public boolean getAutoCalculateStrucConsensus() + { // BH 2019.07.24 + return autoCalculateStrucConsensus; + } + + public void setAutoCalculateStrucConsensus(boolean b) + { + autoCalculateStrucConsensus = b; + } + - protected ResidueShaderI residueShading; + protected boolean ignoreGapsInConsensusCalculation = false; + protected ResidueShaderI residueShading = new ResidueShader(); + @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -641,6 +692,11 @@ public abstract class AlignmentViewport implements AlignViewportI, { residueShading.setConservation(hconservation); } + /* + * reset conservation flag in case just set to false if + * Conservation was null (calculation still in progress) + */ + residueShading.setConservationApplied(getConservationSelected()); residueShading.alignmentChanged(alignment, hiddenRepSequences); } @@ -656,11 +712,12 @@ public abstract class AlignmentViewport implements AlignViewportI, * 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, hiddenRepSequences); + sg.getGroupColourScheme().alignmentChanged(sg, + hiddenRepSequences); } } } @@ -669,8 +726,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public ColourSchemeI getGlobalColourScheme() { - return residueShading == null ? null : residueShading - .getColourScheme(); + return residueShading == null ? null : residueShading.getColourScheme(); } @Override @@ -678,7 +734,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { return residueShading; } - + protected AlignmentAnnotation consensus; protected AlignmentAnnotation complementConsensus; @@ -703,16 +759,16 @@ public abstract class AlignmentViewport implements AlignViewportI, /** * 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) { @@ -738,7 +794,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public void setComplementConsensusHash(Hashtable[] hconsensus) + public void setComplementConsensusHash( + Hashtable[] hconsensus) { this.hcomplementConsensus = hconsensus; } @@ -750,19 +807,32 @@ public abstract class AlignmentViewport implements AlignViewportI, } @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; @@ -804,7 +874,7 @@ public abstract class AlignmentViewport implements AlignViewportI, return strucConsensus; } - protected AlignCalcManagerI calculator = new AlignCalcManager(); + protected AlignCalcManagerI2 calculator = new AlignCalcManager2(); /** * trigger update of conservation annotation @@ -814,15 +884,15 @@ public abstract class AlignmentViewport implements AlignViewportI, // see note in mantis : issue number 8585 if (alignment.isNucleotide() || (conservation == null && quality == null) - || !autoCalculateConsensus) + || !autoCalculateConsensusAndConservation) { return; } - if (calculator - .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null) + if (calculator.getWorkersOfClass( + jalview.workers.ConservationThread.class).isEmpty()) { - calculator.registerWorker(new jalview.workers.ConservationThread( - this, ap)); + calculator.registerWorker( + new jalview.workers.ConservationThread(this, ap)); } } @@ -832,11 +902,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public void updateConsensus(final AlignmentViewPanel ap) { // see note in mantis : issue number 8585 - if ((consensus == null || gapcounts == null) || !autoCalculateConsensus) + if (consensus == null || !autoCalculateConsensusAndConservation) { return; } - if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null) + if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty()) { calculator.registerWorker(new ConsensusThread(this, ap)); } @@ -867,16 +937,23 @@ public abstract class AlignmentViewport implements AlignViewportI, } if (doConsensus) { - if (calculator - .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null) + if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty()) { - calculator - .registerWorker(new ComplementConsensusThread(this, ap)); + calculator.registerWorker(new ComplementConsensusThread(this, ap)); } } } } + @Override + public void initInformationWorker(final AlignmentViewPanel ap) + { + if (calculator.getWorkersOfClass(InformationThread.class).isEmpty()) + { + calculator.registerWorker(new InformationThread(this, ap)); + } + } + // --------START Structure Conservation public void updateStrucConsensus(final AlignmentViewPanel ap) { @@ -892,7 +969,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { return; } - if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null) + if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty()) { calculator.registerWorker(new StrucConsensusThread(this, ap)); } @@ -911,7 +988,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { return false; } - if (calculator.workingInvolvedWith(alignmentAnnotation)) + if (calculator.isWorkingWithAnnotation(alignmentAnnotation)) { // System.err.println("grey out ("+alignmentAnnotation.label+")"); return true; @@ -919,6 +996,13 @@ public abstract class AlignmentViewport implements AlignViewportI, return false; } + private WebServiceExecutor wsExecutor = new WebServiceExecutor(); + + public WebServiceExecutor getWSExecutor() + { + return wsExecutor; + } + public void setAlignment(AlignmentI align) { this.alignment = align; @@ -939,14 +1023,22 @@ public abstract class AlignmentViewport implements AlignViewportI, strucConsensus = null; conservation = null; quality = null; + consensusProfiles = null; groupConsensus = null; groupConservation = null; hconsensus = null; + hconservation = null; hcomplementConsensus = null; - // colour scheme may hold reference to consensus - residueShading = null; - // TODO remove listeners from changeSupport? + gapcounts = null; + calculator.shutdown(); + calculator = null; + wsExecutor.shutdown(); + wsExecutor = null; + residueShading = null; // may hold a reference to Consensus changeSupport = null; + ranges = null; + currentTree = null; + selectionGroup = null; setAlignment(null); } @@ -959,7 +1051,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public AlignCalcManagerI getCalcManager() + public AlignCalcManagerI2 getCalcManager() { return calculator; } @@ -990,6 +1082,21 @@ public abstract class AlignmentViewport implements AlignViewportI, 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 @@ -999,6 +1106,15 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return hmmShowSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1009,13 +1125,31 @@ public abstract class AlignmentViewport implements AlignViewportI, // 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); + for (AlignCalcWorkerI worker : calculator.getWorkers()) + { + if (worker.getClass().equals(ConsensusThread.class) || + worker.getClass().equals(ComplementConsensusThread.class) || + worker.getClass().equals(StrucConsensusThread.class)) + { + worker.updateAnnotation(); + } + } } 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 @@ -1026,6 +1160,14 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @param showInformationHistogram + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.hmmShowHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1071,6 +1213,17 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * + * @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; @@ -1112,7 +1265,6 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setHiddenColumns(HiddenColumns hidden) { this.alignment.setHiddenColumns(hidden); - // this.colSel = colsel; } @Override @@ -1159,7 +1311,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public boolean hasHiddenColumns() { - return colSel != null + return alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(); } @@ -1182,8 +1334,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (sequenceSetID != null) { - System.err - .println("Warning - overwriting a sequenceSetId for a viewport!"); + System.err.println( + "Warning - overwriting a sequenceSetId for a viewport!"); } sequenceSetID = new String(newid); } @@ -1227,7 +1379,16 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; @@ -1260,21 +1421,22 @@ public abstract class AlignmentViewport implements AlignViewportI, * checks current colsel against record of last hash value, and optionally * updates record. * - * @param b + * @param updateHash * update the record of last hash value * @return true if colsel changed since last call (when b is true) */ - public boolean isColSelChanged(boolean b) + public boolean isColSelChanged(boolean updateHash) { int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { - if (b) + if (updateHash) { colselhash = hc; } return true; } + notifySequence(); return false; } @@ -1284,6 +1446,18 @@ public abstract class AlignmentViewport implements AlignViewportI, 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( @@ -1295,7 +1469,9 @@ public abstract class AlignmentViewport implements AlignViewportI, protected boolean showConsensus = true; - private Map sequenceColours = new HashMap(); + protected boolean showOccupancy = true; + + private Map sequenceColours = new HashMap<>(); protected SequenceAnnotationOrder sortAnnotationsBy = null; @@ -1327,23 +1503,10 @@ public abstract class AlignmentViewport implements AlignViewportI, 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); + if (changeSupport != null) + { + changeSupport.removePropertyChangeListener(listener); + } } // common hide/show column stuff @@ -1388,6 +1551,9 @@ public abstract class AlignmentViewport implements AlignViewportI, // common hide/show seq stuff public void showAllHiddenSeqs() { + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + if (alignment.getHiddenSequences().getSize() > 0) { if (selectionGroup == null) @@ -1395,8 +1561,8 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup = new SequenceGroup(); selectionGroup.setEndRes(alignment.getWidth() - 1); } - List tmp = alignment.getHiddenSequences().showAll( - hiddenRepSequences); + List tmp = alignment.getHiddenSequences() + .showAll(hiddenRepSequences); for (SequenceI seq : tmp) { selectionGroup.addSequence(seq, false); @@ -1405,17 +1571,23 @@ public abstract class AlignmentViewport implements AlignViewportI, hiddenRepSequences = null; - firePropertyChange("alignment", null, alignment.getSequences()); + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event + notifySequence(); sendSelection(); } } + public void showSequence(int index) { - List tmp = alignment.getHiddenSequences().showSequence( - index, hiddenRepSequences); + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + + List tmp = alignment.getHiddenSequences().showSequence(index, + hiddenRepSequences); if (tmp.size() > 0) { if (selectionGroup == null) @@ -1429,7 +1601,9 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup.addSequence(seq, false); setSequenceAnnotationsVisible(seq, true); } - firePropertyChange("alignment", null, alignment.getSequences()); + + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + notifyAlignment(); sendSelection(); } } @@ -1450,6 +1624,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public void hideSequence(SequenceI[] seq) { + /* + * cache offset to first visible sequence + */ + int startSeq = ranges.getStartSeq(); + if (seq != null) { for (int i = 0; i < seq.length; i++) @@ -1457,7 +1636,8 @@ public abstract class AlignmentViewport implements AlignViewportI, alignment.getHiddenSequences().hideSequence(seq[i]); setSequenceAnnotationsVisible(seq[i], false); } - firePropertyChange("alignment", null, alignment.getSequences()); + ranges.setStartSeq(startSeq); + notifyAlignment(); } } @@ -1486,8 +1666,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } int gsize = selectionGroup.getSize(); - SequenceI[] hseqs = selectionGroup.getSequences().toArray( - new SequenceI[gsize]); + SequenceI[] hseqs = selectionGroup.getSequences() + .toArray(new SequenceI[gsize]); hideSequence(hseqs); setSelectionGroup(null); @@ -1525,7 +1705,7 @@ public abstract class AlignmentViewport implements AlignViewportI, if (hiddenRepSequences == null) { - hiddenRepSequences = new Hashtable(); + hiddenRepSequences = new Hashtable<>(); } hiddenRepSequences.put(repSequence, sg); @@ -1577,8 +1757,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isHiddenRepSequence(SequenceI seq) { - return (hiddenRepSequences != null && hiddenRepSequences - .containsKey(seq)); + return (hiddenRepSequences != null + && hiddenRepSequences.containsKey(seq)); } /** @@ -1596,14 +1776,15 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public int adjustForHiddenSeqs(int alignmentIndex) { - return alignment.getHiddenSequences().adjustForHiddenSeqs( - alignmentIndex); + return alignment.getHiddenSequences() + .adjustForHiddenSeqs(alignmentIndex); } @Override public void invertColumnSelection() { colSel.invertColumnSelection(0, alignment.getWidth(), alignment); + isColSelChanged(true); } @Override @@ -1649,13 +1830,6 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public CigarArray getViewAsCigars(boolean selectedRegionOnly) - { - return new CigarArray(alignment, alignment.getHiddenColumns(), - (selectedRegionOnly ? selectionGroup : null)); - } - - @Override public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly) { @@ -1667,10 +1841,10 @@ public abstract class AlignmentViewport implements AlignViewportI, boolean selectedOnly, boolean markGroups) { return new AlignmentView(alignment, alignment.getHiddenColumns(), - selectionGroup, alignment.getHiddenColumns() != null + selectionGroup, + alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(), - selectedOnly, - markGroups); + selectedOnly, markGroups); } @Override @@ -1716,8 +1890,12 @@ public abstract class AlignmentViewport implements AlignViewportI, 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 { @@ -1733,7 +1911,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public List getVisibleRegionBoundaries(int min, int max) { - ArrayList regions = new ArrayList(); + ArrayList regions = new ArrayList<>(); int start = min; int end = max; @@ -1744,10 +1922,10 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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; @@ -1762,12 +1940,12 @@ public abstract class AlignmentViewport implements AlignViewportI, 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); - int[][] startEnd = new int[regions.size()][2]; + // int[][] startEnd = new int[regions.size()][2]; return regions; } @@ -1776,7 +1954,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public List getVisibleAlignmentAnnotation( boolean selectedOnly) { - ArrayList ala = new ArrayList(); + ArrayList ala = new ArrayList<>(); AlignmentAnnotation[] aa; if ((aa = alignment.getAlignmentAnnotation()) != null) { @@ -1785,13 +1963,13 @@ public abstract class AlignmentViewport implements AlignViewportI, AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - alignment.getHiddenColumns().makeVisibleAnnotation( - selectionGroup.getStartRes(), - selectionGroup.getEndRes(), clone); + clone.makeVisibleAnnotation( + selectionGroup.getStartRes(), selectionGroup.getEndRes(), + alignment.getHiddenColumns()); } else { - alignment.getHiddenColumns().makeVisibleAnnotation(clone); + clone.makeVisibleAnnotation(alignment.getHiddenColumns()); } ala.add(clone); } @@ -1824,11 +2002,11 @@ public abstract class AlignmentViewport implements AlignViewportI, { alignment.padGaps(); } - if (autoCalculateConsensus) + if (autoCalculateConsensusAndConservation) { updateConsensus(ap); } - if (hconsensus != null && autoCalculateConsensus) + if (hconsensus != null && autoCalculateConsensusAndConservation) { updateConservation(ap); } @@ -1858,7 +2036,6 @@ public abstract class AlignmentViewport implements AlignViewportI, updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -1907,14 +2084,12 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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); - gapcounts = new AlignmentAnnotation("Occupancy", - "Number of aligned positions", - new Annotation[1], 0f, alignment.getHeight(), - AlignmentAnnotation.BAR_GRAPH); - initGapCounts(gapcounts); + + initGapCounts(); initComplementConsensus(); } @@ -1948,7 +2123,9 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; @@ -1971,15 +2148,20 @@ public abstract class AlignmentViewport implements AlignViewportI, // these should be extracted from the view model - style and settings for // derived annotation - private void initGapCounts(AlignmentAnnotation counts) + private void initGapCounts() { - counts.hasText = false; - counts.autoCalculated = true; - counts.graph = AlignmentAnnotation.BAR_GRAPH; - - if (showConsensus) + if (showOccupancy) { - alignment.addAnnotation(counts); + 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); } } @@ -1990,9 +2172,9 @@ public abstract class AlignmentViewport implements AlignViewportI, if (conservation == null) { conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " - + getConsPercGaps() + "% gaps", new Annotation[1], - 0f, 11f, AlignmentAnnotation.BAR_GRAPH); + MessageManager.formatMessage("label.conservation_descr", + getConsPercGaps()), + new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); conservation.hasText = true; conservation.autoCalculated = true; alignment.addAnnotation(conservation); @@ -2007,7 +2189,7 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; @@ -2020,7 +2202,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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; @@ -2112,12 +2295,15 @@ public abstract class AlignmentViewport implements AlignViewportI, 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 @@ -2125,7 +2311,7 @@ public abstract class AlignmentViewport implements AlignViewportI, // intersect alignment annotation with alignment groups AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation(); - List oldrfs = new ArrayList(); + List oldrfs = new ArrayList<>(); if (aan != null) { for (int an = 0; an < aan.length; an++) @@ -2149,6 +2335,9 @@ public abstract class AlignmentViewport implements AlignViewportI, sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); + sg.setShowHMMSequenceLogo(showHMMPrf); + sg.setShowInformationHistogram(showInfoHist); + sg.setNormaliseHMMSequenceLogo(normHMMLogo); } if (conv) { @@ -2227,7 +2416,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void clearSequenceColours() { sequenceColours.clear(); - }; + } @Override public AlignViewportI getCodingComplement() @@ -2471,8 +2660,8 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle = new ViewStyle(settingsForView); if (residueShading != null) { - residueShading.setConservationApplied(settingsForView - .isConservationColourSelected()); + residueShading.setConservationApplied( + settingsForView.isConservationColourSelected()); } } @@ -2640,7 +2829,8 @@ public abstract class AlignmentViewport implements AlignViewportI, return sortAnnotationsBy; } - public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy) + public void setSortAnnotationsBy( + SequenceAnnotationOrder sortAnnotationsBy) { this.sortAnnotationsBy = sortAnnotationsBy; } @@ -2667,6 +2857,42 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle.setScaleProteinAsCdna(b); } + @Override + public boolean isProteinFontAsCdna() + { + return viewStyle.isProteinFontAsCdna(); + } + + @Override + public void setProteinFontAsCdna(boolean b) + { + 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 @@ -2706,8 +2932,8 @@ public abstract class AlignmentViewport implements AlignViewportI, return 0; } boolean iAmProtein = !getAlignment().isNucleotide(); - AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement - .getAlignment(); + AlignmentI proteinAlignment = iAmProtein ? getAlignment() + : complement.getAlignment(); if (proteinAlignment == null) { return 0; @@ -2738,7 +2964,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ int lastSeq = alignment.getHeight() - 1; List seqMappings = null; - for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + for (int seqNo = ranges + .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) @@ -2749,9 +2976,9 @@ public abstract class AlignmentViewport implements AlignViewportI, { continue; } - seqMappings = MappingUtils - .findMappingsForSequenceAndOthers(sequence, mappings, - getCodingComplement().getAlignment().getSequences()); + seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence, + mappings, + getCodingComplement().getAlignment().getSequences()); if (!seqMappings.isEmpty()) { break; @@ -2826,8 +3053,7 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionIsDefinedGroup = gps.contains(selectionGroup); } } - return selectionGroup.getContext() == alignment - || selectionIsDefinedGroup; + return selectionGroup.isDefined() || selectionIsDefinedGroup; } /** @@ -2835,6 +3061,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private SearchResultsI searchResults = null; + protected TreeModel currentTree = null; + @Override public boolean hasSearchResults() { @@ -2852,4 +3080,242 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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; + } + + 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) + { + currentTree = tree; + } + + @Override + public TreeModel getCurrentTree() + { + 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 }); + } + } + } + + /** + * Notify TreePanel and AlignmentPanel of some sort of alignment change. + */ + public void notifyAlignment() + { + changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences()); + } + + /** + * Notify AlignmentPanel of a sequence column selection or visibility changes. + */ + public void notifySequence() + { + changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null); + } }