2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.datamodel;
24 public class HiddenSequences
26 Hashtable hiddenSequences;
29 public HiddenSequences(AlignmentI al)
36 return hiddenSequences == null ? 0 : hiddenSequences.size();
41 Enumeration en = hiddenSequences.elements();
43 while(en.hasMoreElements())
45 SequenceI seq = (SequenceI)en.nextElement();
46 if(seq.getLength()>width)
47 width = seq.getLength();
52 public void hideSequence(SequenceI sequence)
54 if(hiddenSequences==null)
55 hiddenSequences = new Hashtable();
57 int alignmentIndex = alignment.findIndex(sequence);
58 alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
60 hiddenSequences.put(new Integer(alignmentIndex), sequence);
62 alignment.deleteSequence(sequence);
65 public Vector showAll()
67 Vector revealedSeqs = new Vector();
68 for(int i=0; i<alignment.getHeight()+hiddenSequences.size(); i++)
70 Vector tmp = showSequence(i);
71 for(int t=0; t<tmp.size(); t++)
72 revealedSeqs.addElement(tmp.elementAt(t));
77 public Vector showSequence(int alignmentIndex)
79 Vector revealedSeqs = new Vector();
80 SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
82 && repSequence.getHiddenSequences()==null
84 repSequence = alignment.getSequenceAt(alignmentIndex-1);
87 && repSequence.getHiddenSequences()==null)
90 int start = adjustForHiddenSeqs(alignmentIndex-1);
91 int end = adjustForHiddenSeqs(alignmentIndex);
93 for(int index = end; index > start; index--)
95 SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
101 revealedSeqs.addElement(seq);
102 alignment.getSequences().insertElementAt(seq, alignmentIndex);
103 if(repSequence!=null)
105 repSequence.showHiddenSequence(seq);
113 public Hashtable getHiddenSequences()
115 return hiddenSequences;
118 public SequenceI getHiddenSequence(int alignmentIndex)
120 return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
123 public int findIndexWithoutHiddenSeqs(int alignmentIndex)
127 while(index <= alignmentIndex)
129 if(hiddenSequences.containsKey(new Integer(index)))
136 return (alignmentIndex - hiddenSeqs) ;
139 public int adjustForHiddenSeqs(int alignmentIndex)
142 while(index <= alignmentIndex)
144 if(hiddenSequences.containsKey(new Integer(index)))
151 return alignmentIndex ;
154 public AlignmentI getFullAlignment()
156 int isize = alignment.getHeight()+hiddenSequences.size();
157 SequenceI [] seq = new Sequence[isize];
159 Enumeration en = hiddenSequences.keys();
160 while(en.hasMoreElements())
162 Integer key = (Integer)en.nextElement();
163 seq[key.intValue()] = (SequenceI)hiddenSequences.get(key);
167 for(int i=0; i<isize; i++)
174 seq[i] = alignment.getSequenceAt(index);
178 return new Alignment(seq);
181 public boolean isHidden(SequenceI seq)
183 return hiddenSequences.contains(seq);