X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=179bfa0a3a4658cb30feba6291f759965c084cb9;hb=cc4dc8e354640ad8b2c5b522f7a61a469546fa10;hp=23c1d003cdcb2a327b363b39496a7c56ddc19057;hpb=6c7cac79652fa6c7050311f73f36b9a9d05e6a6b;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 23c1d00..179bfa0 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -23,7 +23,9 @@ package jalview.viewmodel; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; -import jalview.api.AlignCalcManagerI; +import jalview.api.AlignCalcManagerI2; +import jalview.api.AlignCalcWorkerI; +import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeaturesDisplayedI; @@ -31,6 +33,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; @@ -54,11 +57,12 @@ 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; @@ -82,6 +86,9 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { + public static final String PROPERTY_ALIGNMENT = "alignment"; + public static final String PROPERTY_SEQUENCE = "sequence"; + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -625,10 +632,31 @@ public abstract class AlignmentViewport 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; + public boolean getAutoCalculateStrucConsensus() + { // BH 2019.07.24 + return autoCalculateStrucConsensus; + } + + public void setAutoCalculateStrucConsensus(boolean b) + { + autoCalculateStrucConsensus = b; + } + + protected boolean ignoreGapsInConsensusCalculation = false; protected ResidueShaderI residueShading = new ResidueShader(); @@ -731,13 +759,13 @@ 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; @@ -766,7 +794,8 @@ public abstract class AlignmentViewport } @Override - public void setComplementConsensusHash(Hashtable[] hconsensus) + public void setComplementConsensusHash( + Hashtable[] hconsensus) { this.hcomplementConsensus = hconsensus; } @@ -790,19 +819,20 @@ public abstract class AlignmentViewport } @Override - public Hashtable[] getComplementConsensusHash() + 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; @@ -844,7 +874,7 @@ public abstract class AlignmentViewport return strucConsensus; } - protected AlignCalcManagerI calculator = new AlignCalcManager(); + protected AlignCalcManagerI2 calculator = new AlignCalcManager2(); /** * trigger update of conservation annotation @@ -854,12 +884,12 @@ public abstract class AlignmentViewport // 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)); @@ -872,12 +902,11 @@ public abstract class AlignmentViewport public void updateConsensus(final AlignmentViewPanel ap) { // see note in mantis : issue number 8585 - if (consensus == 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)); } @@ -908,11 +937,9 @@ public abstract class AlignmentViewport } 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)); } } } @@ -921,8 +948,7 @@ public abstract class AlignmentViewport @Override public void initInformationWorker(final AlignmentViewPanel ap) { - if (calculator - .getRegisteredWorkersOfClass(InformationThread.class) == null) + if (calculator.getWorkersOfClass(InformationThread.class).isEmpty()) { calculator.registerWorker(new InformationThread(this, ap)); } @@ -943,8 +969,7 @@ public abstract class AlignmentViewport { return; } - if (calculator.getRegisteredWorkersOfClass( - StrucConsensusThread.class) == null) + if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty()) { calculator.registerWorker(new StrucConsensusThread(this, ap)); } @@ -963,7 +988,7 @@ public abstract class AlignmentViewport { return false; } - if (calculator.workingInvolvedWith(alignmentAnnotation)) + if (calculator.isWorkingWithAnnotation(alignmentAnnotation)) { // System.err.println("grey out ("+alignmentAnnotation.label+")"); return true; @@ -971,6 +996,13 @@ public abstract class AlignmentViewport return false; } + private WebServiceExecutor wsExecutor = new WebServiceExecutor(); + + public WebServiceExecutor getWSExecutor() + { + return wsExecutor; + } + public void setAlignment(AlignmentI align) { this.alignment = align; @@ -998,7 +1030,10 @@ public abstract class AlignmentViewport hconservation = null; hcomplementConsensus = null; gapcounts = null; + calculator.shutdown(); calculator = null; + wsExecutor.shutdown(); + wsExecutor = null; residueShading = null; // may hold a reference to Consensus changeSupport = null; ranges = null; @@ -1016,7 +1051,7 @@ public abstract class AlignmentViewport } @Override - public AlignCalcManagerI getCalcManager() + public AlignCalcManagerI2 getCalcManager() { return calculator; } @@ -1090,9 +1125,15 @@ public abstract class AlignmentViewport // 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; } @@ -1380,21 +1421,22 @@ public abstract class AlignmentViewport * 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; } @@ -1467,22 +1509,6 @@ public abstract class AlignmentViewport } } - /** - * 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() @@ -1547,13 +1573,14 @@ public abstract class AlignmentViewport ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event + notifySequence(); sendSelection(); } } + public void showSequence(int index) { int startSeq = ranges.getStartSeq(); @@ -1576,8 +1603,7 @@ public abstract class AlignmentViewport } ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); sendSelection(); } } @@ -1611,7 +1637,7 @@ public abstract class AlignmentViewport setSequenceAnnotationsVisible(seq[i], false); } ranges.setStartSeq(startSeq); - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); } } @@ -1919,7 +1945,7 @@ public abstract class AlignmentViewport } } while (end < max); - int[][] startEnd = new int[regions.size()][2]; + // int[][] startEnd = new int[regions.size()][2]; return regions; } @@ -1976,11 +2002,11 @@ public abstract class AlignmentViewport { alignment.padGaps(); } - if (autoCalculateConsensus) + if (autoCalculateConsensusAndConservation) { updateConsensus(ap); } - if (hconsensus != null && autoCalculateConsensus) + if (hconsensus != null && autoCalculateConsensusAndConservation) { updateConservation(ap); } @@ -2277,7 +2303,7 @@ public abstract class AlignmentViewport * 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 @@ -2390,7 +2416,7 @@ public abstract class AlignmentViewport public void clearSequenceColours() { sequenceColours.clear(); - }; + } @Override public AlignViewportI getCodingComplement() @@ -2843,6 +2869,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 @@ -3098,6 +3148,36 @@ public abstract class AlignmentViewport } @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; @@ -3118,7 +3198,6 @@ public abstract class AlignmentViewport { hmmNormaliseSequenceLogo = state; } - /** * flag set to indicate if structure views might be out of sync with sequences * in the alignment @@ -3182,4 +3261,61 @@ public abstract class AlignmentViewport 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); + } }