X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=197018118bc51f1fec9797cd21a3d93407b60e3e;hb=32c056ffe34e60a1fde83bf4061af6e82d41f958;hp=ea974d502765205776ca9d80877e1caef76ea983;hpb=8da7acff9214ddaf0e6d28e76219ab51bd38e62d;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ea974d5..1970181 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! @@ -87,6 +98,19 @@ public class AlignViewport 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. * @@ -95,26 +119,29 @@ public class AlignViewport public AlignViewport(AlignmentI al) { setAlignment(al); + init(); + } + + void init() + { this.startRes = 0; - this.endRes = al.getWidth() - 1; + this.endRes = alignment.getWidth() - 1; this.startSeq = 0; - this.endSeq = al.getHeight() - 1; + this.endSeq = alignment.getHeight() - 1; - updateFromPreferences(); - } + antiAlias = Cache.getDefault("ANTI_ALIAS", false); - /** - * DOCUMENT ME! - */ - public void updateFromPreferences() - { - showFullId = Cache.getDefault("SHOW_FULL_ID", true); + 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); + 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"); @@ -138,8 +165,11 @@ public class AlignViewport // 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 (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) { @@ -166,19 +196,28 @@ public class AlignViewport * * @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 +246,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) == '*') - { - 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() + 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 +343,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,63 +351,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); + hash = (Hashtable) vconsensus.elementAt(i); - float value = 0; - if(ignoreGapsInConsensusCalculation) - value = ((Float)hash.get("pid_nogaps")).floatValue(); - else - value = ((Float)hash.get("pid_gaps")).floatValue(); + 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").toString(); - String mouseOver = hash.get("maxResidue")+" "; + String maxRes = hash.get("maxResidue").toString(); + String mouseOver = hash.get("maxResidue") + " "; - if (maxRes.length() > 1) - { - 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) + 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(); + } + } /** @@ -540,6 +626,7 @@ public class AlignViewport java.awt.FontMetrics fm = c.getFontMetrics(font); setCharHeight(fm.getHeight()); setCharWidth(fm.charWidth('M')); + validCharWidth = true; } /** @@ -597,9 +684,9 @@ public class AlignViewport * * @param w DOCUMENT ME! */ - public void setChunkWidth(int w) + public void setWrappedWidth(int w) { - this.chunkWidth = w; + this.wrappedWidth = w; } /** @@ -607,30 +694,11 @@ public class AlignViewport * * @return DOCUMENT ME! */ - public int getChunkWidth() - { - return chunkWidth; - } - - /** - * DOCUMENT ME! - * - * @param h DOCUMENT ME! - */ - public void setChunkHeight(int h) + public int getWrappedWidth() { - this.chunkHeight = h; + return wrappedWidth; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getChunkHeight() - { - return chunkHeight; - } /** * DOCUMENT ME! @@ -897,9 +965,9 @@ public class AlignViewport * * @return DOCUMENT ME! */ - public boolean getShowFullId() + public boolean getShowJVSuffix() { - return showFullId; + return showJVSuffix; } /** @@ -907,11 +975,12 @@ public class AlignViewport * * @param b DOCUMENT ME! */ - public void setShowFullId(boolean b) + public void setShowJVSuffix(boolean b) { - showFullId = b; + showJVSuffix = b; } + /** * DOCUMENT ME! * @@ -1034,11 +1103,205 @@ public class AlignViewport { 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; + + while (colSel.size() > 0) + { + int column = ( (Integer) colSel.getSelected().firstElement()).intValue(); + colSel.hideColumns(column); + } + setSelectionGroup(null); + hasHiddenColumns = true; + } + + + public void hideColumns(int start, int end) + { + if(start==end) + end++; + + for(int i=start; i0) + { + alignment.getHiddenSequences().showAll(); + hasHiddenRows = false; + } + } + + public int adjustForHiddenSeqs(int alignmentIndex) + { + return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex); + } + + /** + * This method returns the a new SequenceI [] with + * the selection sequence and start and end points adjusted + * @return String[] + */ + public SequenceI[] getSelectionAsNewSequence() + { + SequenceI[] sequences; + + if (selectionGroup == null) + sequences = alignment.getSequencesArray(); + else + sequences = selectionGroup.getSelectionAsNewSequences(alignment); + + return sequences; + } + + + /** + * This method returns the visible alignment as text, as + * seen on the GUI, ie if columns are hidden they will not + * be returned in the result. + * Use this for calculating trees, PCA, redundancy etc on views + * which contain hidden columns. + * @return String[] + */ + public String [] getViewAsString(boolean selectedRegionOnly) + { + String [] selection = null; + SequenceI [] seqs= null; + int i, iSize; + int start = 0, end = 0; + if(selectedRegionOnly && selectionGroup!=null) + { + iSize = selectionGroup.getSize(false); + seqs = selectionGroup.getSequencesInOrder(alignment); + start = selectionGroup.getStartRes(); + end = selectionGroup.getEndRes()+1; + } + else + { + iSize = alignment.getHeight(); + seqs = alignment.getSequencesArray(); + end = alignment.getWidth(); + } + + selection = new String[iSize]; + + + for(i=0; iblockEnd) + { + break; + } + + + visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd)); + + blockStart = hideEnd+1; + blockEnd = end; + } + + if(end>blockStart) + visibleSeq.append(seqs[i].getSequence(blockStart, end)); + + selection[i] = visibleSeq.toString(); + } + else + { + selection[i] = seqs[i].getSequence(start, end); + } + } + + return selection; + } + + public boolean getShowHiddenMarkers() + { + return showHiddenMarkers; + } + + public void setShowHiddenMarkers(boolean show) + { + showHiddenMarkers = show; + } }