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
20 package jalview.datamodel;
\r
22 import jalview.schemes.*;
\r
23 import jalview.analysis.*;
\r
24 import jalview.datamodel.*;
\r
25 import java.util.Vector;
\r
28 public class SequenceGroup
\r
31 Conservation conserve;
\r
33 boolean displayBoxes;
\r
34 boolean displayText;
\r
36 public Vector sequences = new Vector();
\r
38 public ColourSchemeI cs;
\r
41 Color outlineColour = Color.black;
\r
43 public SequenceGroup()
\r
45 groupName = "Group";
\r
46 this.displayBoxes = true;
\r
47 this.displayText = true;
\r
48 this.colourText = false;
\r
52 public SequenceGroup(String groupName, ColourSchemeI scheme,
\r
53 boolean displayBoxes, boolean displayText,
\r
59 this.groupName = groupName;
\r
60 this.displayBoxes = displayBoxes;
\r
61 this.displayText = displayText;
\r
62 this.colourText = colourText;
\r
68 public boolean adjustForRemoveLeft(int col)
\r
70 // return value is true if the group still exists
\r
72 startRes = startRes - col;
\r
75 endRes = endRes - col;
\r
81 // must delete this group!!
\r
88 public boolean adjustForRemoveRight(int col)
\r
93 // delete this group
\r
104 public String getName()
\r
109 public void setName(String name)
\r
114 public Conservation getConservation()
\r
119 public void setConservation(Conservation c)
\r
124 public void addSequence(SequenceI s)
\r
126 if(!sequences.contains(s))
\r
127 sequences.addElement(s);
\r
131 cs.setConsensus( AAFrequency.calculate(sequences, 0, getWidth()) );
\r
133 if(cs instanceof ConservationColourScheme)
\r
134 recalcConservation();
\r
137 void recalcConservation()
\r
139 Conservation c = new Conservation(groupName,
\r
140 ResidueProperties.propHash, 3,
\r
141 sequences, 0, getWidth());
\r
143 c.verdict(false, 25);
\r
144 ConservationColourScheme ccs = (ConservationColourScheme)cs;
\r
148 public void addOrRemove(SequenceI s)
\r
150 if(sequences.contains(s))
\r
156 public void deleteSequence(SequenceI s)
\r
158 sequences.removeElement(s);
\r
161 cs.setConsensus( AAFrequency.calculate(sequences, 0, getWidth()) );
\r
163 if(cs instanceof ConservationColourScheme)
\r
164 recalcConservation();
\r
168 public int getStartRes()
\r
173 public int getEndRes()
\r
178 public void setStartRes(int i)
\r
183 public void setEndRes(int i)
\r
188 public int getSize()
\r
190 return sequences.size();
\r
193 public SequenceI getSequenceAt(int i)
\r
195 return (SequenceI) sequences.elementAt(i);
\r
198 public void setColourText(boolean state)
\r
200 colourText = state;
\r
203 public boolean getColourText()
\r
208 public void setDisplayText(boolean state)
\r
210 displayText = state;
\r
213 public boolean getDisplayText()
\r
215 return displayText;
\r
218 public void setDisplayBoxes(boolean state)
\r
220 displayBoxes = state;
\r
223 public boolean getDisplayBoxes()
\r
225 return displayBoxes;
\r
228 public int getWidth()
\r
230 // MC This needs to get reset when characters are inserted and deleted
\r
231 if (sequences.size()>0)
\r
232 width = ((SequenceI) sequences.elementAt(0)).getLength();
\r
233 for (int i = 1; i < sequences.size(); i++)
\r
235 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
236 if (seq.getLength() > width)
\r
237 width = seq.getLength();
\r
243 public void setOutlineColour(Color c)
\r
247 public Color getOutlineColour()
\r
249 return outlineColour;
\r
253 * returns the sequences in the group ordered by the ordering given by al
\r
255 * @param al Alignment
\r
256 * @return SequenceI[]
\r
258 public SequenceI[] getSequencesInOrder(Alignment al) {
\r
260 java.util.Hashtable orderedSeqs = new java.util.Hashtable();
\r
261 SequenceI[] seqs=new SequenceI[sz=sequences.size()];
\r
262 for(int i=0; i<sz; i++)
\r
264 SequenceI seq = (SequenceI) sequences.elementAt(i);
\r
265 int index = al.findIndex(seq);
\r
266 orderedSeqs.put(index+"", seq);
\r
270 for(int i=0; i<sz; i++) {
\r
271 SequenceI seq = null;
\r
272 while (seq == null)
\r
274 if (orderedSeqs.containsKey(index + ""))
\r
276 seq = (SequenceI) orderedSeqs.get(index + "");
\r