X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=289fab7157bac8477dfa3507684decf6901de678;hb=743075ad19dc11ae8456491c51a0c8808b996dc1;hp=587ce55aafc83af4014080a2186c82a0a4024a0f;hpb=7ebc9696776dd018372c73885706fad8648560c2;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 587ce55..289fab7 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) + * Copyright (C) 2009 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 @@ -142,7 +142,9 @@ public class AlignViewport implements SelectionSource AlignmentAnnotation conservation; AlignmentAnnotation quality; - + AlignmentAnnotation[] groupConsensus; + AlignmentAnnotation[] groupConservation; + boolean autoCalculateConsensus = true; /** DOCUMENT ME!! */ @@ -184,6 +186,8 @@ public class AlignViewport implements SelectionSource Hashtable hiddenRepSequences; + boolean sortByTree; + /** * Creates a new AlignViewport object. * @@ -228,9 +232,11 @@ public class AlignViewport implements SelectionSource if (hiddenColumns != null) { this.colSel = hiddenColumns; - if (hiddenColumns.getHiddenColumns() != null) + if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0) { hasHiddenColumns = true; + } else { + hasHiddenColumns = false; } } init(); @@ -263,9 +269,11 @@ public class AlignViewport implements SelectionSource if (hiddenColumns != null) { this.colSel = hiddenColumns; - if (hiddenColumns.getHiddenColumns() != null) + if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0) { hasHiddenColumns = true; + } else { + hasHiddenColumns = false; } } init(); @@ -342,7 +350,7 @@ public class AlignViewport implements SelectionSource alignment.addAnnotation(quality); } } - + // TODO: add menu option action that nulls or creates consensus object depending on if the user wants to see the annotation or not in a specific alignment consensus = new AlignmentAnnotation("Consensus", "PID", new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); consensus.hasText = true; @@ -373,13 +381,15 @@ public class AlignViewport implements SelectionSource } wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false); + showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false); + sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false); } /** - * DOCUMENT ME! + * set the flag * * @param b - * DOCUMENT ME! + * features are displayed if true */ public void setShowSequenceFeatures(boolean b) { @@ -391,146 +401,6 @@ public class AlignViewport implements SelectionSource return showSequenceFeatures; } - class ConservationThread extends Thread - { - AlignmentPanel ap; - - public ConservationThread(AlignmentPanel ap) - { - this.ap = ap; - } - - public void run() - { - try - { - updatingConservation = true; - - while (UPDATING_CONSERVATION) - { - try - { - if (ap != null) - { - ap.paintAlignment(false); - } - 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, alWidth - 1); - - cons.calculate(); - cons.verdict(false, ConsPercGaps); - - if (quality != null) - { - cons.findQuality(); - } - - char[] 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(); - } - - for (int i = 0; i < alWidth; i++) - { - float value = 0; - - 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; - 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) - { - new OOMWarning("calculating conservation", error); - - conservation = null; - quality = null; - - } - - UPDATING_CONSERVATION = false; - updatingConservation = false; - - if (ap != null) - { - ap.paintAlignment(true); - } - - } - } - ConservationThread conservationThread; ConsensusThread consensusThread; @@ -556,16 +426,22 @@ public class AlignViewport implements SelectionSource private boolean shownpfeats; /** + * consensus annotation includes all percentage for all symbols in column + */ + private boolean includeAllConsensusSymbols=true; + + /** * trigger update of conservation annotation */ public void updateConservation(final AlignmentPanel ap) { - if (alignment.isNucleotide() || conservation == null) + // see note in mantis : issue number 8585 + if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus) { return; } - conservationThread = new ConservationThread(ap); + conservationThread = new ConservationThread(this, ap); conservationThread.start(); } @@ -574,6 +450,11 @@ public class AlignViewport implements SelectionSource */ public void updateConsensus(final AlignmentPanel ap) { + // see note in mantis : issue number 8585 + if (consensus == null || !autoCalculateConsensus) + { + return; + } consensusThread = new ConsensusThread(ap); consensusThread.start(); } @@ -624,38 +505,9 @@ public class AlignViewport implements SelectionSource hconsensus = new Hashtable[aWidth]; AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment - .getWidth(), hconsensus); - - 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); - } - + .getWidth(), hconsensus, includeAllConsensusSymbols); + AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols); + if (globalColourScheme != null) { globalColourScheme.setConsensus(hconsensus); @@ -1618,14 +1470,14 @@ public class AlignViewport implements SelectionSource */ public SequenceI[] getSequenceSelection() { - SequenceI[] sequences; - if (selectionGroup == null) + SequenceI[] sequences=null; + if (selectionGroup!=null) { - sequences = alignment.getSequencesArray(); + sequences = selectionGroup.getSequencesInOrder(alignment); } - else + if (sequences == null) { - sequences = selectionGroup.getSequencesInOrder(alignment); + sequences = alignment.getSequencesArray(); } return sequences; } @@ -1883,9 +1735,12 @@ public class AlignViewport implements SelectionSource } if (hconsensus != null && autoCalculateConsensus) { - updateConsensus(ap); updateConservation(ap); } + if (autoCalculateConsensus) + { + updateConsensus(ap); + } // Reset endRes of groups if beyond alignment width int alWidth = alignment.getWidth(); @@ -2188,5 +2043,91 @@ public class AlignViewport implements SelectionSource { return showSeqFeaturesHeight; } - + boolean showUnconserved=false; + public boolean getShowUnconserved() + { + return showUnconserved; + } + public void setShowUnconserved(boolean showunconserved) + { + showUnconserved=showunconserved; + } + /** + * return the alignPanel containing the given viewport. Use this to get the + * components currently handling the given viewport. + * @param av + * @return null or an alignPanel guaranteed to have non-null alignFrame reference + */ + public AlignmentPanel getAlignPanel() + { + AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId()); + AlignmentPanel ap=null; + for (int p=0;aps!=null && p