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 SequenceI [] getSelectionAsNewSequences(AlignmentI align)
\r
118 int iSize = sequences.size();
\r
119 SequenceI [] seqs = new SequenceI[iSize];
\r
120 SequenceI [] inorder = getSequencesInOrder(align);
\r
125 for (int i = 0; i < iSize; i++)
\r
127 SequenceI seq = inorder[i];
\r
130 //Returns residue following index if gap
\r
131 sres = seq.findPosition(startRes);
\r
134 //Need to find the residue preceeding index if gap
\r
137 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
\r
139 ch = seq.getCharAt(j);
\r
140 if (!jalview.util.Comparison.isGap( (ch)))
\r
148 eres += seq.getStart() - 1;
\r
151 seqs[i] = new Sequence(seq.getName(),
\r
152 seq.getSequence(startRes, endRes + 1),
\r
155 seqs[i].setDescription(seq.getDescription());
\r
156 seqs[i].setDBRef(seq.getDBRef());
\r
157 seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
\r
158 if (seq.getDatasetSequence() != null)
\r
159 seqs[i].setDatasetSequence(seq.getDatasetSequence());
\r
161 if(seq.getAnnotation()!=null)
\r
163 for(int a=0; a<seq.getAnnotation().length; a++)
\r
164 seqs[i].addAlignmentAnnotation(seq.getAnnotation()[a]);
\r
172 public Vector getSequences(boolean includeHidden)
\r
178 Vector allSequences = new Vector();
\r
180 for (int i = 0; i < sequences.size(); i++)
\r
182 seq = (SequenceI) sequences.elementAt(i);
\r
183 allSequences.addElement(seq);
\r
184 if (seq.getHiddenSequences() != null)
\r
186 for (int h = 0; h < seq.getHiddenSequences().getSize(false); h++)
\r
188 allSequences.addElement(
\r
189 seq.getHiddenSequences().getSequenceAt(h)
\r
195 return allSequences;
\r
202 * @param col DOCUMENT ME!
\r
204 * @return DOCUMENT ME!
\r
206 public boolean adjustForRemoveLeft(int col)
\r
208 // return value is true if the group still exists
\r
209 if (startRes >= col)
\r
211 startRes = startRes - col;
\r
216 endRes = endRes - col;
\r
218 if (startRes > endRes)
\r
225 // must delete this group!!
\r
235 * @param col DOCUMENT ME!
\r
237 * @return DOCUMENT ME!
\r
239 public boolean adjustForRemoveRight(int col)
\r
241 if (startRes > col)
\r
243 // delete this group
\r
258 * @return DOCUMENT ME!
\r
260 public String getName()
\r
268 * @param name DOCUMENT ME!
\r
270 public void setName(String name)
\r
278 * @return DOCUMENT ME!
\r
280 public Conservation getConservation()
\r
288 * @param c DOCUMENT ME!
\r
290 public void setConservation(Conservation c)
\r
298 * @param s DOCUMENT ME!
\r
299 * @param recalc DOCUMENT ME!
\r
301 public void addSequence(SequenceI s, boolean recalc)
\r
303 if (!sequences.contains(s))
\r
305 sequences.addElement(s);
\r
310 recalcConservation();
\r
317 public void recalcConservation()
\r
322 cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth()));
\r
325 if (cs instanceof ClustalxColourScheme)
\r
327 ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
\r
331 if (cs.conservationApplied())
\r
333 Conservation c = new Conservation(groupName,
\r
334 ResidueProperties.propHash, 3, sequences, 0, getWidth());
\r
336 c.verdict(false, 25);
\r
339 cs.setConservation(c);
\r
341 if (cs instanceof ClustalxColourScheme)
\r
343 ((ClustalxColourScheme) cs).resetClustalX(sequences,
\r
352 * @param s DOCUMENT ME!
\r
353 * @param recalc DOCUMENT ME!
\r
355 public void addOrRemove(SequenceI s, boolean recalc)
\r
357 if (sequences.contains(s))
\r
359 deleteSequence(s, recalc);
\r
363 addSequence(s, recalc);
\r
370 * @param s DOCUMENT ME!
\r
371 * @param recalc DOCUMENT ME!
\r
373 public void deleteSequence(SequenceI s, boolean recalc)
\r
375 sequences.removeElement(s);
\r
379 recalcConservation();
\r
386 * @return DOCUMENT ME!
\r
388 public int getStartRes()
\r
396 * @return DOCUMENT ME!
\r
398 public int getEndRes()
\r
406 * @param i DOCUMENT ME!
\r
408 public void setStartRes(int i)
\r
416 * @param i DOCUMENT ME!
\r
418 public void setEndRes(int i)
\r
426 * @return DOCUMENT ME!
\r
428 public int getSize(boolean includeHidden)
\r
431 return sequences.size();
\r
434 int total = sequences.size();
\r
436 for (int i = 0; i < sequences.size(); i++)
\r
438 seq = (SequenceI) sequences.elementAt(i);
\r
439 if (seq.getHiddenSequences() != null)
\r
441 total += seq.getHiddenSequences().getSize(false);
\r
451 * @param i DOCUMENT ME!
\r
453 * @return DOCUMENT ME!
\r
455 public SequenceI getSequenceAt(int i)
\r
457 return (SequenceI) sequences.elementAt(i);
\r
463 * @param state DOCUMENT ME!
\r
465 public void setColourText(boolean state)
\r
467 colourText = state;
\r
473 * @return DOCUMENT ME!
\r
475 public boolean getColourText()
\r
483 * @param state DOCUMENT ME!
\r
485 public void setDisplayText(boolean state)
\r
487 displayText = state;
\r
493 * @return DOCUMENT ME!
\r
495 public boolean getDisplayText()
\r
497 return displayText;
\r
503 * @param state DOCUMENT ME!
\r
505 public void setDisplayBoxes(boolean state)
\r
507 displayBoxes = state;
\r
513 * @return DOCUMENT ME!
\r
515 public boolean getDisplayBoxes()
\r
517 return displayBoxes;
\r
523 * @return DOCUMENT ME!
\r
525 public int getWidth()
\r
527 // MC This needs to get reset when characters are inserted and deleted
\r
528 if (sequences.size() > 0)
\r
530 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
533 for (int i = 1; i < sequences.size(); i++)
\r
535 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
537 if (seq.getLength() > width)
\r
539 width = seq.getLength();
\r
549 * @param c DOCUMENT ME!
\r
551 public void setOutlineColour(Color c)
\r
559 * @return DOCUMENT ME!
\r
561 public Color getOutlineColour()
\r
563 return outlineColour;
\r
568 * returns the sequences in the group ordered by the ordering given by al
\r
570 * @param al Alignment
\r
571 * @return SequenceI[]
\r
573 public SequenceI[] getSequencesInOrder(AlignmentI al)
\r
575 int sz = sequences.size();
\r
576 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
577 SequenceI[] seqs = new SequenceI[sz];
\r
579 for (int i = 0; i < sz; i++)
\r
581 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
582 int index = al.findIndex(seq);
\r
583 orderedSeqs.put(index + "", seq);
\r
588 for (int i = 0; i < al.getHeight(); i++)
\r
590 if (orderedSeqs.containsKey(i + ""))
\r
592 seqs[index++] = (SequenceI) orderedSeqs.get(i + "");
\r