2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
24 public class HiddenSequences
\r
26 public SequenceI[] hiddenSequences;
\r
27 AlignmentI alignment;
\r
29 public HiddenSequences(AlignmentI al)
\r
34 public int getSize()
\r
36 if (hiddenSequences == null)
\r
41 for (int i = 0; i < hiddenSequences.length; i++)
\r
43 if (hiddenSequences[i] != null)
\r
52 public int getWidth()
\r
55 for (int i = 0; i < hiddenSequences.length; i++)
\r
57 if (hiddenSequences[i] != null && hiddenSequences[i].getLength() > width)
\r
59 width = hiddenSequences[i].getLength();
\r
67 * Call this method if sequences are removed from the
\r
70 public void adjustHeightSequenceDeleted(int seqIndex)
\r
72 if (hiddenSequences == null)
\r
77 int alHeight = alignment.getHeight();
\r
79 SequenceI[] tmp = new SequenceI[alHeight + getSize()];
\r
80 int deletionIndex = adjustForHiddenSeqs(seqIndex);
\r
82 for (int i = 0; i < hiddenSequences.length; i++)
\r
84 if (hiddenSequences[i] == null)
\r
89 if (i > deletionIndex)
\r
91 tmp[i - 1] = hiddenSequences[i];
\r
95 tmp[i] = hiddenSequences[i];
\r
99 hiddenSequences = tmp;
\r
104 * Call this method if sequences are added to or removed from the
\r
107 public void adjustHeightSequenceAdded()
\r
109 if (hiddenSequences == null)
\r
114 int alHeight = alignment.getHeight();
\r
116 SequenceI[] tmp = new SequenceI[alHeight + getSize()];
\r
117 System.arraycopy(hiddenSequences, 0, tmp, 0, hiddenSequences.length);
\r
118 hiddenSequences = tmp;
\r
121 public void hideSequence(SequenceI sequence)
\r
123 if (hiddenSequences == null)
\r
125 hiddenSequences = new SequenceI[alignment.getHeight()];
\r
128 int alignmentIndex = alignment.findIndex(sequence);
\r
129 alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
\r
131 if (hiddenSequences[alignmentIndex] != null)
\r
133 System.out.println("ERROR!!!!!!!!!!!");
\r
136 hiddenSequences[alignmentIndex] = sequence;
\r
138 alignment.deleteSequence(sequence);
\r
141 public Vector showAll(Hashtable hiddenReps)
\r
143 Vector revealedSeqs = new Vector();
\r
144 for (int i = 0; i < hiddenSequences.length; i++)
\r
146 if (hiddenSequences[i] != null)
\r
148 Vector tmp = showSequence(i, hiddenReps);
\r
149 for (int t = 0; t < tmp.size(); t++)
\r
151 revealedSeqs.addElement(tmp.elementAt(t));
\r
155 return revealedSeqs;
\r
158 public Vector showSequence(int alignmentIndex, Hashtable hiddenReps)
\r
160 Vector revealedSeqs = new Vector();
\r
161 SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
\r
162 if (repSequence != null &&
\r
164 && hiddenReps.containsKey(repSequence))
\r
166 hiddenReps.remove(repSequence);
\r
167 revealedSeqs.addElement(repSequence);
\r
170 int start = adjustForHiddenSeqs(alignmentIndex - 1);
\r
171 int end = adjustForHiddenSeqs(alignmentIndex);
\r
172 if (end >= hiddenSequences.length)
\r
174 end = hiddenSequences.length - 1;
\r
177 for (int index = end; index > start; index--)
\r
179 SequenceI seq = hiddenSequences[index];
\r
180 hiddenSequences[index] = null;
\r
184 if (seq.getLength() > 0)
\r
186 revealedSeqs.addElement(seq);
\r
187 alignment.getSequences().insertElementAt(seq, alignmentIndex);
\r
191 System.out.println(seq.getName() + " has been deleted whilst hidden");
\r
197 return revealedSeqs;
\r
200 public SequenceI getHiddenSequence(int alignmentIndex)
\r
202 return hiddenSequences[alignmentIndex];
\r
205 public int findIndexWithoutHiddenSeqs(int alignmentIndex)
\r
208 int hiddenSeqs = 0;
\r
209 if (hiddenSequences.length <= alignmentIndex)
\r
211 alignmentIndex = hiddenSequences.length - 1;
\r
214 while (index <= alignmentIndex)
\r
216 if (hiddenSequences[index] != null)
\r
224 return (alignmentIndex - hiddenSeqs);
\r
227 public int adjustForHiddenSeqs(int alignmentIndex)
\r
230 int hSize = hiddenSequences.length;
\r
231 while (index <= alignmentIndex && index < hSize)
\r
233 if (hiddenSequences[index] != null)
\r
241 return alignmentIndex;
\r
244 public AlignmentI getFullAlignment()
\r
246 int isize = hiddenSequences.length;
\r
247 SequenceI[] seq = new Sequence[isize];
\r
250 for (int i = 0; i < hiddenSequences.length; i++)
\r
252 if (hiddenSequences[i] != null)
\r
254 seq[i] = hiddenSequences[i];
\r
258 seq[i] = alignment.getSequenceAt(index);
\r
263 return new Alignment(seq);
\r
266 public boolean isHidden(SequenceI seq)
\r
268 for (int i = 0; i < hiddenSequences.length; i++)
\r
270 if (hiddenSequences[i] != null && hiddenSequences[i] == seq)
\r