/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.datamodel;\r
\r
import jalview.analysis.*;\r
\r
import java.util.Vector;\r
\r
-\r
-public class SequenceGroup {\r
- String groupName;\r
- Conservation conserve;\r
- Vector aaFrequency;\r
- boolean displayBoxes;\r
- boolean displayText;\r
- boolean colourText;\r
- public Vector sequences = new Vector();\r
- int width = -1;\r
- public ColourSchemeI cs;\r
- int startRes = 0;\r
- int endRes = 0;\r
- Color outlineColour = Color.black;\r
-\r
- public SequenceGroup() {\r
- groupName = "Group";\r
- this.displayBoxes = true;\r
- this.displayText = true;\r
- this.colourText = false;\r
- cs = null;\r
- }\r
-\r
- public SequenceGroup(String groupName, ColourSchemeI scheme,\r
- boolean displayBoxes, boolean displayText, boolean colourText,\r
- int start, int end) {\r
- this.groupName = groupName;\r
- this.displayBoxes = displayBoxes;\r
- this.displayText = displayText;\r
- this.colourText = colourText;\r
- this.cs = scheme;\r
- startRes = start;\r
- endRes = end;\r
- }\r
-\r
- public boolean adjustForRemoveLeft(int col) {\r
- // return value is true if the group still exists\r
- if (startRes >= col) {\r
- startRes = startRes - col;\r
- }\r
-\r
- if (endRes >= col) {\r
- endRes = endRes - col;\r
-\r
- if (startRes > endRes) {\r
- startRes = 0;\r
- }\r
- } else {\r
- // must delete this group!!\r
- return false;\r
- }\r
-\r
- return true;\r
+public class SequenceGroup\r
+{\r
+ String groupName;\r
+ Conservation conserve;\r
+ Vector aaFrequency;\r
+ boolean displayBoxes;\r
+ boolean displayText;\r
+ boolean colourText;\r
+ public Vector sequences = new Vector();\r
+ int width = -1;\r
+ public ColourSchemeI cs;\r
+ int startRes = 0;\r
+ int endRes = 0;\r
+ Color outlineColour = Color.black;\r
+\r
+ public SequenceGroup()\r
+ {\r
+ groupName = "Group";\r
+ this.displayBoxes = true;\r
+ this.displayText = true;\r
+ this.colourText = false;\r
+ cs = null;\r
+ }\r
+\r
+ public SequenceGroup(Vector sequences, String groupName, ColourSchemeI scheme,\r
+ boolean displayBoxes, boolean displayText,\r
+ boolean colourText,\r
+ int start, int end)\r
+ {\r
+ this.sequences = sequences;\r
+ this.groupName = groupName;\r
+ this.displayBoxes = displayBoxes;\r
+ this.displayText = displayText;\r
+ this.colourText = colourText;\r
+ this.cs = scheme;\r
+ startRes = start;\r
+ endRes = end;\r
+ }\r
+\r
+ public SequenceGroup(String groupName, ColourSchemeI scheme,\r
+ boolean displayBoxes, boolean displayText,\r
+ boolean colourText,\r
+ int start, int end)\r
+ {\r
+ this.groupName = groupName;\r
+ this.displayBoxes = displayBoxes;\r
+ this.displayText = displayText;\r
+ this.colourText = colourText;\r
+ this.cs = scheme;\r
+ startRes = start;\r
+ endRes = end;\r
+ }\r
+\r
+ public boolean adjustForRemoveLeft(int col)\r
+ {\r
+ // return value is true if the group still exists\r
+ if (startRes >= col)\r
+ {\r
+ startRes = startRes - col;\r
}\r
\r
- public boolean adjustForRemoveRight(int col) {\r
- if (startRes > col) {\r
- // delete this group\r
- return false;\r
- }\r
-\r
- if (endRes >= col) {\r
- endRes = col;\r
- }\r
+ if (endRes >= col)\r
+ {\r
+ endRes = endRes - col;\r
\r
- return true;\r
+ if (startRes > endRes)\r
+ {\r
+ startRes = 0;\r
+ }\r
}\r
-\r
- public String getName() {\r
- return groupName;\r
+ else\r
+ {\r
+ // must delete this group!!\r
+ return false;\r
}\r
\r
- public void setName(String name) {\r
- groupName = name;\r
- }\r
+ return true;\r
+ }\r
\r
- public Conservation getConservation() {\r
- return conserve;\r
+ public boolean adjustForRemoveRight(int col)\r
+ {\r
+ if (startRes > col)\r
+ {\r
+ // delete this group\r
+ return false;\r
}\r
\r
- public void setConservation(Conservation c) {\r
- conserve = c;\r
+ if (endRes >= col)\r
+ {\r
+ endRes = col;\r
}\r
\r
- public void addSequence(SequenceI s) {\r
- if (!sequences.contains(s)) {\r
- sequences.addElement(s);\r
- }\r
-\r
- if (cs != null) {\r
- cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));\r
- }\r
+ return true;\r
+ }\r
\r
- if (cs instanceof ConservationColourScheme) {\r
- recalcConservation();\r
- }\r
- }\r
+ public String getName()\r
+ {\r
+ return groupName;\r
+ }\r
\r
- void recalcConservation() {\r
- Conservation c = new Conservation(groupName,\r
- ResidueProperties.propHash, 3, sequences, 0, getWidth());\r
- c.calculate();\r
- c.verdict(false, 25);\r
+ public void setName(String name)\r
+ {\r
+ groupName = name;\r
+ }\r
\r
- ConservationColourScheme ccs = (ConservationColourScheme) cs;\r
- ccs.conserve = c;\r
- }\r
+ public Conservation getConservation()\r
+ {\r
+ return conserve;\r
+ }\r
\r
- public void addOrRemove(SequenceI s) {\r
- if (sequences.contains(s)) {\r
- deleteSequence(s);\r
- } else {\r
- addSequence(s);\r
- }\r
- }\r
+ public void setConservation(Conservation c)\r
+ {\r
+ conserve = c;\r
+ }\r
\r
- public void deleteSequence(SequenceI s) {\r
- sequences.removeElement(s);\r
+ public void addSequence(SequenceI s, boolean recalc)\r
+ {\r
+ if (!sequences.contains(s))\r
+ sequences.addElement(s);\r
\r
- if (cs != null) {\r
- cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));\r
- }\r
+ if(recalc)\r
+ recalcConservation();\r
+ }\r
\r
- if (cs instanceof ConservationColourScheme) {\r
- recalcConservation();\r
- }\r
- }\r
\r
- public int getStartRes() {\r
- return startRes;\r
+ public void recalcConservation()\r
+ {\r
+ if (cs != null)\r
+ {\r
+ cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));\r
}\r
\r
- public int getEndRes() {\r
- return endRes;\r
- }\r
+ if ( cs instanceof ConservationColourScheme)\r
+ {\r
+ Conservation c = new Conservation(groupName,\r
+ ResidueProperties.propHash, 3, sequences,\r
+ 0, getWidth());\r
+ c.calculate();\r
+ c.verdict(false, 25);\r
\r
- public void setStartRes(int i) {\r
- startRes = i;\r
+ ConservationColourScheme ccs = (ConservationColourScheme) cs;\r
+ ccs.conserve = c;\r
}\r
+ }\r
\r
- public void setEndRes(int i) {\r
- endRes = i;\r
+ public void addOrRemove(SequenceI s, boolean recalc)\r
+ {\r
+ if (sequences.contains(s))\r
+ {\r
+ deleteSequence(s, recalc);\r
}\r
-\r
- public int getSize() {\r
- return sequences.size();\r
+ else\r
+ {\r
+ addSequence(s, recalc);\r
}\r
-\r
- public SequenceI getSequenceAt(int i) {\r
- return (SequenceI) sequences.elementAt(i);\r
+ }\r
+\r
+ public void deleteSequence(SequenceI s, boolean recalc)\r
+ {\r
+ sequences.removeElement(s);\r
+ if(recalc)\r
+ recalcConservation();\r
+ }\r
+\r
+ public int getStartRes()\r
+ {\r
+ return startRes;\r
+ }\r
+\r
+ public int getEndRes()\r
+ {\r
+ return endRes;\r
+ }\r
+\r
+ public void setStartRes(int i)\r
+ {\r
+ startRes = i;\r
+ }\r
+\r
+ public void setEndRes(int i)\r
+ {\r
+ endRes = i;\r
+ }\r
+\r
+ public int getSize()\r
+ {\r
+ return sequences.size();\r
+ }\r
+\r
+ public SequenceI getSequenceAt(int i)\r
+ {\r
+ return (SequenceI) sequences.elementAt(i);\r
+ }\r
+\r
+ public void setColourText(boolean state)\r
+ {\r
+ colourText = state;\r
+ }\r
+\r
+ public boolean getColourText()\r
+ {\r
+ return colourText;\r
+ }\r
+\r
+ public void setDisplayText(boolean state)\r
+ {\r
+ displayText = state;\r
+ }\r
+\r
+ public boolean getDisplayText()\r
+ {\r
+ return displayText;\r
+ }\r
+\r
+ public void setDisplayBoxes(boolean state)\r
+ {\r
+ displayBoxes = state;\r
+ }\r
+\r
+ public boolean getDisplayBoxes()\r
+ {\r
+ return displayBoxes;\r
+ }\r
+\r
+ public int getWidth()\r
+ {\r
+ // MC This needs to get reset when characters are inserted and deleted\r
+ if (sequences.size() > 0)\r
+ {\r
+ width = ( (SequenceI) sequences.elementAt(0)).getLength();\r
}\r
\r
- public void setColourText(boolean state) {\r
- colourText = state;\r
- }\r
+ for (int i = 1; i < sequences.size(); i++)\r
+ {\r
+ SequenceI seq = (SequenceI) sequences.elementAt(i);\r
\r
- public boolean getColourText() {\r
- return colourText;\r
+ if (seq.getLength() > width)\r
+ {\r
+ width = seq.getLength();\r
+ }\r
}\r
\r
- public void setDisplayText(boolean state) {\r
- displayText = state;\r
+ return width;\r
+ }\r
+\r
+ public void setOutlineColour(Color c)\r
+ {\r
+ outlineColour = c;\r
+ }\r
+\r
+ public Color getOutlineColour()\r
+ {\r
+ return outlineColour;\r
+ }\r
+\r
+ /**\r
+ *\r
+ * returns the sequences in the group ordered by the ordering given by al\r
+ *\r
+ * @param al Alignment\r
+ * @return SequenceI[]\r
+ */\r
+ public SequenceI[] getSequencesInOrder(Alignment al)\r
+ {\r
+ int sz;\r
+ java.util.Hashtable orderedSeqs = new java.util.Hashtable();\r
+ SequenceI[] seqs = new SequenceI[sz = sequences.size()];\r
+\r
+ for (int i = 0; i < sz; i++)\r
+ {\r
+ SequenceI seq = (SequenceI) sequences.elementAt(i);\r
+ int index = al.findIndex(seq);\r
+ orderedSeqs.put(index + "", seq);\r
}\r
\r
- public boolean getDisplayText() {\r
- return displayText;\r
- }\r
+ int index = 0;\r
\r
- public void setDisplayBoxes(boolean state) {\r
- displayBoxes = state;\r
- }\r
+ for (int i = 0; i < sz; i++)\r
+ {\r
+ SequenceI seq = null;\r
\r
- public boolean getDisplayBoxes() {\r
- return displayBoxes;\r
- }\r
+ while (seq == null)\r
+ {\r
+ if (orderedSeqs.containsKey(index + ""))\r
+ {\r
+ seq = (SequenceI) orderedSeqs.get(index + "");\r
+ index++;\r
\r
- public int getWidth() {\r
- // MC This needs to get reset when characters are inserted and deleted\r
- if (sequences.size() > 0) {\r
- width = ((SequenceI) sequences.elementAt(0)).getLength();\r
+ break;\r
}\r
-\r
- for (int i = 1; i < sequences.size(); i++) {\r
- SequenceI seq = (SequenceI) sequences.elementAt(i);\r
-\r
- if (seq.getLength() > width) {\r
- width = seq.getLength();\r
- }\r
+ else\r
+ {\r
+ index++;\r
}\r
+ }\r
\r
- return width;\r
- }\r
-\r
- public void setOutlineColour(Color c) {\r
- outlineColour = c;\r
- }\r
-\r
- public Color getOutlineColour() {\r
- return outlineColour;\r
+ seqs[index] = seq;\r
}\r
\r
- /**\r
- *\r
- * returns the sequences in the group ordered by the ordering given by al\r
- *\r
- * @param al Alignment\r
- * @return SequenceI[]\r
- */\r
- public SequenceI[] getSequencesInOrder(Alignment al) {\r
- int sz;\r
- java.util.Hashtable orderedSeqs = new java.util.Hashtable();\r
- SequenceI[] seqs = new SequenceI[sz = sequences.size()];\r
-\r
- for (int i = 0; i < sz; i++) {\r
- SequenceI seq = (SequenceI) sequences.elementAt(i);\r
- int index = al.findIndex(seq);\r
- orderedSeqs.put(index + "", seq);\r
- }\r
-\r
- int index = 0;\r
-\r
- for (int i = 0; i < sz; i++) {\r
- SequenceI seq = null;\r
-\r
- while (seq == null) {\r
- if (orderedSeqs.containsKey(index + "")) {\r
- seq = (SequenceI) orderedSeqs.get(index + "");\r
- index++;\r
-\r
- break;\r
- } else {\r
- index++;\r
- }\r
- }\r
-\r
- seqs[index] = seq;\r
- }\r
-\r
- return seqs;\r
- }\r
+ return seqs;\r
+ }\r
}\r