2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
21 import jalview.analysis.*;
\r
23 import jalview.datamodel.*;
\r
25 import jalview.schemes.*;
\r
29 import java.util.Vector;
\r
32 public class SequenceGroup {
\r
34 Conservation conserve;
\r
36 boolean displayBoxes;
\r
37 boolean displayText;
\r
39 public Vector sequences = new Vector();
\r
41 public ColourSchemeI cs;
\r
44 Color outlineColour = Color.black;
\r
46 public SequenceGroup() {
\r
47 groupName = "Group";
\r
48 this.displayBoxes = true;
\r
49 this.displayText = true;
\r
50 this.colourText = false;
\r
54 public SequenceGroup(String groupName, ColourSchemeI scheme,
\r
55 boolean displayBoxes, boolean displayText, boolean colourText,
\r
56 int start, int end) {
\r
57 this.groupName = groupName;
\r
58 this.displayBoxes = displayBoxes;
\r
59 this.displayText = displayText;
\r
60 this.colourText = colourText;
\r
66 public boolean adjustForRemoveLeft(int col) {
\r
67 // return value is true if the group still exists
\r
68 if (startRes >= col) {
\r
69 startRes = startRes - col;
\r
72 if (endRes >= col) {
\r
73 endRes = endRes - col;
\r
75 if (startRes > endRes) {
\r
79 // must delete this group!!
\r
86 public boolean adjustForRemoveRight(int col) {
\r
87 if (startRes > col) {
\r
88 // delete this group
\r
92 if (endRes >= col) {
\r
99 public String getName() {
\r
103 public void setName(String name) {
\r
107 public Conservation getConservation() {
\r
111 public void setConservation(Conservation c) {
\r
115 public void addSequence(SequenceI s) {
\r
116 if (!sequences.contains(s)) {
\r
117 sequences.addElement(s);
\r
121 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
124 if (cs instanceof ConservationColourScheme) {
\r
125 recalcConservation();
\r
129 void recalcConservation() {
\r
130 Conservation c = new Conservation(groupName,
\r
131 ResidueProperties.propHash, 3, sequences, 0, getWidth());
\r
133 c.verdict(false, 25);
\r
135 ConservationColourScheme ccs = (ConservationColourScheme) cs;
\r
139 public void addOrRemove(SequenceI s) {
\r
140 if (sequences.contains(s)) {
\r
147 public void deleteSequence(SequenceI s) {
\r
148 sequences.removeElement(s);
\r
151 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
154 if (cs instanceof ConservationColourScheme) {
\r
155 recalcConservation();
\r
159 public int getStartRes() {
\r
163 public int getEndRes() {
\r
167 public void setStartRes(int i) {
\r
171 public void setEndRes(int i) {
\r
175 public int getSize() {
\r
176 return sequences.size();
\r
179 public SequenceI getSequenceAt(int i) {
\r
180 return (SequenceI) sequences.elementAt(i);
\r
183 public void setColourText(boolean state) {
\r
184 colourText = state;
\r
187 public boolean getColourText() {
\r
191 public void setDisplayText(boolean state) {
\r
192 displayText = state;
\r
195 public boolean getDisplayText() {
\r
196 return displayText;
\r
199 public void setDisplayBoxes(boolean state) {
\r
200 displayBoxes = state;
\r
203 public boolean getDisplayBoxes() {
\r
204 return displayBoxes;
\r
207 public int getWidth() {
\r
208 // MC This needs to get reset when characters are inserted and deleted
\r
209 if (sequences.size() > 0) {
\r
210 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
213 for (int i = 1; i < sequences.size(); i++) {
\r
214 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
216 if (seq.getLength() > width) {
\r
217 width = seq.getLength();
\r
224 public void setOutlineColour(Color c) {
\r
228 public Color getOutlineColour() {
\r
229 return outlineColour;
\r
234 * returns the sequences in the group ordered by the ordering given by al
\r
236 * @param al Alignment
\r
237 * @return SequenceI[]
\r
239 public SequenceI[] getSequencesInOrder(Alignment al) {
\r
241 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
242 SequenceI[] seqs = new SequenceI[sz = sequences.size()];
\r
244 for (int i = 0; i < sz; i++) {
\r
245 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
246 int index = al.findIndex(seq);
\r
247 orderedSeqs.put(index + "", seq);
\r
252 for (int i = 0; i < sz; i++) {
\r
253 SequenceI seq = null;
\r
255 while (seq == null) {
\r
256 if (orderedSeqs.containsKey(index + "")) {
\r
257 seq = (SequenceI) orderedSeqs.get(index + "");
\r