X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=bccb877e88d0ac0718339da63e2fabd4ea033e44;hb=5ae7fc3b4050c0ed10c9e6ad96f4b5360bce5f84;hp=3af97abadb2c86b4cade0940f2607a959ba47b0d;hpb=187b75ac779575fa0399f7c3991dcd7bade8ca90;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 3af97ab..bccb877 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 * @@ -43,7 +43,7 @@ public class AlignViewport int endRes; int startSeq; int endSeq; - boolean showFullId = false; + boolean showJVSuffix = true; boolean showText = true; boolean showColourText = false; boolean showBoxes = true; @@ -61,9 +61,9 @@ public class AlignViewport SequenceGroup selectionGroup; int charHeight; int charWidth; - int chunkWidth; - int chunkHeight; - Font font = new Font("SansSerif", Font.PLAIN, 10); + boolean validCharWidth; + int wrappedWidth; + Font font; AlignmentI alignment; ColumnSelection colSel = new ColumnSelection(); int threshold; @@ -72,12 +72,23 @@ public class AlignViewport 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 Vector vconsensus; AlignmentAnnotation consensus; AlignmentAnnotation conservation; AlignmentAnnotation quality; + boolean autoCalculateConsensus = true; /** DOCUMENT ME!! */ public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! @@ -85,6 +96,21 @@ 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; + + boolean isDataset = false; + + boolean antiAlias = false; + + boolean padGaps = false; + + + public AlignViewport(AlignmentI al, boolean dataset) + { + isDataset = dataset; + setAlignment(al); + init(); + } /** * Creates a new AlignViewport object. * @@ -93,65 +119,81 @@ public class AlignViewport public AlignViewport(AlignmentI al) { setAlignment(al); - this.startRes = 0; - this.endRes = al.getWidth() - 1; - this.startSeq = 0; - this.endSeq = al.getHeight() - 1; - - updateFromPreferences(); + init(); } - /** - * DOCUMENT ME! + * Create a new AlignViewport with hidden regions + * @param al AlignmentI + * @param hiddenColumns ColumnSelection */ - public void updateFromPreferences() + public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) { + setAlignment(al); + if (hiddenColumns!=null) { + this.colSel = hiddenColumns; + if (hiddenColumns.getHiddenColumns() != null) + hasHiddenColumns = true; + } + init(); + } + + void init() { - showFullId = Preferences.showFullId; - showAnnotation = Preferences.showAnnotation; - showConservation = Preferences.showConservation; - showQuality = Preferences.showQuality; - showIdentity = Preferences.showIdentity; - showFullId = Preferences.showFullId; + this.startRes = 0; + this.endRes = alignment.getWidth() - 1; + this.startSeq = 0; + this.endSeq = alignment.getHeight() - 1; - String fontName = Preferences.fontName; - String fontStyle = Preferences.fontStyle; - String fontSize = Cache.getProperty("FONT_SIZE"); + antiAlias = Cache.getDefault("ANTI_ALIAS", false); - if ((fontName != null) && (fontStyle != null) && (fontSize != null)) - { - int style = 0; + showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true); + showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + showConservation = Cache.getDefault("SHOW_CONSERVATION", true); - if (fontStyle.equals("bold")) - { - style = 1; - } - else if (fontStyle.equals("italic")) - { - style = 2; - } + showQuality = Cache.getDefault("SHOW_QUALITY", true); + showIdentity = Cache.getDefault("SHOW_IDENTITY", true); + + autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true); + + padGaps = Cache.getDefault("PAD_GAPS", false); + + String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); + String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ; + String fontSize = Cache.getDefault("FONT_SIZE", "10"); + + int style = 0; + + if (fontStyle.equals("bold")) + { + style = 1; + } + else if (fontStyle.equals("italic")) + { + style = 2; + } + + setFont(new Font(fontName, style, Integer.parseInt(fontSize))); - setFont(new Font(fontName, style, Integer.parseInt(fontSize))); - } - else - { - setFont(font); - } - alignment.setGapCharacter(Preferences.gapSymbol); + alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) ); + // We must set conservation and consensus before setting colour, // as Blosum and Clustal require this to be done - updateConservation(); - updateConsensus(); + if(vconsensus==null && !isDataset) + { + 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,24 +203,35 @@ public class AlignViewport } } + + /** * DOCUMENT ME! * * @param b DOCUMENT ME! */ - public void showSequenceFeatures(boolean b) + public void setShowSequenceFeatures(boolean b) { showSequenceFeatures = b; } + public boolean getShowSequenceFeatures() + { + return showSequenceFeatures; + } + /** * DOCUMENT ME! */ public void updateConservation() { + if(alignment.isNucleotide()) + return; + + 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 +260,96 @@ 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) == '+') { - if (sequence.charAt(i) == '*') - { - value = 11; - } - - if (sequence.charAt(i) == '+') - { - value = 10; - } + 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() + AlignmentAnnotation.BAR_GRAPH); + + if (showConservation) + { + alignment.addAnnotation(conservation); + } + + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + qannotations, + cons.qualityRange[0].floatValue(), + cons.qualityRange[1].floatValue(), + AlignmentAnnotation.BAR_GRAPH); + + 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) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + 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); + } + }); + + System.out.println("Conservation calculation: " + error); + System.gc(); + + } } /** @@ -279,6 +357,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 +365,84 @@ 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); - - float value = Float.parseFloat(hash.get("maxCount").toString()); - value /= Float.parseFloat(hash.get("size").toString()); + hash = (Hashtable) vconsensus.elementAt(i); - value *= 100; + float value = 0; + if (ignoreGapsInConsensusCalculation) + value = ( (Float) hash.get("pid_nogaps")).floatValue(); + else + value = ( (Float) hash.get("pid_gaps")).floatValue(); - String maxRes = hash.get("maxResidue") + " "; - String mouseOver = hash.get("maxResidue") + " "; + String maxRes = hash.get("maxResidue").toString(); + 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,AlignmentAnnotation.BAR_GRAPH); - 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) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Out of memory calc45ulating 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(); + } + } /** @@ -531,12 +635,12 @@ 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')); + validCharWidth = true; } /** @@ -594,9 +698,9 @@ public class AlignViewport * * @param w DOCUMENT ME! */ - public void setChunkWidth(int w) + public void setWrappedWidth(int w) { - this.chunkWidth = w; + this.wrappedWidth = w; } /** @@ -604,30 +708,11 @@ public class AlignViewport * * @return DOCUMENT ME! */ - public int getChunkWidth() + public int getWrappedWidth() { - return chunkWidth; + return wrappedWidth; } - /** - * DOCUMENT ME! - * - * @param h DOCUMENT ME! - */ - public void setChunkHeight(int h) - { - this.chunkHeight = h; - } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getChunkHeight() - { - return chunkHeight; - } /** * DOCUMENT ME! @@ -802,41 +887,6 @@ public class AlignViewport return increment; } - /** - * DOCUMENT ME! - * - * @param y DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getIndex(int y) - { - int y1 = 0; - int starty = getStartSeq(); - int endy = getEndSeq(); - - for (int i = starty; i <= endy; i++) - { - if ((i < alignment.getHeight()) && - (alignment.getSequenceAt(i) != null)) - { - int y2 = y1 + getCharHeight(); - - if ((y >= y1) && (y <= y2)) - { - return i; - } - - y1 = y2; - } - else - { - return -1; - } - } - - return -1; - } /** * DOCUMENT ME! @@ -848,15 +898,6 @@ public class AlignViewport return colSel; } - /** - * DOCUMENT ME! - * - * @param height DOCUMENT ME! - */ - public void resetSeqLimits(int height) - { - setEndSeq(height / getCharHeight()); - } /** * DOCUMENT ME! @@ -903,9 +944,9 @@ public class AlignViewport * * @return DOCUMENT ME! */ - public boolean getShowFullId() + public boolean getShowJVSuffix() { - return showFullId; + return showJVSuffix; } /** @@ -913,11 +954,12 @@ public class AlignViewport * * @param b DOCUMENT ME! */ - public void setShowFullId(boolean b) + public void setShowJVSuffix(boolean b) { - showFullId = b; + showJVSuffix = b; } + /** * DOCUMENT ME! * @@ -999,7 +1041,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param listener DOCUMENT ME! */ @@ -1021,7 +1063,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param prop DOCUMENT ME! * @param oldvalue DOCUMENT ME! @@ -1031,4 +1073,359 @@ 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; + } + + public void setDataset(boolean b) + { + isDataset = b; + } + + public boolean isDataset() + { + return isDataset; + } + + + public void hideSelectedColumns() + { + if (colSel.size() < 1) + return; + + colSel.hideSelectedColumns(); + setSelectionGroup(null); + + hasHiddenColumns = true; + } + + + public void hideColumns(int start, int end) + { + if(start==end) + colSel.hideColumns(start); + else + colSel.hideColumns(start, end); + + hasHiddenColumns = true; + } + + public void hideAllSelectedSeqs() + { + if (selectionGroup == null) + return; + + SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment); + + for (int i = 0; i < seqs.length; i++) + { + alignment.getHiddenSequences().hideSequence(seqs[i]); + } + firePropertyChange("alignment", null, alignment.getSequences()); + hasHiddenRows = true; + setSelectionGroup(null); + } + + public void hideSequence(SequenceI seq) + { + if(seq!=null) + { + alignment.getHiddenSequences().hideSequence(seq); + hasHiddenRows = true; + firePropertyChange("alignment", null, alignment.getSequences()); + } + } + + public void showSequence(int index) + { + Vector tmp = alignment.getHiddenSequences().showSequence(index); + if(tmp.size()>0) + { + if(selectionGroup==null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(alignment.getWidth()-1); + } + + for (int t = 0; t < tmp.size(); t++) + { + selectionGroup.addSequence( + (SequenceI) tmp.elementAt(t), false + ); + } + firePropertyChange("alignment", null, alignment.getSequences()); + } + + if(alignment.getHiddenSequences().getSize()<1) + hasHiddenRows = false; + } + + public void showColumn(int col) + { + colSel.revealHiddenColumns(col); + if(colSel.getHiddenColumns()==null) + hasHiddenColumns = false; + } + + public void showAllHiddenColumns() + { + colSel.revealAllHiddenColumns(); + hasHiddenColumns = false; + } + + public void showAllHiddenSeqs() + { + if(alignment.getHiddenSequences().getSize()>0) + { + if(selectionGroup==null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(alignment.getWidth()-1); + } + Vector tmp = alignment.getHiddenSequences().showAll(); + for(int t=0; t