2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import java.util.ArrayList;
24 import java.util.List;
27 public class HiddenSequences
30 * holds a list of hidden sequences associated with an alignment.
32 public SequenceI[] hiddenSequences;
36 public HiddenSequences(AlignmentI al)
43 if (hiddenSequences == null)
48 for (int i = 0; i < hiddenSequences.length; i++)
50 if (hiddenSequences[i] != null)
62 for (int i = 0; i < hiddenSequences.length; i++)
64 if (hiddenSequences[i] != null
65 && hiddenSequences[i].getLength() > width)
67 width = hiddenSequences[i].getLength();
75 * Call this method if sequences are removed from the main alignment
77 public void adjustHeightSequenceDeleted(int seqIndex)
79 if (hiddenSequences == null)
84 int alHeight = alignment.getHeight();
86 SequenceI[] tmp = new SequenceI[alHeight + getSize()];
87 int deletionIndex = adjustForHiddenSeqs(seqIndex);
89 for (int i = 0; i < hiddenSequences.length; i++)
91 if (hiddenSequences[i] == null)
96 if (i > deletionIndex)
98 tmp[i - 1] = hiddenSequences[i];
102 tmp[i] = hiddenSequences[i];
106 hiddenSequences = tmp;
111 * Call this method if sequences are added to or removed from the main
114 public void adjustHeightSequenceAdded()
116 if (hiddenSequences == null)
121 int alHeight = alignment.getHeight();
123 SequenceI[] tmp = new SequenceI[alHeight + getSize()];
124 System.arraycopy(hiddenSequences, 0, tmp, 0, hiddenSequences.length);
125 hiddenSequences = tmp;
128 public void hideSequence(SequenceI sequence)
130 if (hiddenSequences == null)
132 hiddenSequences = new SequenceI[alignment.getHeight()];
135 int alignmentIndex = alignment.findIndex(sequence);
136 alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
138 if (hiddenSequences[alignmentIndex] != null)
140 System.out.println("ERROR!!!!!!!!!!!");
143 hiddenSequences[alignmentIndex] = sequence;
145 alignment.deleteSequence(sequence);
148 public List<SequenceI> showAll(
149 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
151 List<SequenceI> revealedSeqs = new ArrayList<SequenceI>();
152 for (int i = 0; i < hiddenSequences.length; i++)
154 if (hiddenSequences[i] != null)
156 List<SequenceI> tmp = showSequence(i, hiddenRepSequences);
157 for (SequenceI seq : tmp)
159 revealedSeqs.add(seq);
166 public List<SequenceI> showSequence(int alignmentIndex,
167 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
169 List<SequenceI> revealedSeqs = new ArrayList<SequenceI>();
170 SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
171 if (repSequence != null && hiddenRepSequences != null
172 && hiddenRepSequences.containsKey(repSequence))
174 hiddenRepSequences.remove(repSequence);
175 revealedSeqs.add(repSequence);
178 int start = adjustForHiddenSeqs(alignmentIndex - 1);
179 int end = adjustForHiddenSeqs(alignmentIndex);
180 if (end >= hiddenSequences.length)
182 end = hiddenSequences.length - 1;
185 List<SequenceI> asequences;
186 synchronized (asequences = alignment.getSequences())
188 for (int index = end; index > start; index--)
190 SequenceI seq = hiddenSequences[index];
191 hiddenSequences[index] = null;
195 if (seq.getLength() > 0)
197 revealedSeqs.add(seq);
198 asequences.add(alignmentIndex, seq);
202 System.out.println(seq.getName()
203 + " has been deleted whilst hidden");
213 public SequenceI getHiddenSequence(int alignmentIndex)
215 return hiddenSequences[alignmentIndex];
218 public int findIndexWithoutHiddenSeqs(int alignmentIndex)
222 if (hiddenSequences.length <= alignmentIndex)
224 alignmentIndex = hiddenSequences.length - 1;
227 while (index <= alignmentIndex)
229 if (hiddenSequences[index] != null)
237 return (alignmentIndex - hiddenSeqs);
240 public int adjustForHiddenSeqs(int alignmentIndex)
243 int hSize = hiddenSequences.length;
244 while (index <= alignmentIndex && index < hSize)
246 if (hiddenSequences[index] != null)
254 return alignmentIndex;
257 public AlignmentI getFullAlignment()
259 int isize = hiddenSequences.length;
260 SequenceI[] seq = new Sequence[isize];
263 for (int i = 0; i < hiddenSequences.length; i++)
265 if (hiddenSequences[i] != null)
267 seq[i] = hiddenSequences[i];
271 seq[i] = alignment.getSequenceAt(index);
275 Alignment fAlignmt = new Alignment(seq);
276 fAlignmt.annotations = alignment.getAlignmentAnnotation();
277 fAlignmt.alignmentProperties = alignment.getProperties();
278 fAlignmt.groups = alignment.getGroups();
279 fAlignmt.hasRNAStructure = alignment.hasRNAStructure();
284 public boolean isHidden(SequenceI seq)
286 if (hiddenSequences != null)
288 for (int i = 0; i < hiddenSequences.length; i++)
290 if (hiddenSequences[i] != null && hiddenSequences[i] == seq)