2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
52 public int thresholdTextColour = 0;
\r
53 public Color textColour = Color.black;
\r
54 public Color textColour2 = Color.white;
\r
58 * Creates a new SequenceGroup object.
\r
60 public SequenceGroup()
\r
62 groupName = "Group";
\r
63 this.displayBoxes = true;
\r
64 this.displayText = true;
\r
65 this.colourText = false;
\r
70 * Creates a new SequenceGroup object.
\r
72 * @param sequences DOCUMENT ME!
\r
73 * @param groupName DOCUMENT ME!
\r
74 * @param scheme DOCUMENT ME!
\r
75 * @param displayBoxes DOCUMENT ME!
\r
76 * @param displayText DOCUMENT ME!
\r
77 * @param colourText DOCUMENT ME!
\r
78 * @param start DOCUMENT ME!
\r
79 * @param end DOCUMENT ME!
\r
81 public SequenceGroup(Vector sequences, String groupName,
\r
82 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
\r
83 boolean colourText, int start, int end)
\r
85 this.sequences = sequences;
\r
86 this.groupName = groupName;
\r
87 this.displayBoxes = displayBoxes;
\r
88 this.displayText = displayText;
\r
89 this.colourText = colourText;
\r
93 recalcConservation();
\r
97 * Creates a new SequenceGroup object.
\r
99 * @param groupName DOCUMENT ME!
\r
100 * @param scheme DOCUMENT ME!
\r
101 * @param displayBoxes DOCUMENT ME!
\r
102 * @param displayText DOCUMENT ME!
\r
103 * @param colourText DOCUMENT ME!
\r
104 * @param start DOCUMENT ME!
\r
105 * @param end DOCUMENT ME!
\r
107 public SequenceGroup(String groupName, ColourSchemeI scheme,
\r
108 boolean displayBoxes, boolean displayText, boolean colourText,
\r
109 int start, int end)
\r
111 this.groupName = groupName;
\r
112 this.displayBoxes = displayBoxes;
\r
113 this.displayText = displayText;
\r
114 this.colourText = colourText;
\r
120 public SequenceI [] getSelectionAsNewSequences(AlignmentI align)
\r
122 int iSize = sequences.size();
\r
123 SequenceI [] seqs = new SequenceI[iSize];
\r
124 SequenceI [] inorder = getSequencesInOrder(align);
\r
127 for (int i = 0; i < iSize; i++)
\r
129 SequenceI seq = inorder[i];
\r
131 seqs[i] = new Sequence(seq.getName(),
\r
132 seq.getSequence(startRes, endRes + 1),
\r
133 seq.findPosition(startRes),
\r
136 seqs[i].setDescription(seq.getDescription());
\r
137 seqs[i].setDBRef(seq.getDBRef());
\r
138 seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
\r
139 if (seq.getDatasetSequence() != null)
\r
140 seqs[i].setDatasetSequence(seq.getDatasetSequence());
\r
142 if(seq.getAnnotation()!=null)
\r
144 for(int a=0; a<seq.getAnnotation().length; a++)
\r
145 seqs[i].addAlignmentAnnotation(seq.getAnnotation()[a]);
\r
154 * If sequence ends in gaps, the end residue can
\r
155 * be correctly calculated here
\r
156 * @param seq SequenceI
\r
159 public int findEndRes(SequenceI seq)
\r
164 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
\r
166 ch = seq.getCharAt(j);
\r
167 if (!jalview.util.Comparison.isGap( (ch)))
\r
175 eres += seq.getStart() - 1;
\r
181 public Vector getSequences(boolean includeHidden)
\r
187 Vector allSequences = new Vector();
\r
189 for (int i = 0; i < sequences.size(); i++)
\r
191 seq = (SequenceI) sequences.elementAt(i);
\r
192 allSequences.addElement(seq);
\r
193 if (seq.getHiddenSequences() != null)
\r
195 for (int h = 0; h < seq.getHiddenSequences().getSize(false); h++)
\r
197 allSequences.addElement(
\r
198 seq.getHiddenSequences().getSequenceAt(h)
\r
204 return allSequences;
\r
208 public SequenceI[] getSequencesAsArray(boolean includeHidden)
\r
210 Vector tmp = getSequences(includeHidden);
\r
213 SequenceI [] result = new SequenceI[tmp.size()];
\r
214 for(int i=0; i<result.length; i++)
\r
215 result[i] = (SequenceI)tmp.elementAt(i);
\r
223 * @param col DOCUMENT ME!
\r
225 * @return DOCUMENT ME!
\r
227 public boolean adjustForRemoveLeft(int col)
\r
229 // return value is true if the group still exists
\r
230 if (startRes >= col)
\r
232 startRes = startRes - col;
\r
237 endRes = endRes - col;
\r
239 if (startRes > endRes)
\r
246 // must delete this group!!
\r
256 * @param col DOCUMENT ME!
\r
258 * @return DOCUMENT ME!
\r
260 public boolean adjustForRemoveRight(int col)
\r
262 if (startRes > col)
\r
264 // delete this group
\r
279 * @return DOCUMENT ME!
\r
281 public String getName()
\r
289 * @param name DOCUMENT ME!
\r
291 public void setName(String name)
\r
299 * @return DOCUMENT ME!
\r
301 public Conservation getConservation()
\r
309 * @param c DOCUMENT ME!
\r
311 public void setConservation(Conservation c)
\r
319 * @param s DOCUMENT ME!
\r
320 * @param recalc DOCUMENT ME!
\r
322 public void addSequence(SequenceI s, boolean recalc)
\r
324 if (s!=null && !sequences.contains(s))
\r
326 sequences.addElement(s);
\r
331 recalcConservation();
\r
338 public void recalcConservation()
\r
345 cs.setConsensus(AAFrequency.calculate(sequences, startRes, endRes+1));
\r
347 if (cs instanceof ClustalxColourScheme)
\r
349 ( (ClustalxColourScheme) cs).resetClustalX(sequences, getWidth());
\r
352 if (cs.conservationApplied())
\r
354 Conservation c = new Conservation(groupName,
\r
355 ResidueProperties.propHash, 3, sequences,
\r
356 startRes, endRes+1);
\r
358 c.verdict(false, 25);
\r
360 cs.setConservation(c);
\r
362 if (cs instanceof ClustalxColourScheme)
\r
364 ( (ClustalxColourScheme) cs).resetClustalX(sequences,
\r
369 catch (java.lang.OutOfMemoryError err)
\r
371 System.out.println("Out of memory loading groups: " + err);
\r
379 * @param s DOCUMENT ME!
\r
380 * @param recalc DOCUMENT ME!
\r
382 public void addOrRemove(SequenceI s, boolean recalc)
\r
384 if (sequences.contains(s))
\r
386 deleteSequence(s, recalc);
\r
390 addSequence(s, recalc);
\r
397 * @param s DOCUMENT ME!
\r
398 * @param recalc DOCUMENT ME!
\r
400 public void deleteSequence(SequenceI s, boolean recalc)
\r
402 sequences.removeElement(s);
\r
406 recalcConservation();
\r
413 * @return DOCUMENT ME!
\r
415 public int getStartRes()
\r
423 * @return DOCUMENT ME!
\r
425 public int getEndRes()
\r
433 * @param i DOCUMENT ME!
\r
435 public void setStartRes(int i)
\r
443 * @param i DOCUMENT ME!
\r
445 public void setEndRes(int i)
\r
453 * @return DOCUMENT ME!
\r
455 public int getSize(boolean includeHidden)
\r
458 return sequences.size();
\r
461 int total = sequences.size();
\r
463 for (int i = 0; i < sequences.size(); i++)
\r
465 seq = (SequenceI) sequences.elementAt(i);
\r
466 if (seq.getHiddenSequences() != null)
\r
468 total += seq.getHiddenSequences().getSize(false);
\r
478 * @param i DOCUMENT ME!
\r
480 * @return DOCUMENT ME!
\r
482 public SequenceI getSequenceAt(int i)
\r
484 return (SequenceI) sequences.elementAt(i);
\r
490 * @param state DOCUMENT ME!
\r
492 public void setColourText(boolean state)
\r
494 colourText = state;
\r
500 * @return DOCUMENT ME!
\r
502 public boolean getColourText()
\r
510 * @param state DOCUMENT ME!
\r
512 public void setDisplayText(boolean state)
\r
514 displayText = state;
\r
520 * @return DOCUMENT ME!
\r
522 public boolean getDisplayText()
\r
524 return displayText;
\r
530 * @param state DOCUMENT ME!
\r
532 public void setDisplayBoxes(boolean state)
\r
534 displayBoxes = state;
\r
540 * @return DOCUMENT ME!
\r
542 public boolean getDisplayBoxes()
\r
544 return displayBoxes;
\r
550 * @return DOCUMENT ME!
\r
552 public int getWidth()
\r
554 // MC This needs to get reset when characters are inserted and deleted
\r
555 if (sequences.size() > 0)
\r
557 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
560 for (int i = 1; i < sequences.size(); i++)
\r
562 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
564 if (seq.getLength() > width)
\r
566 width = seq.getLength();
\r
576 * @param c DOCUMENT ME!
\r
578 public void setOutlineColour(Color c)
\r
586 * @return DOCUMENT ME!
\r
588 public Color getOutlineColour()
\r
590 return outlineColour;
\r
595 * returns the sequences in the group ordered by the ordering given by al
\r
597 * @param al Alignment
\r
598 * @return SequenceI[]
\r
600 public SequenceI[] getSequencesInOrder(AlignmentI al)
\r
602 int sSize = sequences.size();
\r
603 int alHeight = al.getHeight();
\r
605 SequenceI[] seqs = new SequenceI[sSize];
\r
608 for (int i = 0; i < alHeight && index<sSize; i++)
\r
610 if(sequences.contains( al.getSequenceAt(i) ) )
\r
611 seqs[index++] = al.getSequenceAt(i);
\r