X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=1efb272234cb4194bfcab4bc116713d85dbcca3d;hb=42959f09b255337ab66e0abebb02896745400a29;hp=e8f34d8a320ae0a5924cbe6f0c025b446312586b;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index e8f34d8..1efb272 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,4 +1,4 @@ -/* + /* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * @@ -58,7 +58,7 @@ public class AlignViewport ColourSchemeI globalColourScheme = null; boolean conservationColourSelected = false; boolean abovePIDThreshold = false; - SequenceGroup selectionGroup = new SequenceGroup(); + SequenceGroup selectionGroup; int charHeight; int charWidth; int chunkWidth; @@ -85,6 +85,8 @@ public class AlignViewport // JBPNote Prolly only need this in the applet version. private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this); + boolean ignoreGapsInConsensusCalculation = false; + /** * Creates a new AlignViewport object. * @@ -106,52 +108,48 @@ public class AlignViewport */ public void updateFromPreferences() { - showFullId = Preferences.showFullId; - showAnnotation = Preferences.showAnnotation; - showConservation = Preferences.showConservation; - showQuality = Preferences.showQuality; - showIdentity = Preferences.showIdentity; - showFullId = Preferences.showFullId; + showFullId = Cache.getDefault("SHOW_FULL_ID", true); + showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + showConservation = Cache.getDefault("SHOW_CONSERVATION", true); - String fontName = Preferences.fontName; - String fontStyle = Preferences.fontStyle; - String fontSize = Cache.getProperty("FONT_SIZE"); + showQuality = Cache.getDefault("SHOW_QUALITY", true); + showIdentity = Cache.getDefault("SHOW_IDENTITY", true); - if ((fontName != null) && (fontStyle != null) && (fontSize != null)) - { - int style = 0; + String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); + String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ; + String fontSize = Cache.getDefault("FONT_SIZE", "10"); - if (fontStyle.equals("bold")) - { - style = 1; - } - else if (fontStyle.equals("italic")) - { - style = 2; - } + int style = 0; - setFont(new Font(fontName, style, Integer.parseInt(fontSize))); - } - else - { - setFont(font); - } + if (fontStyle.equals("bold")) + { + style = 1; + } + else if (fontStyle.equals("italic")) + { + style = 2; + } + + setFont(new Font(fontName, style, Integer.parseInt(fontSize))); + + + alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) ); - alignment.setGapCharacter(Preferences.gapSymbol); // We must set conservation and consensus before setting colour, // as Blosum and Clustal require this to be done updateConservation(); updateConsensus(); - if (Preferences.defaultColour != null) + if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) { - globalColourScheme = ColourSchemeProperty.getColour(alignment, - Preferences.defaultColour); + 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) @@ -161,6 +159,8 @@ public class AlignViewport } } + + /** * DOCUMENT ME! * @@ -176,9 +176,10 @@ public class AlignViewport */ public void updateConservation() { + try{ Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alignment.getWidth() - 1); + jalview.schemes.ResidueProperties.propHash, 3, + alignment.getSequences(), 0, alignment.getWidth() - 1); cons.calculate(); cons.verdict(false, ConsPercGaps); cons.findQuality(); @@ -207,71 +208,80 @@ public class AlignViewport for (int i = 0; i < alWidth; i++) { - float value = 0; - - try + float value = 0; + + try + { + value = Integer.parseInt(sequence.charAt(i) + ""); + } + catch (Exception ex) + { + if (sequence.charAt(i) == '*') { - value = Integer.parseInt(sequence.charAt(i) + ""); + value = 11; } - catch (Exception ex) - { - if (sequence.charAt(i) == '*') - { - value = 11; - } - if (sequence.charAt(i) == '+') - { - value = 10; - } + if (sequence.charAt(i) == '+') + { + value = 10; } - - float vprop = value - min; - vprop /= max; - annotations[i] = new Annotation(sequence.charAt(i) + "", - String.valueOf(value), ' ', value, - new Color(minR + (maxR * vprop), minG + (maxG * vprop), - minB + (maxB * vprop))); - - // Quality calc - value = ((Double) cons.quality.get(i)).floatValue(); - vprop = value - qmin; - vprop /= qmax; - qannotations[i] = new Annotation(" ", String.valueOf(value), ' ', - value, - new Color(minR + (maxR * vprop), minG + (maxG * vprop), - minB + (maxB * vprop))); + } + + float vprop = value - min; + vprop /= max; + annotations[i] = new Annotation(sequence.charAt(i) + "", + String.valueOf(value), ' ', value, + new Color(minR + (maxR * vprop), + minG + (maxG * vprop), + minB + (maxB * vprop))); + + // Quality calc + value = ( (Double) cons.quality.get(i)).floatValue(); + vprop = value - qmin; + vprop /= qmax; + qannotations[i] = new Annotation(" ", String.valueOf(value), ' ', + value, + new Color(minR + (maxR * vprop), + minG + (maxG * vprop), + minB + (maxB * vprop))); } if (conservation == null) { - conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " + - ConsPercGaps + "% gaps", annotations, 0f, // cons.qualityRange[0].floatValue(), - 11f, // cons.qualityRange[1].floatValue() - 1); - - if (showConservation) - { - alignment.addAnnotation(conservation); - } - - quality = new AlignmentAnnotation("Quality", - "Alignment Quality based on Blosum62 scores", qannotations, - cons.qualityRange[0].floatValue(), - cons.qualityRange[1].floatValue(), 1); - - if (showQuality) - { - alignment.addAnnotation(quality); - } + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment less than " + + ConsPercGaps + "% gaps", + annotations, 0f, // cons.qualityRange[0].floatValue(), + 11f, // cons.qualityRange[1].floatValue() + 1); + + if (showConservation) + { + alignment.addAnnotation(conservation); + } + + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + qannotations, + cons.qualityRange[0].floatValue(), + cons.qualityRange[1].floatValue(), + 1); + + if (showQuality) + { + alignment.addAnnotation(quality); + } } else { - conservation.annotations = annotations; - quality.annotations = qannotations; - quality.graphMax = cons.qualityRange[1].floatValue(); + conservation.annotations = annotations; + quality.annotations = qannotations; + quality.graphMax = cons.qualityRange[1].floatValue(); } + }catch(OutOfMemoryError error) + { + System.out.println("Out of memory calculating conservation."); + } } /** @@ -279,6 +289,7 @@ public class AlignViewport */ public void updateConsensus() { + try{ Annotation[] annotations = new Annotation[alignment.getWidth()]; // this routine prevents vconsensus becoming a new object each time @@ -286,59 +297,69 @@ public class AlignViewport // and PID colouring of alignment if (vconsensus == null) { - vconsensus = alignment.getAAFrequency(); + vconsensus = alignment.getAAFrequency(); } else { - Vector temp = alignment.getAAFrequency(); - vconsensus.clear(); + Vector temp = alignment.getAAFrequency(); + vconsensus.clear(); - Enumeration e = temp.elements(); + Enumeration e = temp.elements(); - while (e.hasMoreElements()) - { - vconsensus.add(e.nextElement()); - } + while (e.hasMoreElements()) + { + vconsensus.add(e.nextElement()); + } } Hashtable hash = null; for (int i = 0; i < alignment.getWidth(); i++) { - hash = (Hashtable) vconsensus.elementAt(i); + hash = (Hashtable) vconsensus.elementAt(i); - float value = Float.parseFloat(hash.get("maxCount").toString()); - value /= Float.parseFloat(hash.get("size").toString()); + float value = 0; + if (ignoreGapsInConsensusCalculation) + value = ( (Float) hash.get("pid_nogaps")).floatValue(); + else + value = ( (Float) hash.get("pid_gaps")).floatValue(); - value *= 100; + String maxRes = hash.get("maxResidue").toString(); + String mouseOver = hash.get("maxResidue") + " "; - String maxRes = hash.get("maxResidue") + " "; - String mouseOver = hash.get("maxResidue") + " "; - - if (maxRes.length() > 2) - { - mouseOver = "[" + maxRes + "] "; - maxRes = "+ "; - } + if (maxRes.length() > 1) + { + mouseOver = "[" + maxRes + "] "; + maxRes = "+"; + } - mouseOver += ((int) value + "%"); - annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + mouseOver += ( (int) value + "%"); + annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); } if (consensus == null) { - consensus = new AlignmentAnnotation("Consensus", "PID", - annotations, 0f, 100f, 1); + consensus = new AlignmentAnnotation("Consensus", "PID", + annotations, 0f, 100f, 1); - if (showIdentity) - { - alignment.addAnnotation(consensus); - } + if (showIdentity) + { + alignment.addAnnotation(consensus); + } } else { - consensus.annotations = annotations; + consensus.annotations = annotations; } + + if (globalColourScheme != null) + globalColourScheme.setConsensus(vconsensus); + + }catch(OutOfMemoryError error) + { + System.out.println("Out of memory calculating consensus."); + } + } /** @@ -531,10 +552,9 @@ public class AlignViewport { font = f; - javax.swing.JFrame temp = new javax.swing.JFrame(); - temp.addNotify(); + Container c = new Container(); - java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font); + java.awt.FontMetrics fm = c.getFontMetrics(font); setCharHeight(fm.getHeight()); setCharWidth(fm.charWidth('M')); } @@ -848,15 +868,6 @@ public class AlignViewport return colSel; } - /** - * DOCUMENT ME! - * - * @param height DOCUMENT ME! - */ - public void resetSeqLimits(int height) - { - setEndSeq(height / getCharHeight()); - } /** * DOCUMENT ME! @@ -999,7 +1010,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param listener DOCUMENT ME! */ @@ -1021,7 +1032,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param prop DOCUMENT ME! * @param oldvalue DOCUMENT ME! @@ -1031,4 +1042,20 @@ public class AlignViewport { changeSupport.firePropertyChange(prop, oldvalue, newvalue); } + + public void setIgnoreGapsConsensus(boolean b) + { + ignoreGapsInConsensusCalculation = b; + updateConsensus(); + if(globalColourScheme!=null) + { + globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation); + } + + } + + public boolean getIgnoreGapsConsensus() + { + return ignoreGapsInConsensusCalculation; + } }