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
241 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
244 if (cs instanceof ClustalxColourScheme)
\r
246 ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
\r
250 if (cs.conservationApplied())
\r
252 Conservation c = new Conservation(groupName,
\r
253 ResidueProperties.propHash, 3, sequences, 0, getWidth());
\r
255 c.verdict(false, 25);
\r
258 cs.setConservation(c);
\r
260 if (cs instanceof ClustalxColourScheme)
\r
262 ((ClustalxColourScheme) cs).resetClustalX(sequences,
\r
271 * @param s DOCUMENT ME!
\r
272 * @param recalc DOCUMENT ME!
\r
274 public void addOrRemove(SequenceI s, boolean recalc)
\r
276 if (sequences.contains(s))
\r
278 deleteSequence(s, recalc);
\r
282 addSequence(s, recalc);
\r
289 * @param s DOCUMENT ME!
\r
290 * @param recalc DOCUMENT ME!
\r
292 public void deleteSequence(SequenceI s, boolean recalc)
\r
294 sequences.removeElement(s);
\r
298 recalcConservation();
\r
305 * @return DOCUMENT ME!
\r
307 public int getStartRes()
\r
315 * @return DOCUMENT ME!
\r
317 public int getEndRes()
\r
325 * @param i DOCUMENT ME!
\r
327 public void setStartRes(int i)
\r
335 * @param i DOCUMENT ME!
\r
337 public void setEndRes(int i)
\r
345 * @return DOCUMENT ME!
\r
347 public int getSize()
\r
349 return sequences.size();
\r
355 * @param i DOCUMENT ME!
\r
357 * @return DOCUMENT ME!
\r
359 public SequenceI getSequenceAt(int i)
\r
361 return (SequenceI) sequences.elementAt(i);
\r
367 * @param state DOCUMENT ME!
\r
369 public void setColourText(boolean state)
\r
371 colourText = state;
\r
377 * @return DOCUMENT ME!
\r
379 public boolean getColourText()
\r
387 * @param state DOCUMENT ME!
\r
389 public void setDisplayText(boolean state)
\r
391 displayText = state;
\r
397 * @return DOCUMENT ME!
\r
399 public boolean getDisplayText()
\r
401 return displayText;
\r
407 * @param state DOCUMENT ME!
\r
409 public void setDisplayBoxes(boolean state)
\r
411 displayBoxes = state;
\r
417 * @return DOCUMENT ME!
\r
419 public boolean getDisplayBoxes()
\r
421 return displayBoxes;
\r
427 * @return DOCUMENT ME!
\r
429 public int getWidth()
\r
431 // MC This needs to get reset when characters are inserted and deleted
\r
432 if (sequences.size() > 0)
\r
434 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
437 for (int i = 1; i < sequences.size(); i++)
\r
439 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
441 if (seq.getLength() > width)
\r
443 width = seq.getLength();
\r
453 * @param c DOCUMENT ME!
\r
455 public void setOutlineColour(Color c)
\r
463 * @return DOCUMENT ME!
\r
465 public Color getOutlineColour()
\r
467 return outlineColour;
\r
472 * returns the sequences in the group ordered by the ordering given by al
\r
474 * @param al Alignment
\r
475 * @return SequenceI[]
\r
477 public SequenceI[] getSequencesInOrder(AlignmentI al)
\r
479 int sz = sequences.size();
\r
480 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
481 SequenceI[] seqs = new SequenceI[sz];
\r
483 for (int i = 0; i < sz; i++)
\r
485 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
486 int index = al.findIndex(seq);
\r
487 orderedSeqs.put(index + "", seq);
\r
492 for (int i = 0; i < al.getHeight(); i++)
\r
494 if (orderedSeqs.containsKey(i + ""))
\r
496 seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
\r