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.schemes.*;
\r
34 * @version $Revision$
\r
36 public class SequenceGroup
\r
39 Conservation conserve;
\r
41 boolean displayBoxes;
\r
42 boolean displayText;
\r
45 /** DOCUMENT ME!! */
\r
46 public Vector sequences = new Vector();
\r
49 /** DOCUMENT ME!! */
\r
50 public ColourSchemeI cs;
\r
53 Color outlineColour = Color.black;
\r
56 * Creates a new SequenceGroup object.
\r
58 public SequenceGroup()
\r
60 groupName = "Group";
\r
61 this.displayBoxes = true;
\r
62 this.displayText = true;
\r
63 this.colourText = false;
\r
68 * Creates a new SequenceGroup object.
\r
70 * @param sequences DOCUMENT ME!
\r
71 * @param groupName DOCUMENT ME!
\r
72 * @param scheme DOCUMENT ME!
\r
73 * @param displayBoxes DOCUMENT ME!
\r
74 * @param displayText DOCUMENT ME!
\r
75 * @param colourText DOCUMENT ME!
\r
76 * @param start DOCUMENT ME!
\r
77 * @param end DOCUMENT ME!
\r
79 public SequenceGroup(Vector sequences, String groupName,
\r
80 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
\r
81 boolean colourText, int start, int end)
\r
83 this.sequences = sequences;
\r
84 this.groupName = groupName;
\r
85 this.displayBoxes = displayBoxes;
\r
86 this.displayText = displayText;
\r
87 this.colourText = colourText;
\r
91 recalcConservation();
\r
95 * Creates a new SequenceGroup object.
\r
97 * @param groupName DOCUMENT ME!
\r
98 * @param scheme DOCUMENT ME!
\r
99 * @param displayBoxes DOCUMENT ME!
\r
100 * @param displayText DOCUMENT ME!
\r
101 * @param colourText DOCUMENT ME!
\r
102 * @param start DOCUMENT ME!
\r
103 * @param end DOCUMENT ME!
\r
105 public SequenceGroup(String groupName, ColourSchemeI scheme,
\r
106 boolean displayBoxes, boolean displayText, boolean colourText,
\r
107 int start, int end)
\r
109 this.groupName = groupName;
\r
110 this.displayBoxes = displayBoxes;
\r
111 this.displayText = displayText;
\r
112 this.colourText = colourText;
\r
121 * @param col DOCUMENT ME!
\r
123 * @return DOCUMENT ME!
\r
125 public boolean adjustForRemoveLeft(int col)
\r
127 // return value is true if the group still exists
\r
128 if (startRes >= col)
\r
130 startRes = startRes - col;
\r
135 endRes = endRes - col;
\r
137 if (startRes > endRes)
\r
144 // must delete this group!!
\r
154 * @param col DOCUMENT ME!
\r
156 * @return DOCUMENT ME!
\r
158 public boolean adjustForRemoveRight(int col)
\r
160 if (startRes > col)
\r
162 // delete this group
\r
177 * @return DOCUMENT ME!
\r
179 public String getName()
\r
187 * @param name DOCUMENT ME!
\r
189 public void setName(String name)
\r
197 * @return DOCUMENT ME!
\r
199 public Conservation getConservation()
\r
207 * @param c DOCUMENT ME!
\r
209 public void setConservation(Conservation c)
\r
217 * @param s DOCUMENT ME!
\r
218 * @param recalc DOCUMENT ME!
\r
220 public void addSequence(SequenceI s, boolean recalc)
\r
222 if (!sequences.contains(s))
\r
224 sequences.addElement(s);
\r
229 recalcConservation();
\r
236 public void recalcConservation()
\r
240 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
243 if (cs instanceof ClustalxColourScheme)
\r
245 ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
\r
248 if (cs instanceof ConservationColourScheme)
\r
250 Conservation c = new Conservation(groupName,
\r
251 ResidueProperties.propHash, 3, sequences, 0, getWidth());
\r
253 c.verdict(false, 25);
\r
255 ConservationColourScheme ccs = (ConservationColourScheme) cs;
\r
258 if (ccs.cs instanceof ClustalxColourScheme)
\r
260 ((ClustalxColourScheme) ccs.cs).resetClustalX(sequences,
\r
269 * @param s DOCUMENT ME!
\r
270 * @param recalc DOCUMENT ME!
\r
272 public void addOrRemove(SequenceI s, boolean recalc)
\r
274 if (sequences.contains(s))
\r
276 deleteSequence(s, recalc);
\r
280 addSequence(s, recalc);
\r
287 * @param s DOCUMENT ME!
\r
288 * @param recalc DOCUMENT ME!
\r
290 public void deleteSequence(SequenceI s, boolean recalc)
\r
292 sequences.removeElement(s);
\r
296 recalcConservation();
\r
303 * @return DOCUMENT ME!
\r
305 public int getStartRes()
\r
313 * @return DOCUMENT ME!
\r
315 public int getEndRes()
\r
323 * @param i DOCUMENT ME!
\r
325 public void setStartRes(int i)
\r
333 * @param i DOCUMENT ME!
\r
335 public void setEndRes(int i)
\r
343 * @return DOCUMENT ME!
\r
345 public int getSize()
\r
347 return sequences.size();
\r
353 * @param i DOCUMENT ME!
\r
355 * @return DOCUMENT ME!
\r
357 public SequenceI getSequenceAt(int i)
\r
359 return (SequenceI) sequences.elementAt(i);
\r
365 * @param state DOCUMENT ME!
\r
367 public void setColourText(boolean state)
\r
369 colourText = state;
\r
375 * @return DOCUMENT ME!
\r
377 public boolean getColourText()
\r
385 * @param state DOCUMENT ME!
\r
387 public void setDisplayText(boolean state)
\r
389 displayText = state;
\r
395 * @return DOCUMENT ME!
\r
397 public boolean getDisplayText()
\r
399 return displayText;
\r
405 * @param state DOCUMENT ME!
\r
407 public void setDisplayBoxes(boolean state)
\r
409 displayBoxes = state;
\r
415 * @return DOCUMENT ME!
\r
417 public boolean getDisplayBoxes()
\r
419 return displayBoxes;
\r
425 * @return DOCUMENT ME!
\r
427 public int getWidth()
\r
429 // MC This needs to get reset when characters are inserted and deleted
\r
430 if (sequences.size() > 0)
\r
432 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
435 for (int i = 1; i < sequences.size(); i++)
\r
437 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
439 if (seq.getLength() > width)
\r
441 width = seq.getLength();
\r
451 * @param c DOCUMENT ME!
\r
453 public void setOutlineColour(Color c)
\r
461 * @return DOCUMENT ME!
\r
463 public Color getOutlineColour()
\r
465 return outlineColour;
\r
470 * returns the sequences in the group ordered by the ordering given by al
\r
472 * @param al Alignment
\r
473 * @return SequenceI[]
\r
475 public SequenceI[] getSequencesInOrder(AlignmentI al)
\r
477 int sz = sequences.size();
\r
478 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
479 SequenceI[] seqs = new SequenceI[sz];
\r
481 for (int i = 0; i < sz; i++)
\r
483 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
484 int index = al.findIndex(seq);
\r
485 orderedSeqs.put(index + "", seq);
\r
490 for (int i = 0; i < al.getHeight(); i++)
\r
492 if (orderedSeqs.containsKey(i + ""))
\r
494 seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
\r