X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=6de42b9d23e704384ecc0af78a279b1bab9765a7;hb=8a18973f7e4521c7dd3705ebd8fabd3ca08cfcaf;hp=d6ea5dd8131d8ee996d840ac693ac74b44eb6f31;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index d6ea5dd..6de42b9 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1,287 +1,502 @@ /* -* 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.schemes.*; import jalview.analysis.*; -import jalview.datamodel.*; -import java.util.Vector; + +import jalview.schemes.*; + import java.awt.*; +import java.util.*; + + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ 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) + String groupName; + Conservation conserve; + Vector aaFrequency; + boolean displayBoxes; + boolean displayText; + boolean colourText; + + /** DOCUMENT ME!! */ + public Vector sequences = new Vector(); + int width = -1; + + /** DOCUMENT ME!! */ + public ColourSchemeI cs; + int startRes = 0; + int endRes = 0; + Color outlineColour = Color.black; + + /** + * Creates a new SequenceGroup object. + */ + public SequenceGroup() { - endRes = endRes - col; - if(startRes>endRes) - startRes = 0; + groupName = "Group"; + this.displayBoxes = true; + this.displayText = true; + this.colourText = false; + cs = null; } - else + + /** + * Creates a new SequenceGroup object. + * + * @param sequences DOCUMENT ME! + * @param groupName DOCUMENT ME! + * @param scheme DOCUMENT ME! + * @param displayBoxes DOCUMENT ME! + * @param displayText DOCUMENT ME! + * @param colourText DOCUMENT ME! + * @param start DOCUMENT ME! + * @param end DOCUMENT ME! + */ + public SequenceGroup(Vector sequences, String groupName, + ColourSchemeI scheme, boolean displayBoxes, boolean displayText, + boolean colourText, int start, int end) { - // must delete this group!! - return false; + this.sequences = sequences; + this.groupName = groupName; + this.displayBoxes = displayBoxes; + this.displayText = displayText; + this.colourText = colourText; + this.cs = scheme; + startRes = start; + endRes = end; + recalcConservation(); } - return true; - } + /** + * Creates a new SequenceGroup object. + * + * @param groupName DOCUMENT ME! + * @param scheme DOCUMENT ME! + * @param displayBoxes DOCUMENT ME! + * @param displayText DOCUMENT ME! + * @param colourText DOCUMENT ME! + * @param start DOCUMENT ME! + * @param end DOCUMENT ME! + */ + 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; + } + + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + 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 (endRes >= col) + { + endRes = endRes - col; - if(startRes>col) + if (startRes > endRes) + { + startRes = 0; + } + } + else + { + // must delete this group!! + return false; + } + + return true; + } + + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean adjustForRemoveRight(int col) + { + if (startRes > col) + { + // delete this group + return false; + } + + if (endRes >= col) + { + endRes = col; + } + + return true; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String getName() { - // delete this group - return false; + return groupName; } - if(endRes>=col) - endRes = col; - - return true; - } - - - public String getName() - { - return groupName; - } - - public void setName(String name) - { - groupName = name; - } - - public Conservation getConservation() - { - return conserve; - } - - public void setConservation(Conservation c) - { - conserve = c; - } - - public void addSequence(SequenceI s) - { - if(!sequences.contains(s)) - sequences.addElement(s); - - - if(cs!=null) - cs.setConsensus( AAFrequency.calculate(sequences, 0, getWidth()) ); - - if(cs instanceof ConservationColourScheme) - recalcConservation(); - } - - void recalcConservation() - { - Conservation c = new Conservation(groupName, - ResidueProperties.propHash, 3, - sequences, 0, getWidth()); - c.calculate(); - c.verdict(false, 25); - ConservationColourScheme ccs = (ConservationColourScheme)cs; - ccs.conserve = c; - } - - public void addOrRemove(SequenceI s) - { - if(sequences.contains(s)) - deleteSequence(s); - else - addSequence(s); - } - - public void deleteSequence(SequenceI s) - { - sequences.removeElement(s); - - if(cs!=null) - cs.setConsensus( AAFrequency.calculate(sequences, 0, getWidth()) ); - - if(cs instanceof ConservationColourScheme) - 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(); - for (int i = 1; i < sequences.size(); i++) + /** + * DOCUMENT ME! + * + * @param name DOCUMENT ME! + */ + public void setName(String name) { - SequenceI seq = (SequenceI) sequences.elementAt(i); - if (seq.getLength() > width) - width = seq.getLength(); + groupName = name; } - 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 0) + { + width = ((SequenceI) sequences.elementAt(0)).getLength(); + } + + for (int i = 1; i < sequences.size(); i++) + { + SequenceI seq = (SequenceI) sequences.elementAt(i); + + if (seq.getLength() > width) + { + width = seq.getLength(); + } + } + + return width; + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + */ + public void setOutlineColour(Color c) + { + outlineColour = c; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + 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(AlignmentI al) + { + int sz = sequences.size(); + java.util.Hashtable orderedSeqs = new java.util.Hashtable(); + SequenceI[] seqs = new SequenceI[sz]; + + 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 < al.getHeight(); i++) + { + if (orderedSeqs.containsKey(i + "")) + { + seqs[index++] = (SequenceI) orderedSeqs.get(i + ""); + } + } + + return seqs; } - return seqs; - } }