X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=6de42b9d23e704384ecc0af78a279b1bab9765a7;hb=cb8ec179c020265666678572815ab056a024da22;hp=0ae9ec2bb1e2702d88b639ecba6615c142b66740;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 0ae9ec2..6de42b9 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1,49 +1,62 @@ /* -* 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.*; -import jalview.datamodel.*; - import jalview.schemes.*; import java.awt.*; -import java.util.Vector; +import java.util.*; -public class SequenceGroup { +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class SequenceGroup +{ 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; - public SequenceGroup() { + /** + * Creates a new SequenceGroup object. + */ + public SequenceGroup() + { groupName = "Group"; this.displayBoxes = true; this.displayText = true; @@ -51,9 +64,48 @@ public class SequenceGroup { cs = null; } + /** + * 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) + { + this.sequences = sequences; + this.groupName = groupName; + this.displayBoxes = displayBoxes; + this.displayText = displayText; + this.colourText = colourText; + this.cs = scheme; + startRes = start; + endRes = end; + recalcConservation(); + } + + /** + * 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) { + int start, int end) + { this.groupName = groupName; this.displayBoxes = displayBoxes; this.displayText = displayText; @@ -63,19 +115,32 @@ public class SequenceGroup { endRes = end; } - public boolean adjustForRemoveLeft(int col) { + /** + * 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) { + if (startRes >= col) + { startRes = startRes - col; } - if (endRes >= col) { + if (endRes >= col) + { endRes = endRes - col; - if (startRes > endRes) { + if (startRes > endRes) + { startRes = 0; } - } else { + } + else + { // must delete this group!! return false; } @@ -83,137 +148,298 @@ public class SequenceGroup { return true; } - public boolean adjustForRemoveRight(int col) { - if (startRes > col) { + /** + * 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) { + if (endRes >= col) + { endRes = col; } return true; } - public String getName() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String getName() + { return groupName; } - public void setName(String name) { + /** + * DOCUMENT ME! + * + * @param name DOCUMENT ME! + */ + public void setName(String name) + { groupName = name; } - public Conservation getConservation() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Conservation getConservation() + { return conserve; } - public void setConservation(Conservation c) { + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + */ + public void setConservation(Conservation c) + { conserve = c; } - public void addSequence(SequenceI s) { - if (!sequences.contains(s)) { + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param recalc DOCUMENT ME! + */ + 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 (cs instanceof ConservationColourScheme) { + if (recalc) + { recalcConservation(); } } - void recalcConservation() { - Conservation c = new Conservation(groupName, - ResidueProperties.propHash, 3, sequences, 0, getWidth()); - c.calculate(); - c.verdict(false, 25); + /** + * DOCUMENT ME! + */ + public void recalcConservation() + { + if(cs == null) + return; + + cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); + + + if (cs instanceof ClustalxColourScheme) + { + ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth()); + } + + + if (cs.conservationApplied()) + { + Conservation c = new Conservation(groupName, + ResidueProperties.propHash, 3, sequences, 0, getWidth()); + c.calculate(); + c.verdict(false, 25); + - ConservationColourScheme ccs = (ConservationColourScheme) cs; - ccs.conserve = c; + cs.setConservation(c); + + if (cs instanceof ClustalxColourScheme) + { + ((ClustalxColourScheme) cs).resetClustalX(sequences, + getWidth()); + } + } } - public void addOrRemove(SequenceI s) { - if (sequences.contains(s)) { - deleteSequence(s); - } else { - addSequence(s); + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param recalc DOCUMENT ME! + */ + public void addOrRemove(SequenceI s, boolean recalc) + { + if (sequences.contains(s)) + { + deleteSequence(s, recalc); + } + else + { + addSequence(s, recalc); } } - public void deleteSequence(SequenceI s) { + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param recalc DOCUMENT ME! + */ + public void deleteSequence(SequenceI s, boolean recalc) + { sequences.removeElement(s); - if (cs != null) { - cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); - } - - if (cs instanceof ConservationColourScheme) { + if (recalc) + { recalcConservation(); } } - public int getStartRes() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getStartRes() + { return startRes; } - public int getEndRes() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getEndRes() + { return endRes; } - public void setStartRes(int i) { + /** + * DOCUMENT ME! + * + * @param i DOCUMENT ME! + */ + public void setStartRes(int i) + { startRes = i; } - public void setEndRes(int i) { + /** + * DOCUMENT ME! + * + * @param i DOCUMENT ME! + */ + public void setEndRes(int i) + { endRes = i; } - public int getSize() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getSize() + { return sequences.size(); } - public SequenceI getSequenceAt(int i) { + /** + * DOCUMENT ME! + * + * @param i DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public SequenceI getSequenceAt(int i) + { return (SequenceI) sequences.elementAt(i); } - public void setColourText(boolean state) { + /** + * DOCUMENT ME! + * + * @param state DOCUMENT ME! + */ + public void setColourText(boolean state) + { colourText = state; } - public boolean getColourText() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean getColourText() + { return colourText; } - public void setDisplayText(boolean state) { + /** + * DOCUMENT ME! + * + * @param state DOCUMENT ME! + */ + public void setDisplayText(boolean state) + { displayText = state; } - public boolean getDisplayText() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean getDisplayText() + { return displayText; } - public void setDisplayBoxes(boolean state) { + /** + * DOCUMENT ME! + * + * @param state DOCUMENT ME! + */ + public void setDisplayBoxes(boolean state) + { displayBoxes = state; } - public boolean getDisplayBoxes() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean getDisplayBoxes() + { return displayBoxes; } - public int getWidth() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getWidth() + { // MC This needs to get reset when characters are inserted and deleted - if (sequences.size() > 0) { + if (sequences.size() > 0) + { width = ((SequenceI) sequences.elementAt(0)).getLength(); } - for (int i = 1; i < sequences.size(); i++) { + for (int i = 1; i < sequences.size(); i++) + { SequenceI seq = (SequenceI) sequences.elementAt(i); - if (seq.getLength() > width) { + if (seq.getLength() > width) + { width = seq.getLength(); } } @@ -221,11 +447,23 @@ public class SequenceGroup { return width; } - public void setOutlineColour(Color c) { + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + */ + public void setOutlineColour(Color c) + { outlineColour = c; } - public Color getOutlineColour() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color getOutlineColour() + { return outlineColour; } @@ -236,12 +474,14 @@ public class SequenceGroup { * @param al Alignment * @return SequenceI[] */ - public SequenceI[] getSequencesInOrder(Alignment al) { - int sz; + public SequenceI[] getSequencesInOrder(AlignmentI al) + { + int sz = sequences.size(); java.util.Hashtable orderedSeqs = new java.util.Hashtable(); - SequenceI[] seqs = new SequenceI[sz = sequences.size()]; + SequenceI[] seqs = new SequenceI[sz]; - for (int i = 0; i < sz; i++) { + for (int i = 0; i < sz; i++) + { SequenceI seq = (SequenceI) sequences.elementAt(i); int index = al.findIndex(seq); orderedSeqs.put(index + "", seq); @@ -249,21 +489,12 @@ public class SequenceGroup { 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++; - } + for (int i = 0; i < al.getHeight(); i++) + { + if (orderedSeqs.containsKey(i + "")) + { + seqs[index++] = (SequenceI) orderedSeqs.get(i + ""); } - - seqs[index] = seq; } return seqs;