X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=c05406e69e2320a0e07ca8b612bc94231873f82f;hb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;hp=358d00d26f4997b76d611de53cdfb8fa04f7b21c;hpb=9009e5f176d57ba6bc5b1c2a11e9d9330576e03e;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java old mode 100755 new mode 100644 index 358d00d..c05406e --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,6 +1,24 @@ - /* +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +/* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,1616 +36,1279 @@ */ package jalview.gui; -import jalview.analysis.*; - -import jalview.bin.*; - -import jalview.datamodel.*; - -import jalview.schemes.*; - -import java.awt.*; - -import java.util.*; - +import jalview.analysis.NJTree; +import jalview.api.AlignViewportI; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Annotation; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.UserColourScheme; +import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; +import jalview.viewmodel.AlignmentViewport; +import jalview.ws.params.AutoCalcSetting; + +import java.awt.Color; +import java.awt.Container; +import java.awt.Font; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Stack; +import java.util.Vector; /** * DOCUMENT ME! - * + * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.141 $ */ -public class AlignViewport +public class AlignViewport extends AlignmentViewport implements + SelectionSource, VamsasSource, AlignViewportI { - int startRes; - int endRes; - int startSeq; - int endSeq; - boolean showJVSuffix = true; - boolean showText = true; - boolean showColourText = false; - boolean showBoxes = true; - boolean wrapAlignment = false; - boolean renderGaps = true; - boolean showSequenceFeatures = false; - boolean showAnnotation = true; - boolean colourAppliesToAllGroups = true; - ColourSchemeI globalColourScheme = null; - boolean conservationColourSelected = false; - boolean abovePIDThreshold = false; - SequenceGroup selectionGroup; - int charHeight; - int charWidth; - boolean validCharWidth; - int wrappedWidth; - Font font; - AlignmentI alignment; - ColumnSelection colSel = new ColumnSelection(); - int threshold; - int increment; - NJTree currentTree = null; - boolean scaleAboveWrapped = false; - boolean scaleLeftWrapped = true; - boolean scaleRightWrapped = true; - boolean hasHiddenColumns = false; - boolean hasHiddenRows = false; - boolean showHiddenMarkers = true; - - boolean cursorMode = false; - - // The following vector holds the features which are - // currently visible, in the correct order or rendering - Hashtable featuresDisplayed = null; - - - /** DOCUMENT ME!! */ - public Hashtable [] hconsensus; - AlignmentAnnotation consensus; - AlignmentAnnotation conservation; - AlignmentAnnotation quality; - boolean autoCalculateConsensus = true; - - /** DOCUMENT ME!! */ - public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! - - // JBPNote Prolly only need this in the applet version. - private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this); - - boolean ignoreGapsInConsensusCalculation = false; - - boolean isDataset = false; - - boolean antiAlias = false; - - boolean padGaps = false; - - Rectangle explodedPosition; - - String viewName; - - String sequenceSetID; - - boolean gatherViewsHere = false; - - Stack historyList = new Stack(); - Stack redoList = new Stack(); - - Hashtable sequenceColours; - - int thresholdTextColour = 0; - Color textColour = Color.black; - Color textColour2 = Color.white; - - boolean rightAlignIds = false; - - - /** - * Creates a new AlignViewport object. - * - * @param al DOCUMENT ME! - */ - public AlignViewport(AlignmentI al) - { - setAlignment(al); - init(); - } - /** - * Create a new AlignViewport with hidden regions - * @param al AlignmentI - * @param hiddenColumns ColumnSelection - */ - public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) { - setAlignment(al); - if (hiddenColumns!=null) { - this.colSel = hiddenColumns; - if (hiddenColumns.getHiddenColumns() != null) - hasHiddenColumns = true; - } - init(); - } - - void init() - { - this.startRes = 0; - this.endRes = alignment.getWidth() - 1; - this.startSeq = 0; - this.endSeq = alignment.getHeight() - 1; + int startRes; - antiAlias = Cache.getDefault("ANTI_ALIAS", false); + int endRes; - showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true); - showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + int startSeq; - rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false); + int endSeq; - autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true); + boolean showJVSuffix = true; - padGaps = Cache.getDefault("PAD_GAPS", true); + boolean showText = true; - String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); - String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ; - String fontSize = Cache.getDefault("FONT_SIZE", "10"); + boolean showColourText = false; - int style = 0; + boolean showBoxes = true; - if (fontStyle.equals("bold")) - { - style = 1; - } - else if (fontStyle.equals("italic")) - { - style = 2; - } + boolean wrapAlignment = false; - setFont(new Font(fontName, style, Integer.parseInt(fontSize))); + boolean renderGaps = true; - alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) ); + boolean showSequenceFeatures = false; + boolean showAnnotation = true; - // We must set conservation and consensus before setting colour, - // as Blosum and Clustal require this to be done - if(hconsensus==null && !isDataset) - { - if(!alignment.isNucleotide()) - { - conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " + - ConsPercGaps + "% gaps", - new Annotation[1], 0f, - 11f, - AlignmentAnnotation.BAR_GRAPH); - conservation.hasText = true; - - - if (Cache.getDefault("SHOW_CONSERVATION", true)) - { - alignment.addAnnotation(conservation); - } - - if (Cache.getDefault("SHOW_QUALITY", true)) - { - quality = new AlignmentAnnotation("Quality", - "Alignment Quality based on Blosum62 scores", - new Annotation[1], - 0f, - 11f, - AlignmentAnnotation.BAR_GRAPH); - quality.hasText = true; - - alignment.addAnnotation(quality); - } - } - - consensus = new AlignmentAnnotation("Consensus", "PID", - new Annotation[1], 0f, 100f, - AlignmentAnnotation.BAR_GRAPH); - consensus.hasText = true; - - if (Cache.getDefault("SHOW_IDENTITY", true)) - { - alignment.addAnnotation(consensus); - } - } - - if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) - { - globalColourScheme = ColourSchemeProperty.getColour(alignment, - jalview.bin.Cache.getProperty("DEFAULT_COLOUR")); - - if (globalColourScheme instanceof UserColourScheme) - { - globalColourScheme = UserDefinedColours.loadDefaultColours(); - ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus()); - } - - if (globalColourScheme != null) - { - globalColourScheme.setConsensus(hconsensus); - } - } + int charHeight; - wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false); - } + int charWidth; + boolean validCharWidth; + int wrappedWidth; - /** - * DOCUMENT ME! - * - * @param b DOCUMENT ME! - */ - public void setShowSequenceFeatures(boolean b) - { - showSequenceFeatures = b; - } + Font font; - public boolean getShowSequenceFeatures() - { - return showSequenceFeatures; - } + boolean seqNameItalics; + NJTree currentTree = null; + boolean scaleAboveWrapped = false; - class ConservationThread extends Thread - { - AlignmentPanel ap; - public ConservationThread(AlignmentPanel ap) - { - this.ap = ap; - } + boolean scaleLeftWrapped = true; - public void run() - { - try - { - updatingConservation = true; + boolean scaleRightWrapped = true; - while (UPDATING_CONSERVATION) - { - try - { - if (ap != null) - { - ap.repaint(); - } - Thread.sleep(200); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } + boolean showHiddenMarkers = true; - UPDATING_CONSERVATION = true; + boolean cursorMode = false; + /** + * Keys are the feature types which are currently visible. Note: Values are + * not used! + */ + Hashtable featuresDisplayed = null; - int alWidth = alignment.getWidth(); - if(alWidth<0) - return; + boolean antiAlias = false; - Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alWidth -1); + Rectangle explodedPosition; - cons.calculate(); - cons.verdict(false, ConsPercGaps); + String viewName; - if (quality!=null) - { - cons.findQuality(); - } + boolean gatherViewsHere = false; - String sequence = cons.getConsSequence().getSequence(); - float minR; - float minG; - float minB; - float maxR; - float maxG; - float maxB; - minR = 0.3f; - minG = 0.0f; - minB = 0f; - maxR = 1.0f - minR; - maxG = 0.9f - minG; - maxB = 0f - minB; // scalable range for colouring both Conservation and Quality - - float min = 0f; - float max = 11f; - float qmin = 0f; - float qmax = 0f; - - char c; - - conservation.annotations = new Annotation[alWidth]; - - if (quality!=null) - { - quality.graphMax = cons.qualityRange[1].floatValue(); - quality.annotations = new Annotation[alWidth]; - qmin = cons.qualityRange[0].floatValue(); - qmax = cons.qualityRange[1].floatValue(); - } + Stack historyList = new Stack(); - for (int i = 0; i < alWidth; i++) - { - float value = 0; - - c = sequence.charAt(i); - - if (Character.isDigit(c)) - value = (int) (c - '0'); - else if (c == '*') - value = 11; - else if (c == '+') - value = 10; - - float vprop = value - min; - vprop /= max; - conservation.annotations[i] = - new Annotation(String.valueOf(c), - String.valueOf(value), ' ', value, - new Color(minR + (maxR * vprop), - minG + (maxG * vprop), - minB + (maxB * vprop))); - - // Quality calc - if (quality!=null) - { - value = ( (Double) cons.quality.get(i)).floatValue(); - vprop = value - qmin; - vprop /= qmax; - quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ', - value, - new Color(minR + (maxR * vprop), - minG + (maxG * vprop), - minB + (maxB * vprop))); - } - } - } - catch (OutOfMemoryError error) - { - javax.swing.SwingUtilities.invokeLater(new Runnable() - { + Stack redoList = new Stack(); + Hashtable sequenceColours; - public void run() - { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory calculating conservation!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - javax.swing.JOptionPane.WARNING_MESSAGE); - } - }); + int thresholdTextColour = 0; - conservation = null; - quality = null; + Color textColour = Color.black; - System.out.println("Conservation calculation: " + error); - System.gc(); + Color textColour2 = Color.white; - } + boolean rightAlignIds = false; - UPDATING_CONSERVATION = false; - updatingConservation = false; + /** + * Creates a new AlignViewport object. + * + * @param al + * alignment to view + */ + public AlignViewport(AlignmentI al) + { + setAlignment(al); + init(); + } - if(ap!=null) - { - ap.repaint(); - } + /** + * Create a new AlignViewport object with a specific sequence set ID + * + * @param al + * @param seqsetid + * (may be null - but potential for ambiguous constructor exception) + */ + public AlignViewport(AlignmentI al, String seqsetid) + { + this(al, seqsetid, null); + } - } - } - - - ConservationThread conservationThread; - - ConsensusThread consensusThread; - - boolean consUpdateNeeded = false; - - static boolean UPDATING_CONSENSUS = false; - - static boolean UPDATING_CONSERVATION = false; - - boolean updatingConsensus = false; - - boolean updatingConservation = false; - - /** - * DOCUMENT ME! - */ - public void updateConservation(final AlignmentPanel ap) + public AlignViewport(AlignmentI al, String seqsetid, String viewid) + { + sequenceSetID = seqsetid; + viewId = viewid; + // TODO remove these once 2.4.VAMSAS release finished + if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null) { - if (alignment.isNucleotide() || conservation==null) - return; - - conservationThread = new ConservationThread(ap); - conservationThread.start(); + Cache.log.debug("Setting viewport's sequence set id : " + + sequenceSetID); } - - /** - * DOCUMENT ME! - */ - public void updateConsensus(final AlignmentPanel ap) + if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null) { - consensusThread = new ConsensusThread(ap); - consensusThread.start(); + Cache.log.debug("Setting viewport's view id : " + viewId); } + setAlignment(al); + init(); + } - - class ConsensusThread extends Thread + /** + * Create a new AlignViewport with hidden regions + * + * @param al + * AlignmentI + * @param hiddenColumns + * ColumnSelection + */ + public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) + { + setAlignment(al); + if (hiddenColumns != null) { - AlignmentPanel ap; - public ConsensusThread(AlignmentPanel ap) + this.colSel = hiddenColumns; + if (hiddenColumns.getHiddenColumns() != null + && hiddenColumns.getHiddenColumns().size() > 0) { - this.ap = ap; + hasHiddenColumns = true; } - public void run() + else { - updatingConsensus = true; - while (UPDATING_CONSENSUS) - { - try - { - if (ap != null) - { - ap.repaint(); - } - - Thread.sleep(200); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - - UPDATING_CONSENSUS = true; - - try - { - int aWidth = alignment.getWidth(); - if(aWidth<0) - return; - - consensus.annotations = null; - consensus.annotations = new Annotation[aWidth]; - - - hconsensus = new Hashtable[aWidth]; - AAFrequency.calculate(alignment.getSequencesArray(), - 0, - alignment.getWidth(), - hconsensus); - - for (int i = 0; i < aWidth; i++) - { - float value = 0; - if (ignoreGapsInConsensusCalculation) - value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)). - floatValue(); - else - value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)). - floatValue(); - - String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString(); - String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " "; - - if (maxRes.length() > 1) - { - mouseOver = "[" + maxRes + "] "; - maxRes = "+"; - } - - mouseOver += ( (int) value + "%"); - consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); - } - - - if (globalColourScheme != null) - globalColourScheme.setConsensus(hconsensus); - - } - catch (OutOfMemoryError error) - { - alignment.deleteAnnotation(consensus); - - consensus = null; - hconsensus = null; - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory calculating consensus!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - javax.swing.JOptionPane.WARNING_MESSAGE); - } - }); - - System.out.println("Consensus calculation: " + error); - System.gc(); - } - UPDATING_CONSENSUS = false; - updatingConsensus = false; - - if (ap != null) - { - ap.repaint(); - } + hasHiddenColumns = false; } } - /** - * 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