X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAlignViewport.java;h=ff8f7df33959c561cc8eefe9cdd119a15e87edab;hb=fd026dead85b733e64fdc7c2e6c88d1adc10626a;hp=eb832f2f68a8b3c2c58dd8c415176c10bec59906;hpb=d545553b53ac1bd1e29eb72250cdb29745f7292f;p=jalview.git diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java old mode 100755 new mode 100644 index eb832f2..ff8f7df --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -1,22 +1,20 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ - package jalview.appletgui; import java.util.*; @@ -27,82 +25,134 @@ import jalview.analysis.*; import jalview.bin.*; import jalview.datamodel.*; import jalview.schemes.*; +import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; -public class AlignViewport +public class AlignViewport implements SelectionSource, VamsasSource { int startRes; + int endRes; int startSeq; - int endSeq; + int endSeq; boolean cursorMode = false; boolean showJVSuffix = true; + boolean showText = true; + boolean showColourText = false; + boolean showBoxes = true; + boolean wrapAlignment = false; + boolean renderGaps = true; + boolean showSequenceFeatures = false; + boolean showAnnotation = true; + boolean showConservation = true; + boolean showQuality = true; + boolean showConsensus = true; + boolean upperCasebold = false; + boolean colourAppliesToAllGroups = true; + ColourSchemeI globalColourScheme = null; + boolean conservationColourSelected = false; + boolean abovePIDThreshold = false; SequenceGroup selectionGroup; int charHeight; + int charWidth; + int wrappedWidth; Font font = new Font("SansSerif", Font.PLAIN, 10); + boolean validCharWidth = true; + AlignmentI alignment; ColumnSelection colSel = new ColumnSelection(); int threshold; + int increment; NJTree currentTree = null; boolean scaleAboveWrapped = true; + boolean scaleLeftWrapped = true; + boolean scaleRightWrapped = true; // The following vector holds the features which are - // currently visible, in the correct order or rendering - Hashtable featuresDisplayed; + // currently visible, in the correct order or rendering + public Hashtable featuresDisplayed; boolean hasHiddenColumns = false; + boolean hasHiddenRows = false; + boolean showHiddenMarkers = true; + public Hashtable[] hconsensus; - public Vector vconsensus; AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + AlignmentAnnotation quality; + AlignmentAnnotation[] groupConsensus; + + AlignmentAnnotation[] groupConservation; + boolean autocalculateConsensus = true; public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! - private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this); + private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport( + this); boolean ignoreGapsInConsensusCalculation = false; - jalview.bin.JalviewLite applet; + public jalview.bin.JalviewLite applet; + + Hashtable sequenceColours; boolean MAC = false; + Stack historyList = new Stack(); + + Stack redoList = new Stack(); + + String sequenceSetID; + + Hashtable hiddenRepSequences; + + public void finalize() { + applet=null; + quality=null; + alignment=null; + colSel=null; + } + public AlignViewport(AlignmentI al, JalviewLite applet) { this.applet = applet; @@ -111,77 +161,165 @@ public class AlignViewport this.endRes = al.getWidth() - 1; this.startSeq = 0; this.endSeq = al.getHeight() - 1; - setFont(font); - - if(System.getProperty("os.name").startsWith("Mac")) - MAC = true; - if (applet != null) { - String param = applet.getParameter("showFullId"); + // get the width and height scaling factors if they were specified + String param = applet.getParameter("widthScale"); if (param != null) { - showJVSuffix = Boolean.valueOf(param).booleanValue(); + try + { + widthScale = new Float(param).floatValue(); + } catch (Exception e) + { + } + if (widthScale <= 1.0) + { + System.err + .println("Invalid alignment character width scaling factor (" + + widthScale + "). Ignoring."); + widthScale = 1; + } + if (applet.debug) + { + System.err + .println("Alignment character width scaling factor is now " + + widthScale); + } } - - param = applet.getParameter("showAnnotation"); + param = applet.getParameter("heightScale"); if (param != null) { - showAnnotation = Boolean.valueOf(param).booleanValue(); + try + { + heightScale = new Float(param).floatValue(); + } catch (Exception e) + { + } + if (heightScale <= 1.0) + { + System.err + .println("Invalid alignment character height scaling factor (" + + heightScale + "). Ignoring."); + heightScale = 1; + } + if (applet.debug) + { + System.err + .println("Alignment character height scaling factor is now " + + heightScale); + } } + } + setFont(font); - param = applet.getParameter("showConservation"); - if (param != null) - { - showConservation = Boolean.valueOf(param).booleanValue(); - } + MAC = new jalview.util.Platform().isAMac(); - param = applet.getParameter("showQuality"); - if (param != null) - { - showQuality = Boolean.valueOf(param).booleanValue(); - } + if (applet != null) + { + showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix); + + showAnnotation = applet.getDefaultParameter("showAnnotation", showAnnotation); + + showConservation = applet.getDefaultParameter("showConservation", showConservation); + + showQuality = applet.getDefaultParameter("showQuality", showQuality); + + showConsensus = applet.getDefaultParameter("showConsensus", showConsensus); + + showUnconserved = applet.getDefaultParameter("showUnconserved", showUnconserved); - param = applet.getParameter("showConsensus"); + String param = applet.getParameter("upperCase"); if (param != null) { - showConsensus = Boolean.valueOf(param).booleanValue(); + if (param.equalsIgnoreCase("bold")) + { + upperCasebold = true; + } } + sortByTree = applet.getDefaultParameter("sortByTree", sortByTree); + + followHighlight = applet.getDefaultParameter("automaticScrolling",followHighlight); + followSelection = followHighlight; + + showSequenceLogo = applet.getDefaultParameter("showSequenceLogo", showSequenceLogo); + + showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus); + + showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation); + + showConsensusHistogram = applet.getDefaultParameter("showConsensusHistogram", showConsensusHistogram); + } - // We must set conservation and consensus before setting colour, - // as Blosum and Clustal require this to be done - updateConservation(); - updateConsensus(); - if (applet != null) { String colour = applet.getParameter("defaultColour"); - if(colour == null) + if (colour == null) { colour = applet.getParameter("userDefinedColour"); - if(colour !=null) + if (colour != null) + { colour = "User Defined"; + } } - if(colour != null) + if (colour != null) { - globalColourScheme = ColourSchemeProperty.getColour(alignment, colour); + globalColourScheme = ColourSchemeProperty.getColour(alignment, + colour); if (globalColourScheme != null) { - globalColourScheme.setConsensus(vconsensus); + globalColourScheme.setConsensus(hconsensus); } } - if(applet.getParameter("userDefinedColour")!=null) + if (applet.getParameter("userDefinedColour") != null) + { + ((UserColourScheme) globalColourScheme).parseAppletParameter(applet + .getParameter("userDefinedColour")); + } + } + if (hconsensus == null) + { + if (!alignment.isNucleotide()) { - ((UserColourScheme)globalColourScheme).parseAppletParameter( - applet.getParameter("userDefinedColour")); + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment less than " + ConsPercGaps + + "% gaps", new Annotation[1], 0f, 11f, + AlignmentAnnotation.BAR_GRAPH); + conservation.hasText = true; + conservation.autoCalculated = true; + + if (showConservation) + { + alignment.addAnnotation(conservation); + } + + if (showQuality) + { + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); + quality.hasText = true; + quality.autoCalculated = true; + + alignment.addAnnotation(quality); + } } + consensus = new AlignmentAnnotation("Consensus", "PID", + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + consensus.hasText = true; + consensus.autoCalculated = true; + if (showConsensus) + { + alignment.addAnnotation(consensus); + } } + } public void showSequenceFeatures(boolean b) @@ -194,195 +332,320 @@ public class AlignViewport return showSequenceFeatures; } - - public void updateConservation() + class ConservationThread extends Thread { - if(alignment.isNucleotide()) - return; + AlignmentPanel ap; - Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, - alignment.getWidth() - 1); - cons.calculate(); - cons.verdict(false, ConsPercGaps); - cons.findQuality(); - int alWidth = alignment.getWidth(); - Annotation[] annotations = new Annotation[alWidth]; - Annotation[] qannotations = new Annotation[alWidth]; - String sequence = cons.getConsSequence().getSequence(); - float minR, minG, minB, maxR, maxG, 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 = cons.qualityRange[0].floatValue(); - float qmax = cons.qualityRange[1].floatValue(); - - for (int i = 0; i < alWidth; i++) + public ConservationThread(AlignmentPanel ap) + { + this.ap = ap; + } + + public void run() { - float value = 0; try { - value = Integer.parseInt(sequence.charAt(i) + ""); - } - catch (Exception ex) - { - if (sequence.charAt(i) == '*') + updatingConservation = true; + + while (UPDATING_CONSERVATION) { - value = 11; + try + { + if (ap != null) + { + ap.paintAlignment(false); + } + Thread.sleep(200); + } catch (Exception ex) + { + ex.printStackTrace(); + } } - if (sequence.charAt(i) == '+') + + UPDATING_CONSERVATION = true; + + int alWidth = (alignment==null) ? -1 : alignment.getWidth(); + if (alWidth < 0) { - value = 10; + updatingConservation = false; + UPDATING_CONSERVATION = false; + return; } - } - float vprop = value - min; - vprop /= max; - - annotations[i] = new Annotation(sequence.charAt(i) + "", - "", ' ', value, - new Color(minR + maxR * vprop, - minG + maxG * vprop, - minB + maxB * vprop)); - // Quality calc - value = ( (Double) cons.quality.elementAt(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() - AlignmentAnnotation.BAR_GRAPH); - if (showConservation) + 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; + } + // TODO - refactor to use a graduatedColorScheme to calculate the + // histogram colors. + 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.elementAt(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) { - alignment.addAnnotation(conservation); + System.out.println("Out of memory calculating conservation!!"); + conservation = null; + quality = null; + System.gc(); } - quality = new AlignmentAnnotation("Quality", - "Alignment Quality based on Blosum62 scores", - qannotations, - cons.qualityRange[0].floatValue(), - cons.qualityRange[1].floatValue(), - AlignmentAnnotation.BAR_GRAPH); - if (showQuality) + + UPDATING_CONSERVATION = false; + updatingConservation = false; + + if (ap != null) { - alignment.addAnnotation(quality); + ap.paintAlignment(true); } + } - else + } + + ConservationThread conservationThread; + + ConsensusThread consensusThread; + + boolean consUpdateNeeded = false; + + static boolean UPDATING_CONSENSUS = false; + + static boolean UPDATING_CONSERVATION = false; + + boolean updatingConsensus = false; + + boolean updatingConservation = false; + + /** + * DOCUMENT ME! + */ + public void updateConservation(final AlignmentPanel ap) + { + if (alignment.isNucleotide() || conservation == null) { - conservation.annotations = annotations; - quality.annotations = qannotations; - quality.graphMax = cons.qualityRange[1].floatValue(); + return; } + conservationThread = new ConservationThread(ap); + conservationThread.start(); + } + + /** + * DOCUMENT ME! + */ + public void updateConsensus(final AlignmentPanel ap) + { + consensusThread = new ConsensusThread(ap); + consensusThread.start(); } - public void updateConsensus() + class ConsensusThread extends Thread { - Annotation[] annotations = new Annotation[alignment.getWidth()]; + AlignmentPanel ap; - // this routine prevents vconsensus becoming a new object each time - // consenus is calculated. Important for speed of Blosum62 - // and PID colouring of alignment - if (vconsensus == null) + public ConsensusThread(AlignmentPanel ap) { - vconsensus = alignment.getAAFrequency(); + this.ap = ap; } - else + + public void run() { - Vector temp = alignment.getAAFrequency(); - vconsensus.removeAllElements(); - Enumeration e = temp.elements(); - while (e.hasMoreElements()) + updatingConsensus = true; + while (UPDATING_CONSENSUS) { - vconsensus.addElement(e.nextElement()); + try + { + if (ap != null) + { + ap.paintAlignment(false); + } + + Thread.sleep(200); + } catch (Exception ex) + { + ex.printStackTrace(); + } } - } - Hashtable hash = null; - for (int i = 0; i < alignment.getWidth(); 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(); - String maxRes = hash.get("maxResidue").toString(); - String mouseOver = hash.get("maxResidue") + " "; - if (maxRes.length() > 1) + UPDATING_CONSENSUS = true; + + try { - mouseOver = "[" + maxRes + "] "; - maxRes = "+"; - } + int aWidth = alignment==null ? -1 : alignment.getWidth(); + if (aWidth < 0) + { + UPDATING_CONSENSUS = false; + updatingConsensus = false; + return; + } + consensus.annotations = null; + consensus.annotations = new Annotation[aWidth]; + + hconsensus = new Hashtable[aWidth]; + AAFrequency.calculate(alignment.getSequencesArray(), 0, + alignment.getWidth(), hconsensus, true); // always calculate the + // full profile + updateAnnotation(true); + //AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth, + // ignoreGapsInConsensusCalculation, + // true); + + if (globalColourScheme != null) + { + globalColourScheme.setConsensus(hconsensus); + } - mouseOver += (int) value + "%"; - annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + } catch (OutOfMemoryError error) + { + alignment.deleteAnnotation(consensus); - } + consensus = null; + hconsensus = null; + System.out.println("Out of memory calculating consensus!!"); + System.gc(); + } + UPDATING_CONSENSUS = false; + updatingConsensus = false; - if (consensus == null) - { - consensus = new AlignmentAnnotation("Consensus", - "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH); - if (showConsensus) + if (ap != null) { - alignment.addAnnotation(consensus); + ap.paintAlignment(true); } } - else + + /** + * update the consensus annotation from the sequence profile data using + * current visualization settings. + */ + public void updateAnnotation() { - consensus.annotations = annotations; + updateAnnotation(false); } - if(globalColourScheme!=null) - globalColourScheme.setConsensus(vconsensus); - + protected void updateAnnotation(boolean immediate) + { + // TODO: make calls thread-safe, so if another thread calls this method, + // it will either return or wait until one calculation is finished. + if (immediate + || (!updatingConsensus && consensus != null && hconsensus != null)) + { + AAFrequency.completeConsensus(consensus, hconsensus, 0, + hconsensus.length, ignoreGapsInConsensusCalculation, + showSequenceLogo); + } + } } + /** - * get the consensus sequence as displayed under the PID consensus annotation row. - * @return consensus sequence as a new sequence object - */ - /** - * get the consensus sequence as displayed under the PID consensus annotation row. + * get the consensus sequence as displayed under the PID consensus annotation + * row. + * * @return consensus sequence as a new sequence object */ - public SequenceI getConsensusSeq() { - if (consensus==null) - updateConsensus(); - if (consensus==null) + public SequenceI getConsensusSeq() + { + if (consensus == null) + { + updateConsensus(null); + } + if (consensus == null) + { return null; - StringBuffer seqs=new StringBuffer(); - for (int i=0; i alignment.getWidth() - 1) { - // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1)); + // log.System.out.println(" Corrected res from " + res + " to maximum " + + // (alignment.getWidth()-1)); res = alignment.getWidth() - 1; } if (res < 0) @@ -481,18 +745,30 @@ public class AlignViewport } java.awt.Frame nullFrame; + + protected FeatureSettings featureSettings = null; + + private float heightScale = 1, widthScale = 1; + public void setFont(Font f) { font = f; - if(nullFrame == null) + if (nullFrame == null) { nullFrame = new java.awt.Frame(); nullFrame.addNotify(); } java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font); - setCharHeight(fm.getHeight()); - charWidth = fm.charWidth('M'); + setCharHeight((int) (heightScale * fm.getHeight())); + charWidth = (int) (widthScale * fm.charWidth('M')); + + if (upperCasebold) + { + Font f2 = new Font(f.getName(), Font.BOLD, f.getSize()); + fm = nullFrame.getGraphics().getFontMetrics(f2); + charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)); + } } public Font getFont() @@ -616,8 +892,10 @@ public class AlignViewport public void setHiddenColumns(ColumnSelection colsel) { this.colSel = colsel; - if(colSel.getHiddenColumns()!=null) + if (colSel.getHiddenColumns() != null) + { hasHiddenColumns = true; + } } public ColumnSelection getColumnSelection() @@ -703,59 +981,66 @@ public class AlignViewport public void setIgnoreGapsConsensus(boolean b) { ignoreGapsInConsensusCalculation = b; - updateConsensus(); - if (globalColourScheme!=null) + updateConsensus(null); + if (globalColourScheme != null) { globalColourScheme.setThreshold(globalColourScheme.getThreshold(), - ignoreGapsInConsensusCalculation); + ignoreGapsInConsensusCalculation); } } /** * Property change listener for changes in alignment - * - * @param listener DOCUMENT ME! + * + * @param listener + * DOCUMENT ME! */ public void addPropertyChangeListener( - java.beans.PropertyChangeListener listener) + java.beans.PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); + changeSupport.addPropertyChangeListener(listener); } /** * DOCUMENT ME! - * - * @param listener DOCUMENT ME! + * + * @param listener + * DOCUMENT ME! */ public void removePropertyChangeListener( - java.beans.PropertyChangeListener listener) + java.beans.PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); + changeSupport.removePropertyChangeListener(listener); } /** * Property change listener for changes in alignment - * - * @param prop DOCUMENT ME! - * @param oldvalue DOCUMENT ME! - * @param newvalue DOCUMENT ME! + * + * @param prop + * DOCUMENT ME! + * @param oldvalue + * DOCUMENT ME! + * @param newvalue + * DOCUMENT ME! */ - public void firePropertyChange(String prop, Object oldvalue, Object newvalue) + public void firePropertyChange(String prop, Object oldvalue, + Object newvalue) { - changeSupport.firePropertyChange(prop, oldvalue, newvalue); + changeSupport.firePropertyChange(prop, oldvalue, newvalue); } - - public boolean getIgnoreGapsConsensus() { return ignoreGapsInConsensusCalculation; } + public void hideSelectedColumns() { if (colSel.size() < 1) + { return; + } colSel.hideSelectedColumns(); setSelectionGroup(null); @@ -765,61 +1050,130 @@ public class AlignViewport public void invertColumnSelection() { - int column; for (int i = 0; i < alignment.getWidth(); i++) { - column = i; - - if (colSel.contains(column)) - colSel.removeElement(column); + if (colSel.contains(i)) + { + colSel.removeElement(i); + } else - colSel.addElement(column); - + { + if (!hasHiddenColumns || colSel.isVisible(i)) + { + colSel.addElement(i); + } + } } } - public void hideColumns(int start, int end) { - if(start==end) + if (start == end) + { colSel.hideColumns(start); + } else + { colSel.hideColumns(start, end); + } hasHiddenColumns = true; } - public void hideSequence(SequenceI seq) + public void hideRepSequences(SequenceI repSequence, SequenceGroup sg) { - if(seq!=null) + int sSize = sg.getSize(); + if (sSize < 2) { - alignment.getHiddenSequences().hideSequence(seq); - hasHiddenRows = true; - firePropertyChange("alignment", null, alignment.getSequences()); + return; } + + if (hiddenRepSequences == null) + { + hiddenRepSequences = new Hashtable(); + } + + hiddenRepSequences.put(repSequence, sg); + + // Hide all sequences except the repSequence + SequenceI[] seqs = new SequenceI[sSize - 1]; + int index = 0; + for (int i = 0; i < sSize; i++) + { + if (sg.getSequenceAt(i) != repSequence) + { + if (index == sSize - 1) + { + return; + } + + seqs[index++] = sg.getSequenceAt(i); + } + } + + hideSequence(seqs); + } public void hideAllSelectedSeqs() { - if (selectionGroup == null) + if (selectionGroup == null || selectionGroup.getSize() < 1) + { return; + } SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment); - for (int i = 0; i < seqs.length; i++) + hideSequence(seqs); + + setSelectionGroup(null); + } + + public void hideSequence(SequenceI[] seq) + { + if (seq != null) { - alignment.getHiddenSequences().hideSequence(seqs[i]); + for (int i = 0; i < seq.length; i++) + { + alignment.getHiddenSequences().hideSequence(seq[i]); + } + + hasHiddenRows = true; + firePropertyChange("alignment", null, alignment.getSequences()); } - firePropertyChange("alignment", null, alignment.getSequences()); - hasHiddenRows = true; - setSelectionGroup(null); } + public void showSequence(int index) + { + Vector tmp = alignment.getHiddenSequences().showSequence(index, + hiddenRepSequences); + 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()); + sendSelection(); + } + if (alignment.getHiddenSequences().getSize() < 1) + { + hasHiddenRows = false; + } + } public void showColumn(int col) { colSel.revealHiddenColumns(col); - if(colSel.getHiddenColumns()==null) + if (colSel.getHiddenColumns() == null) + { hasHiddenColumns = false; + } } public void showAllHiddenColumns() @@ -830,33 +1184,36 @@ public class AlignViewport public void showAllHiddenSeqs() { - if(alignment.getHiddenSequences().getSize()>0) + if (alignment.getHiddenSequences().getSize() > 0) { - if(selectionGroup==null) + if (selectionGroup == null) { selectionGroup = new SequenceGroup(); - selectionGroup.setEndRes(alignment.getWidth()-1); + selectionGroup.setEndRes(alignment.getWidth() - 1); } - Vector tmp = alignment.getHiddenSequences().showAll(); - for(int t=0; t