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
44 private Vector sequences = new Vector();
\r
47 /** DOCUMENT ME!! */
\r
48 public ColourSchemeI cs;
\r
51 Color outlineColour = Color.black;
\r
54 * Creates a new SequenceGroup object.
\r
56 public SequenceGroup()
\r
58 groupName = "Group";
\r
59 this.displayBoxes = true;
\r
60 this.displayText = true;
\r
61 this.colourText = false;
\r
66 * Creates a new SequenceGroup object.
\r
68 * @param sequences DOCUMENT ME!
\r
69 * @param groupName DOCUMENT ME!
\r
70 * @param scheme DOCUMENT ME!
\r
71 * @param displayBoxes DOCUMENT ME!
\r
72 * @param displayText DOCUMENT ME!
\r
73 * @param colourText DOCUMENT ME!
\r
74 * @param start DOCUMENT ME!
\r
75 * @param end DOCUMENT ME!
\r
77 public SequenceGroup(Vector sequences, String groupName,
\r
78 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
\r
79 boolean colourText, int start, int end)
\r
81 this.sequences = sequences;
\r
82 this.groupName = groupName;
\r
83 this.displayBoxes = displayBoxes;
\r
84 this.displayText = displayText;
\r
85 this.colourText = colourText;
\r
89 recalcConservation();
\r
93 * Creates a new SequenceGroup object.
\r
95 * @param groupName DOCUMENT ME!
\r
96 * @param scheme DOCUMENT ME!
\r
97 * @param displayBoxes DOCUMENT ME!
\r
98 * @param displayText DOCUMENT ME!
\r
99 * @param colourText DOCUMENT ME!
\r
100 * @param start DOCUMENT ME!
\r
101 * @param end DOCUMENT ME!
\r
103 public SequenceGroup(String groupName, ColourSchemeI scheme,
\r
104 boolean displayBoxes, boolean displayText, boolean colourText,
\r
105 int start, int end)
\r
107 this.groupName = groupName;
\r
108 this.displayBoxes = displayBoxes;
\r
109 this.displayText = displayText;
\r
110 this.colourText = colourText;
\r
116 public Vector getSequences(boolean includeHidden)
\r
122 Vector allSequences = new Vector();
\r
124 for (int i = 0; i < sequences.size(); i++)
\r
126 seq = (SequenceI) sequences.elementAt(i);
\r
127 allSequences.addElement(seq);
\r
128 if (seq.getHiddenSequences() != null)
\r
130 for (int h = 0; h < seq.getHiddenSequences().getSize(false); h++)
\r
132 allSequences.addElement(
\r
133 seq.getHiddenSequences().getSequenceAt(h)
\r
139 return allSequences;
\r
146 * @param col DOCUMENT ME!
\r
148 * @return DOCUMENT ME!
\r
150 public boolean adjustForRemoveLeft(int col)
\r
152 // return value is true if the group still exists
\r
153 if (startRes >= col)
\r
155 startRes = startRes - col;
\r
160 endRes = endRes - col;
\r
162 if (startRes > endRes)
\r
169 // must delete this group!!
\r
179 * @param col DOCUMENT ME!
\r
181 * @return DOCUMENT ME!
\r
183 public boolean adjustForRemoveRight(int col)
\r
185 if (startRes > col)
\r
187 // delete this group
\r
202 * @return DOCUMENT ME!
\r
204 public String getName()
\r
212 * @param name DOCUMENT ME!
\r
214 public void setName(String name)
\r
222 * @return DOCUMENT ME!
\r
224 public Conservation getConservation()
\r
232 * @param c DOCUMENT ME!
\r
234 public void setConservation(Conservation c)
\r
242 * @param s DOCUMENT ME!
\r
243 * @param recalc DOCUMENT ME!
\r
245 public void addSequence(SequenceI s, boolean recalc)
\r
247 if (!sequences.contains(s))
\r
249 sequences.addElement(s);
\r
254 recalcConservation();
\r
261 public void recalcConservation()
\r
266 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
269 if (cs instanceof ClustalxColourScheme)
\r
271 ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
\r
275 if (cs.conservationApplied())
\r
277 Conservation c = new Conservation(groupName,
\r
278 ResidueProperties.propHash, 3, sequences, 0, getWidth());
\r
280 c.verdict(false, 25);
\r
283 cs.setConservation(c);
\r
285 if (cs instanceof ClustalxColourScheme)
\r
287 ((ClustalxColourScheme) cs).resetClustalX(sequences,
\r
296 * @param s DOCUMENT ME!
\r
297 * @param recalc DOCUMENT ME!
\r
299 public void addOrRemove(SequenceI s, boolean recalc)
\r
301 if (sequences.contains(s))
\r
303 deleteSequence(s, recalc);
\r
307 addSequence(s, recalc);
\r
314 * @param s DOCUMENT ME!
\r
315 * @param recalc DOCUMENT ME!
\r
317 public void deleteSequence(SequenceI s, boolean recalc)
\r
319 sequences.removeElement(s);
\r
323 recalcConservation();
\r
330 * @return DOCUMENT ME!
\r
332 public int getStartRes()
\r
340 * @return DOCUMENT ME!
\r
342 public int getEndRes()
\r
350 * @param i DOCUMENT ME!
\r
352 public void setStartRes(int i)
\r
360 * @param i DOCUMENT ME!
\r
362 public void setEndRes(int i)
\r
370 * @return DOCUMENT ME!
\r
372 public int getSize(boolean includeHidden)
\r
375 return sequences.size();
\r
378 int total = sequences.size();
\r
380 for (int i = 0; i < sequences.size(); i++)
\r
382 seq = (SequenceI) sequences.elementAt(i);
\r
383 if (seq.getHiddenSequences() != null)
\r
385 total += seq.getHiddenSequences().getSize(false);
\r
395 * @param i DOCUMENT ME!
\r
397 * @return DOCUMENT ME!
\r
399 public SequenceI getSequenceAt(int i)
\r
401 return (SequenceI) sequences.elementAt(i);
\r
407 * @param state DOCUMENT ME!
\r
409 public void setColourText(boolean state)
\r
411 colourText = state;
\r
417 * @return DOCUMENT ME!
\r
419 public boolean getColourText()
\r
427 * @param state DOCUMENT ME!
\r
429 public void setDisplayText(boolean state)
\r
431 displayText = state;
\r
437 * @return DOCUMENT ME!
\r
439 public boolean getDisplayText()
\r
441 return displayText;
\r
447 * @param state DOCUMENT ME!
\r
449 public void setDisplayBoxes(boolean state)
\r
451 displayBoxes = state;
\r
457 * @return DOCUMENT ME!
\r
459 public boolean getDisplayBoxes()
\r
461 return displayBoxes;
\r
467 * @return DOCUMENT ME!
\r
469 public int getWidth()
\r
471 // MC This needs to get reset when characters are inserted and deleted
\r
472 if (sequences.size() > 0)
\r
474 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
477 for (int i = 1; i < sequences.size(); i++)
\r
479 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
481 if (seq.getLength() > width)
\r
483 width = seq.getLength();
\r
493 * @param c DOCUMENT ME!
\r
495 public void setOutlineColour(Color c)
\r
503 * @return DOCUMENT ME!
\r
505 public Color getOutlineColour()
\r
507 return outlineColour;
\r
512 * returns the sequences in the group ordered by the ordering given by al
\r
514 * @param al Alignment
\r
515 * @return SequenceI[]
\r
517 public SequenceI[] getSequencesInOrder(AlignmentI al)
\r
519 int sz = sequences.size();
\r
520 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
521 SequenceI[] seqs = new SequenceI[sz];
\r
523 for (int i = 0; i < sz; i++)
\r
525 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
526 int index = al.findIndex(seq);
\r
527 orderedSeqs.put(index + "", seq);
\r
532 for (int i = 0; i < al.getHeight(); i++)
\r
534 if (orderedSeqs.containsKey(i + ""))
\r
536 seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
\r