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
24 public class HiddenSequences
\r
26 Hashtable hiddenSequences;
\r
27 AlignmentI alignment;
\r
29 public HiddenSequences(AlignmentI al)
\r
34 public int getSize()
\r
36 return hiddenSequences == null ? 0 : hiddenSequences.size();
\r
39 public int getWidth()
\r
41 Enumeration en = hiddenSequences.elements();
\r
43 while(en.hasMoreElements())
\r
45 SequenceI seq = (SequenceI)en.nextElement();
\r
46 if(seq.getLength()>width)
\r
47 width = seq.getLength();
\r
52 public void hideSequence(SequenceI sequence)
\r
54 if(hiddenSequences==null)
\r
55 hiddenSequences = new Hashtable();
\r
57 int alignmentIndex = alignment.findIndex(sequence);
\r
58 alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
\r
60 hiddenSequences.put(new Integer(alignmentIndex), sequence);
\r
62 alignment.deleteSequence(sequence);
\r
65 public void showAll()
\r
67 for(int i=0; i<alignment.getHeight()+hiddenSequences.size(); i++)
\r
71 public void showSequence(int alignmentIndex)
\r
73 SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
\r
74 if(repSequence!=null
\r
75 && repSequence.getHiddenSequences()==null
\r
76 && alignmentIndex>0)
\r
77 repSequence = alignment.getSequenceAt(alignmentIndex-1);
\r
79 if(repSequence!=null
\r
80 && repSequence.getHiddenSequences()==null)
\r
83 int start = adjustForHiddenSeqs(alignmentIndex-1);
\r
84 int end = adjustForHiddenSeqs(alignmentIndex);
\r
86 for(int index = end; index > start; index--)
\r
88 SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
\r
93 alignment.getSequences().insertElementAt(seq, alignmentIndex);
\r
94 if(repSequence!=null)
\r
96 repSequence.showHiddenSequence(seq);
\r
102 public Hashtable getHiddenSequences()
\r
104 return hiddenSequences;
\r
107 public SequenceI getHiddenSequence(int alignmentIndex)
\r
109 return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
\r
112 public int findIndexWithoutHiddenSeqs(int alignmentIndex)
\r
115 int hiddenSeqs = 0;
\r
116 while(index <= alignmentIndex)
\r
118 if(hiddenSequences.containsKey(new Integer(index)))
\r
125 return (alignmentIndex - hiddenSeqs) ;
\r
128 public int adjustForHiddenSeqs(int alignmentIndex)
\r
131 while(index <= alignmentIndex)
\r
133 if(hiddenSequences.containsKey(new Integer(index)))
\r
140 return alignmentIndex ;
\r
143 public AlignmentI getFullAlignment()
\r
145 int isize = alignment.getHeight()+hiddenSequences.size();
\r
146 SequenceI [] seq = new Sequence[isize];
\r
148 Enumeration en = hiddenSequences.keys();
\r
149 while(en.hasMoreElements())
\r
151 Integer key = (Integer)en.nextElement();
\r
152 seq[key.intValue()] = (SequenceI)hiddenSequences.get(key);
\r
156 for(int i=0; i<isize; i++)
\r
163 seq[i] = alignment.getSequenceAt(index);
\r
167 return new Alignment(seq);
\r
170 public boolean isHidden(SequenceI seq)
\r
172 return hiddenSequences.contains(seq);
\r