X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=b68008a0495a467e946fcd83b38e05ba11fb0052;hb=5c57814f95e73a63e012479651b919fdc4099f53;hp=ddb871e3e891f38cccb5cad4d4a8483d6f817f99;hpb=82cbe684b0afeb8a6a8c6014b9266cb90439dfe7;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ddb871e..b68008a 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,6 +1,6 @@ /* * 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 +18,10 @@ */ package jalview.gui; +import java.util.*; + +import java.awt.*; + import jalview.analysis.*; import jalview.bin.*; @@ -26,11 +30,6 @@ import jalview.datamodel.*; import jalview.schemes.*; -import java.awt.*; - -import java.util.*; - - /** * DOCUMENT ME! * @@ -51,9 +50,6 @@ public class AlignViewport boolean renderGaps = true; boolean showSequenceFeatures = false; boolean showAnnotation = true; - boolean showConservation = true; - boolean showQuality = true; - boolean showIdentity = true; boolean colourAppliesToAllGroups = true; ColourSchemeI globalColourScheme = null; boolean conservationColourSelected = false; @@ -64,6 +60,7 @@ public class AlignViewport boolean validCharWidth; int wrappedWidth; Font font; + boolean seqNameItalics; AlignmentI alignment; ColumnSelection colSel = new ColumnSelection(); int threshold; @@ -94,7 +91,8 @@ public class AlignViewport 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); + private java.beans.PropertyChangeSupport changeSupport = new java.beans. + PropertyChangeSupport(this); boolean ignoreGapsInConsensusCalculation = false; @@ -112,13 +110,20 @@ public class AlignViewport 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; + + Hashtable hiddenRepSequences; + - public AlignViewport(AlignmentI al, boolean dataset) - { - isDataset = dataset; - setAlignment(al); - init(); - } /** * Creates a new AlignViewport object. * @@ -134,13 +139,17 @@ public class AlignViewport * @param al AlignmentI * @param hiddenColumns ColumnSelection */ - public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) { + public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) + { setAlignment(al); - if (hiddenColumns!=null) { + if (hiddenColumns != null) + { this.colSel = hiddenColumns; if (hiddenColumns.getHiddenColumns() != null) + { hasHiddenColumns = true; } + } init(); } @@ -155,19 +164,19 @@ public class AlignViewport showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true); showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); - showConservation = Cache.getDefault("SHOW_CONSERVATION", true); - showQuality = Cache.getDefault("SHOW_QUALITY", true); - showIdentity = Cache.getDefault("SHOW_IDENTITY", true); + rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false); autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true); - padGaps = Cache.getDefault("PAD_GAPS", false); + padGaps = Cache.getDefault("PAD_GAPS", true); String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ; String fontSize = Cache.getDefault("FONT_SIZE", "10"); + seqNameItalics = Cache.getDefault("ID_ITALICS", true); + int style = 0; if (fontStyle.equals("bold")) @@ -181,7 +190,6 @@ public class AlignViewport setFont(new Font(fontName, style, Integer.parseInt(fontSize))); - alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) ); @@ -198,13 +206,15 @@ public class AlignViewport 11f, AlignmentAnnotation.BAR_GRAPH); conservation.hasText = true; + conservation.autoCalculated=true; + - if (showConservation) + if (Cache.getDefault("SHOW_CONSERVATION", true)) { alignment.addAnnotation(conservation); } - if (showQuality) + if (Cache.getDefault("SHOW_QUALITY", true)) { quality = new AlignmentAnnotation("Quality", "Alignment Quality based on Blosum62 scores", @@ -212,6 +222,8 @@ public class AlignViewport 0f, 11f, AlignmentAnnotation.BAR_GRAPH); + quality.hasText = true; + quality.autoCalculated=true; alignment.addAnnotation(quality); } @@ -221,12 +233,12 @@ public class AlignViewport new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); consensus.hasText = true; + consensus.autoCalculated=true; - if (showIdentity) + if (Cache.getDefault("SHOW_IDENTITY", true)) { alignment.addAnnotation(consensus); } - } if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) @@ -237,7 +249,8 @@ public class AlignViewport if (globalColourScheme instanceof UserColourScheme) { globalColourScheme = UserDefinedColours.loadDefaultColours(); - ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus()); + ( (UserColourScheme) globalColourScheme).setThreshold(0, + getIgnoreGapsConsensus()); } if (globalColourScheme != null) @@ -245,6 +258,8 @@ public class AlignViewport globalColourScheme.setConsensus(hconsensus); } } + + wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false); } @@ -264,9 +279,8 @@ public class AlignViewport return showSequenceFeatures; } - - - class ConservationThread extends Thread + class ConservationThread + extends Thread { AlignmentPanel ap; public ConservationThread(AlignmentPanel ap) @@ -278,25 +292,46 @@ public class AlignViewport { try { - long t = System.currentTimeMillis(); + updatingConservation = true; + + while (UPDATING_CONSERVATION) + { + try + { + if (ap != null) + { + ap.paintAlignment(true); + } + Thread.sleep(200); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + UPDATING_CONSERVATION = true; + + + int alWidth = alignment.getWidth(); + if(alWidth<0) + { + return; + } Conservation cons = new jalview.analysis.Conservation("All", jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alignment.getWidth() - 1); + alignment.getSequences(), 0, alWidth -1); cons.calculate(); cons.verdict(false, ConsPercGaps); - if (showQuality) + if (quality!=null) { cons.findQuality(); } - System.out.println("Conservation took " + (System.currentTimeMillis() - t) + - "ms"); - - int alWidth = alignment.getWidth(); - String sequence = cons.getConsSequence().getSequence(); + char [] sequence = cons.getConsSequence().getSequence(); float minR; float minG; float minB; @@ -319,8 +354,9 @@ public class AlignViewport conservation.annotations = new Annotation[alWidth]; - if (showQuality) + if (quality!=null) { + quality.graphMax = cons.qualityRange[1].floatValue(); quality.annotations = new Annotation[alWidth]; qmin = cons.qualityRange[0].floatValue(); qmax = cons.qualityRange[1].floatValue(); @@ -330,14 +366,20 @@ public class AlignViewport { float value = 0; - c = sequence.charAt(i); + c = sequence[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; @@ -349,28 +391,26 @@ public class AlignViewport minB + (maxB * vprop))); // Quality calc - if (showQuality) + if (quality!=null) { value = ( (Double) cons.quality.get(i)).floatValue(); vprop = value - qmin; vprop /= qmax; - quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ', + quality.annotations[i] = new Annotation(" ", String.valueOf(value), + ' ', value, new Color(minR + (maxR * vprop), minG + (maxG * vprop), minB + (maxB * vprop))); } } - - if (quality != null) - { - quality.graphMax = cons.qualityRange[1].floatValue(); - } } catch (OutOfMemoryError error) { javax.swing.SwingUtilities.invokeLater(new Runnable() { + + public void run() { javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, @@ -382,16 +422,22 @@ public class AlignViewport } }); + conservation = null; + quality = null; + System.out.println("Conservation calculation: " + error); System.gc(); } + UPDATING_CONSERVATION = false; + updatingConservation = false; + if(ap!=null) { - ap.annotationPanel.repaint(); + ap.paintAlignment(true); } - updatingConservation = false; + } } @@ -402,6 +448,10 @@ public class AlignViewport boolean consUpdateNeeded = false; + static boolean UPDATING_CONSENSUS = false; + + static boolean UPDATING_CONSERVATION = false; + boolean updatingConsensus = false; boolean updatingConservation = false; @@ -409,46 +459,28 @@ public class AlignViewport /** * DOCUMENT ME! */ - public void updateConservation(AlignmentPanel ap) + public void updateConservation(final AlignmentPanel ap) + { + if (alignment.isNucleotide() || conservation==null) { - if (alignment.isNucleotide()) return; + } - updatingConservation = true; - - if (conservationThread == null || !conservationThread.isAlive()) - { - conservationThread = new ConservationThread(ap); - conservationThread.start(); - } - else - { - consUpdateNeeded = true; - System.out.println("come back later"); - } + conservationThread = new ConservationThread(ap); + conservationThread.start(); } /** * DOCUMENT ME! */ - public void updateConsensus(AlignmentPanel ap) + public void updateConsensus(final AlignmentPanel ap) { - updatingConsensus = true; - - if (consensusThread == null || !consensusThread.isAlive()) - { - consensusThread = new ConsensusThread(ap); - consensusThread.start(); - } - else - { - consUpdateNeeded = true; - System.out.println("come back later"); - } + consensusThread = new ConsensusThread(ap); + consensusThread.start(); } - - class ConsensusThread extends Thread + class ConsensusThread + extends Thread { AlignmentPanel ap; public ConsensusThread(AlignmentPanel ap) @@ -457,32 +489,58 @@ public class AlignViewport } public void run() { + updatingConsensus = true; + while (UPDATING_CONSENSUS) + { + try + { + if (ap != null) + { + ap.paintAlignment(true); + } + + 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]; - long t = System.currentTimeMillis(); + hconsensus = new Hashtable[aWidth]; AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment.getWidth(), hconsensus); - System.out.println("Consensus took " + - (System.currentTimeMillis() - t) + "ms"); - 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) + " "; @@ -494,16 +552,23 @@ public class AlignViewport } mouseOver += ( (int) value + "%"); - consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', 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() @@ -520,36 +585,49 @@ public class AlignViewport System.out.println("Consensus calculation: " + error); System.gc(); } + UPDATING_CONSENSUS = false; + updatingConsensus = false; if (ap != null) { - ap.annotationPanel.repaint(); + ap.paintAlignment(true); } - - - 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() { + public SequenceI getConsensusSeq() + { if (consensus==null) + { updateConsensus(null); + } if (consensus==null) + { return null; + } StringBuffer seqs=new StringBuffer(); - for (int i=0; i0) { if(selectionGroup==null) @@ -1274,15 +1398,19 @@ public class AlignViewport } if(alignment.getHiddenSequences().getSize()<1) + { hasHiddenRows = false; } + } public void showColumn(int col) { colSel.revealHiddenColumns(col); if(colSel.getHiddenColumns()==null) + { hasHiddenColumns = false; } + } public void showAllHiddenColumns() { @@ -1299,7 +1427,7 @@ public class AlignViewport selectionGroup = new SequenceGroup(); selectionGroup.setEndRes(alignment.getWidth()-1); } - Vector tmp = alignment.getHiddenSequences().showAll(); + Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences); for(int t=0; t