From 92a3a0f396a86b2bc0a8d1a311680ceda4abec7b Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 8 Jun 2005 16:22:17 +0000 Subject: [PATCH] Recalc accelerated --- src/jalview/datamodel/SequenceGroup.java | 493 +++++++++++++++++------------- src/jalview/gui/AlignFrame.java | 4 +- src/jalview/gui/IdCanvas.java | 5 +- src/jalview/gui/Jalview2XML.java | 19 +- src/jalview/gui/RotatableCanvas.java | 6 +- src/jalview/gui/ScalePanel.java | 2 +- src/jalview/gui/SeqPanel.java | 15 +- src/jalview/gui/TreeCanvas.java | 20 +- 8 files changed, 314 insertions(+), 250 deletions(-) diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 0ae9ec2..a855f6f 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1,21 +1,21 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 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 + * Copyright (C) 2005 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 + */ package jalview.datamodel; import jalview.analysis.*; @@ -28,244 +28,305 @@ import java.awt.*; import java.util.Vector; - -public class SequenceGroup { - String groupName; - Conservation conserve; - Vector aaFrequency; - boolean displayBoxes; - boolean displayText; - boolean colourText; - public Vector sequences = new Vector(); - int width = -1; - public ColourSchemeI cs; - int startRes = 0; - int endRes = 0; - Color outlineColour = Color.black; - - public SequenceGroup() { - groupName = "Group"; - this.displayBoxes = true; - this.displayText = true; - this.colourText = false; - cs = null; - } - - public SequenceGroup(String groupName, ColourSchemeI scheme, - boolean displayBoxes, boolean displayText, boolean colourText, - int start, int end) { - this.groupName = groupName; - this.displayBoxes = displayBoxes; - this.displayText = displayText; - this.colourText = colourText; - this.cs = scheme; - startRes = start; - endRes = end; - } - - public boolean adjustForRemoveLeft(int col) { - // return value is true if the group still exists - if (startRes >= col) { - startRes = startRes - col; - } - - if (endRes >= col) { - endRes = endRes - col; - - if (startRes > endRes) { - startRes = 0; - } - } else { - // must delete this group!! - return false; - } - - return true; +public class SequenceGroup +{ + String groupName; + Conservation conserve; + Vector aaFrequency; + boolean displayBoxes; + boolean displayText; + boolean colourText; + public Vector sequences = new Vector(); + int width = -1; + public ColourSchemeI cs; + int startRes = 0; + int endRes = 0; + Color outlineColour = Color.black; + + public SequenceGroup() + { + groupName = "Group"; + this.displayBoxes = true; + this.displayText = true; + this.colourText = false; + cs = null; + } + + public SequenceGroup(Vector sequences, String groupName, ColourSchemeI scheme, + boolean displayBoxes, boolean displayText, + boolean colourText, + int start, int end) + { + this.sequences = sequences; + this.groupName = groupName; + this.displayBoxes = displayBoxes; + this.displayText = displayText; + this.colourText = colourText; + this.cs = scheme; + startRes = start; + endRes = end; + } + + public SequenceGroup(String groupName, ColourSchemeI scheme, + boolean displayBoxes, boolean displayText, + boolean colourText, + int start, int end) + { + this.groupName = groupName; + this.displayBoxes = displayBoxes; + this.displayText = displayText; + this.colourText = colourText; + this.cs = scheme; + startRes = start; + endRes = end; + } + + public boolean adjustForRemoveLeft(int col) + { + // return value is true if the group still exists + if (startRes >= col) + { + startRes = startRes - col; } - public boolean adjustForRemoveRight(int col) { - if (startRes > col) { - // delete this group - return false; - } - - if (endRes >= col) { - endRes = col; - } + if (endRes >= col) + { + endRes = endRes - col; - return true; + if (startRes > endRes) + { + startRes = 0; + } } - - public String getName() { - return groupName; + else + { + // must delete this group!! + return false; } - public void setName(String name) { - groupName = name; - } + return true; + } - public Conservation getConservation() { - return conserve; + public boolean adjustForRemoveRight(int col) + { + if (startRes > col) + { + // delete this group + return false; } - public void setConservation(Conservation c) { - conserve = c; + if (endRes >= col) + { + endRes = col; } - public void addSequence(SequenceI s) { - if (!sequences.contains(s)) { - sequences.addElement(s); - } - - if (cs != null) { - cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); - } + return true; + } - if (cs instanceof ConservationColourScheme) { - recalcConservation(); - } - } + public String getName() + { + return groupName; + } - void recalcConservation() { - Conservation c = new Conservation(groupName, - ResidueProperties.propHash, 3, sequences, 0, getWidth()); - c.calculate(); - c.verdict(false, 25); + public void setName(String name) + { + groupName = name; + } - ConservationColourScheme ccs = (ConservationColourScheme) cs; - ccs.conserve = c; - } + public Conservation getConservation() + { + return conserve; + } - public void addOrRemove(SequenceI s) { - if (sequences.contains(s)) { - deleteSequence(s); - } else { - addSequence(s); - } - } + public void setConservation(Conservation c) + { + conserve = c; + } - public void deleteSequence(SequenceI s) { - sequences.removeElement(s); + public void addSequence(SequenceI s, boolean recalc) + { + if (!sequences.contains(s)) + sequences.addElement(s); - if (cs != null) { - cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); - } + if(recalc) + recalcConservation(); + } - if (cs instanceof ConservationColourScheme) { - recalcConservation(); - } - } - public int getStartRes() { - return startRes; + public void recalcConservation() + { + if (cs != null) + { + cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); } - public int getEndRes() { - return endRes; - } + if ( cs instanceof ConservationColourScheme) + { + Conservation c = new Conservation(groupName, + ResidueProperties.propHash, 3, sequences, + 0, getWidth()); + c.calculate(); + c.verdict(false, 25); - public void setStartRes(int i) { - startRes = i; + ConservationColourScheme ccs = (ConservationColourScheme) cs; + ccs.conserve = c; } + } - public void setEndRes(int i) { - endRes = i; + public void addOrRemove(SequenceI s, boolean recalc) + { + if (sequences.contains(s)) + { + deleteSequence(s, recalc); } - - public int getSize() { - return sequences.size(); + else + { + addSequence(s, recalc); } - - public SequenceI getSequenceAt(int i) { - return (SequenceI) sequences.elementAt(i); + } + + public void deleteSequence(SequenceI s, boolean recalc) + { + sequences.removeElement(s); + if(recalc) + recalcConservation(); + } + + public int getStartRes() + { + return startRes; + } + + public int getEndRes() + { + return endRes; + } + + public void setStartRes(int i) + { + startRes = i; + } + + public void setEndRes(int i) + { + endRes = i; + } + + public int getSize() + { + return sequences.size(); + } + + public SequenceI getSequenceAt(int i) + { + return (SequenceI) sequences.elementAt(i); + } + + public void setColourText(boolean state) + { + colourText = state; + } + + public boolean getColourText() + { + return colourText; + } + + public void setDisplayText(boolean state) + { + displayText = state; + } + + public boolean getDisplayText() + { + return displayText; + } + + public void setDisplayBoxes(boolean state) + { + displayBoxes = state; + } + + public boolean getDisplayBoxes() + { + return displayBoxes; + } + + public int getWidth() + { + // MC This needs to get reset when characters are inserted and deleted + if (sequences.size() > 0) + { + width = ( (SequenceI) sequences.elementAt(0)).getLength(); } - public void setColourText(boolean state) { - colourText = state; - } + for (int i = 1; i < sequences.size(); i++) + { + SequenceI seq = (SequenceI) sequences.elementAt(i); - public boolean getColourText() { - return colourText; + if (seq.getLength() > width) + { + width = seq.getLength(); + } } - public void setDisplayText(boolean state) { - displayText = state; + return width; + } + + public void setOutlineColour(Color c) + { + outlineColour = c; + } + + public Color getOutlineColour() + { + return outlineColour; + } + + /** + * + * returns the sequences in the group ordered by the ordering given by al + * + * @param al Alignment + * @return SequenceI[] + */ + public SequenceI[] getSequencesInOrder(Alignment al) + { + int sz; + java.util.Hashtable orderedSeqs = new java.util.Hashtable(); + SequenceI[] seqs = new SequenceI[sz = sequences.size()]; + + for (int i = 0; i < sz; i++) + { + SequenceI seq = (SequenceI) sequences.elementAt(i); + int index = al.findIndex(seq); + orderedSeqs.put(index + "", seq); } - public boolean getDisplayText() { - return displayText; - } + int index = 0; - public void setDisplayBoxes(boolean state) { - displayBoxes = state; - } + for (int i = 0; i < sz; i++) + { + SequenceI seq = null; - public boolean getDisplayBoxes() { - return displayBoxes; - } + while (seq == null) + { + if (orderedSeqs.containsKey(index + "")) + { + seq = (SequenceI) orderedSeqs.get(index + ""); + index++; - public int getWidth() { - // MC This needs to get reset when characters are inserted and deleted - if (sequences.size() > 0) { - width = ((SequenceI) sequences.elementAt(0)).getLength(); + break; } - - for (int i = 1; i < sequences.size(); i++) { - SequenceI seq = (SequenceI) sequences.elementAt(i); - - if (seq.getLength() > width) { - width = seq.getLength(); - } + else + { + index++; } + } - return width; - } - - public void setOutlineColour(Color c) { - outlineColour = c; - } - - public Color getOutlineColour() { - return outlineColour; + seqs[index] = seq; } - /** - * - * returns the sequences in the group ordered by the ordering given by al - * - * @param al Alignment - * @return SequenceI[] - */ - public SequenceI[] getSequencesInOrder(Alignment al) { - int sz; - java.util.Hashtable orderedSeqs = new java.util.Hashtable(); - SequenceI[] seqs = new SequenceI[sz = sequences.size()]; - - for (int i = 0; i < sz; i++) { - SequenceI seq = (SequenceI) sequences.elementAt(i); - int index = al.findIndex(seq); - orderedSeqs.put(index + "", seq); - } - - int index = 0; - - for (int i = 0; i < sz; i++) { - SequenceI seq = null; - - while (seq == null) { - if (orderedSeqs.containsKey(index + "")) { - seq = (SequenceI) orderedSeqs.get(index + ""); - index++; - - break; - } else { - index++; - } - } - - seqs[index] = seq; - } - - return seqs; - } + return seqs; + } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9bc4bc0..5c31931 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -558,7 +558,7 @@ public class AlignFrame for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) { - sg.addSequence(viewport.getAlignment().getSequenceAt(i)); + sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); } sg.setEndRes(viewport.alignment.getWidth()); @@ -581,7 +581,7 @@ public class AlignFrame for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) { - sg.addOrRemove(viewport.getAlignment().getSequenceAt(i)); + sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false); } PaintRefresher.Refresh(null); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index e30be30..c14da85 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -93,7 +93,6 @@ public class IdCanvas if (gg == null) { repaint(); - return; } @@ -178,6 +177,10 @@ public class IdCanvas void drawIds(int starty, int endy) { + if(gg==null) + return; + + Color currentColor = Color.white; Color currentTextColor = Color.black; diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index b8977c5..51bf824 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -580,21 +580,24 @@ public class Jalview2XML } } + Vector seqs = new Vector(); + int[] ids = groups[i].getSeq(); + + for (int s = 0; s < ids.length; s++) + { + seqs.addElement( (jalview.datamodel.SequenceI) seqids.elementAt( + ids[s])); + } + jalview.datamodel.SequenceGroup sg = new jalview.datamodel. - SequenceGroup(groups[i].getName(), + SequenceGroup(seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(), groups[i].getDisplayText(), groups[i].getColourText(), groups[i].getStart(), groups[i].getEnd()); + sg.setOutlineColour(new java.awt.Color( groups[i].getOutlineColour())); - int[] ids = groups[i].getSeq(); - - for (int s = 0; s < ids.length; s++) - { - sg.addSequence( (jalview.datamodel.SequenceI) seqids.elementAt( - ids[s])); - } if (groups[i].getConsThreshold() != 0) { diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 0fc83c3..c89cd59 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -474,13 +474,13 @@ public class RotatableCanvas { if (av.getSelectionGroup() != null) { - av.getSelectionGroup().addOrRemove(found); + av.getSelectionGroup().addOrRemove(found, true); PaintRefresher.Refresh(this); } else { av.setSelectionGroup(new SequenceGroup()); - av.getSelectionGroup().addOrRemove(found); + av.getSelectionGroup().addOrRemove(found, true); av.getSelectionGroup().setEndRes(av.alignment.getWidth()); } } @@ -570,7 +570,7 @@ public class RotatableCanvas if (!av.getSelectionGroup().sequences.contains(sp.sequence)) { changedSel = true; - av.getSelectionGroup().addSequence(sp.sequence); + av.getSelectionGroup().addSequence(sp.sequence, true); } } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 250998f..551f262 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -77,7 +77,7 @@ public class ScalePanel for (int i = 0; i < av.alignment.getSequences().size(); i++) { - sg.addSequence(av.alignment.getSequenceAt(i)); + sg.addSequence(av.alignment.getSequenceAt(i), false); } sg.setStartRes(res); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index f4d77c3..52d137b 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -570,7 +570,7 @@ public class SeqPanel SequenceGroup sg = new SequenceGroup(); sg.setStartRes(res); sg.setEndRes(res); - sg.addSequence(sequence); + sg.addSequence(sequence, false); av.setSelectionGroup(sg); stretchGroup = sg; @@ -620,11 +620,12 @@ public class SeqPanel return; } + stretchGroup.recalcConservation(); + if (stretchGroup.cs instanceof ClustalxColourScheme) { stretchGroup.cs = new ClustalxColourScheme(stretchGroup.sequences, av.alignment.getWidth()); - repaint(); } else if (stretchGroup.cs instanceof ConservationColourScheme) { @@ -633,7 +634,6 @@ public class SeqPanel SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()); - repaint(); } else { @@ -644,6 +644,7 @@ public class SeqPanel changeEndRes = false; changeStartRes = false; stretchGroup = null; + repaint(); ap.idPanel.repaint(); } @@ -720,17 +721,17 @@ public class SeqPanel if (stretchGroup.sequences.contains(nextSeq)) { - stretchGroup.deleteSequence(seq); - stretchGroup.deleteSequence(nextSeq); + stretchGroup.deleteSequence(seq, false); + stretchGroup.deleteSequence(nextSeq, false); } else { if (seq != null) { - stretchGroup.addSequence(seq); + stretchGroup.addSequence(seq, false); } - stretchGroup.addSequence(nextSeq); + stretchGroup.addSequence(nextSeq, false); } } diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 12416ae..0f74faf 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -79,7 +79,7 @@ public class TreeCanvas } selected.setEndRes(av.alignment.getWidth()); - selected.addOrRemove(sequence); + selected.addOrRemove(sequence, true); PaintRefresher.Refresh(this); repaint(); @@ -299,7 +299,7 @@ public class TreeCanvas if (sg != null) { - sg.addOrRemove(seq); + sg.addOrRemove(seq, true); } } } @@ -561,21 +561,17 @@ public class TreeCanvas Vector l = tree.findLeaves( (SequenceNode) tree.getGroups() .elementAt(i), new Vector()); - SequenceGroup sg = null; + Vector sequences = new Vector(); for (int j = 0; j < l.size(); j++) { - SequenceNode sn = (SequenceNode) l.elementAt(j); + sequences.add( (Sequence)((SequenceNode) l.elementAt(j)).element()); + } - if (sg == null) - { - sg = new SequenceGroup("TreeGroup", - av.getGlobalColourScheme(), true, true, - false, 0, av.alignment.getWidth()); - } + SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup", + av.getGlobalColourScheme(), true, true, + false, 0, av.alignment.getWidth()); - sg.addSequence( (Sequence) sn.element()); - } if (av.getGlobalColourScheme() instanceof ConservationColourScheme) { -- 1.7.10.2