X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=9208e5e4308cdc979b721448a9bf8c9b480f3be8;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=36f69a52d6f27bb235ad2999e8c676287c57dce0;hpb=95028e2485f520a9263e779ea1340d433e414072;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 36f69a5..9208e5e 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,6 +1,23 @@ - /* +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * 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 . + */ +/* * 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,6 +35,10 @@ */ package jalview.gui; +import java.util.*; + +import java.awt.*; + import jalview.analysis.*; import jalview.bin.*; @@ -25,1537 +46,2277 @@ import jalview.bin.*; import jalview.datamodel.*; import jalview.schemes.*; - -import java.awt.*; - -import java.util.*; - +import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; /** * DOCUMENT ME! - * + * * @author $author$ * @version $Revision$ */ -public class AlignViewport +public class AlignViewport implements SelectionSource { - 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; + private static final int RIGHT_JUSTIFY = 1; - /** - * 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(); - } + int startRes; - void init() - { - this.startRes = 0; - this.endRes = alignment.getWidth() - 1; - this.startSeq = 0; - this.endSeq = alignment.getHeight() - 1; + int endRes; - antiAlias = Cache.getDefault("ANTI_ALIAS", false); + int startSeq; - showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true); - showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + 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); - } - } + boolean colourAppliesToAllGroups = true; - consensus = new AlignmentAnnotation("Consensus", "PID", - new Annotation[1], 0f, 100f, - AlignmentAnnotation.BAR_GRAPH); - consensus.hasText = true; + ColourSchemeI globalColourScheme = null; - if (Cache.getDefault("SHOW_IDENTITY", true)) - { - alignment.addAnnotation(consensus); - } - } + boolean conservationColourSelected = false; - if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) - { - globalColourScheme = ColourSchemeProperty.getColour(alignment, - jalview.bin.Cache.getProperty("DEFAULT_COLOUR")); + boolean abovePIDThreshold = false; - if (globalColourScheme instanceof UserColourScheme) - { - globalColourScheme = UserDefinedColours.loadDefaultColours(); - ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus()); - } + SequenceGroup selectionGroup; - if (globalColourScheme != null) - { - globalColourScheme.setConsensus(hconsensus); - } - } - } + int charHeight; + int charWidth; + boolean validCharWidth; - /** - * DOCUMENT ME! - * - * @param b DOCUMENT ME! - */ - public void setShowSequenceFeatures(boolean b) - { - showSequenceFeatures = b; - } + int wrappedWidth; - public boolean getShowSequenceFeatures() - { - return showSequenceFeatures; - } + Font font; + boolean seqNameItalics; + AlignmentI alignment; - class ConservationThread extends Thread - { - AlignmentPanel ap; - public ConservationThread(AlignmentPanel ap) - { - this.ap = ap; - } + ColumnSelection colSel = new ColumnSelection(); - public void run() - { - try - { - while (updatingConservation) - { - try - { - Thread.sleep(200); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } + int threshold; - updatingConservation = true; + int increment; + NJTree currentTree = null; - int alWidth = alignment.getWidth(); - if(alWidth<0) - return; + boolean scaleAboveWrapped = false; - Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alWidth -1); + boolean scaleLeftWrapped = true; - cons.calculate(); - cons.verdict(false, ConsPercGaps); + boolean scaleRightWrapped = true; - if (quality!=null) - { - cons.findQuality(); - } + boolean hasHiddenColumns = 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(); - } + boolean hasHiddenRows = false; - 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() - { + boolean showHiddenMarkers = true; + boolean cursorMode = false; - 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); - } - }); + /** + * Keys are the feature types which are currently visible. Note: Values are + * not used! + */ + Hashtable featuresDisplayed = null; - conservation = null; - quality = null; + /** DOCUMENT ME!! */ + public Hashtable[] hconsensus; - System.out.println("Conservation calculation: " + error); - System.gc(); + AlignmentAnnotation consensus; - } + AlignmentAnnotation conservation; - if(ap!=null) - { - ap.repaint(); - } - updatingConservation = false; - } - } + AlignmentAnnotation quality; + AlignmentAnnotation[] groupConsensus; - ConservationThread conservationThread; + AlignmentAnnotation[] groupConservation; - ConsensusThread consensusThread; + boolean autoCalculateConsensus = true; - boolean consUpdateNeeded = false; + /** DOCUMENT ME!! */ + public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! - static boolean updatingConsensus = false; + // JBPNote Prolly only need this in the applet version. + private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport( + this); - static boolean updatingConservation = false; + boolean ignoreGapsInConsensusCalculation = false; - /** - * DOCUMENT ME! - */ - public void updateConservation(final AlignmentPanel ap) - { - if (alignment.isNucleotide() || conservation==null) - return; + boolean isDataset = false; - conservationThread = new ConservationThread(ap); - conservationThread.start(); - } + boolean antiAlias = false; - /** - * DOCUMENT ME! - */ - public void updateConsensus(final AlignmentPanel ap) - { - consensusThread = new ConsensusThread(ap); - consensusThread.start(); - } + boolean padGaps = false; + Rectangle explodedPosition; - class ConsensusThread extends Thread - { - AlignmentPanel ap; - public ConsensusThread(AlignmentPanel ap) - { - this.ap = ap; - } - public void run() - { - while (updatingConsensus) - { - try - { - Thread.sleep(200); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } + String viewName; - updatingConsensus = true; + String sequenceSetID; - try - { - int aWidth = alignment.getWidth(); - if(aWidth<0) - return; + boolean gatherViewsHere = false; - consensus.annotations = null; - consensus.annotations = new Annotation[aWidth]; + Stack historyList = new Stack(); + Stack redoList = new Stack(); - hconsensus = new Hashtable[aWidth]; - AAFrequency.calculate(alignment.getSequencesArray(), - 0, - alignment.getWidth(), - hconsensus); + Hashtable sequenceColours; - 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); - } + int thresholdTextColour = 0; + Color textColour = Color.black; - if (globalColourScheme != null) - globalColourScheme.setConsensus(hconsensus); + Color textColour2 = Color.white; - } - catch (OutOfMemoryError error) - { - 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(); - } + boolean rightAlignIds = false; - if (ap != null) - { - ap.repaint(); - } + Hashtable hiddenRepSequences; + boolean sortByTree; - updatingConsensus = 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