-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-\r
-package jalview.datamodel;\r
-\r
-import java.util.*;\r
-\r
-public class HiddenSequences\r
-{\r
- Hashtable hiddenSequences;\r
- AlignmentI alignment;\r
-\r
- public HiddenSequences(AlignmentI al)\r
- {\r
- alignment = al;\r
- }\r
-\r
- public int getSize()\r
- {\r
- return hiddenSequences == null ? 0 : hiddenSequences.size();\r
- }\r
-\r
- public void hideSequence(SequenceI sequence)\r
- {\r
- if(hiddenSequences==null)\r
- hiddenSequences = new Hashtable();\r
-\r
- int alignmentIndex = alignment.findIndex(sequence);\r
- alignmentIndex = adjustForHiddenSeqs(alignmentIndex);\r
-\r
- hiddenSequences.put(new Integer(alignmentIndex), sequence);\r
-\r
- alignment.deleteSequence(sequence);\r
- }\r
-\r
- public void showSequence(int alignmentIndex)\r
- {\r
- SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);\r
- if(repSequence.getHiddenSequences()==null && alignmentIndex>0)\r
- repSequence = alignment.getSequenceAt(alignmentIndex-1);\r
- if(repSequence.getHiddenSequences()==null)\r
- repSequence = null;\r
-\r
- int start = adjustForHiddenSeqs(alignmentIndex-1);\r
- int end = adjustForHiddenSeqs(alignmentIndex);\r
-\r
- for(int index = end; index > start; index--)\r
- {\r
- SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(\r
- index));\r
-\r
- if(seq!=null)\r
- {\r
- alignment.getSequences().insertElementAt(seq, alignmentIndex);\r
- if(repSequence!=null)\r
- {\r
- repSequence.showHiddenSequence(seq);\r
- }\r
- }\r
- }\r
- }\r
-\r
- public SequenceI getHiddenSequence(int alignmentIndex)\r
- {\r
- return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));\r
- }\r
-\r
- public int findIndexWithoutHiddenSeqs(int alignmentIndex)\r
- {\r
- int index = 0;\r
- int hiddenSeqs = 0;\r
- while(index <= alignmentIndex)\r
- {\r
- if(hiddenSequences.containsKey(new Integer(index)))\r
- {\r
- hiddenSeqs ++;\r
- }\r
- index ++;\r
- };\r
-\r
- return (alignmentIndex - hiddenSeqs) ;\r
- }\r
-\r
- public int adjustForHiddenSeqs(int alignmentIndex)\r
- {\r
- int index = 0;\r
- while(index <= alignmentIndex)\r
- {\r
- if(hiddenSequences.containsKey(new Integer(index)))\r
- {\r
- alignmentIndex ++;\r
- }\r
- index ++;\r
- };\r
-\r
- return alignmentIndex ;\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.datamodel;
+
+import java.util.*;
+
+public class HiddenSequences
+{
+ Hashtable hiddenSequences;
+ AlignmentI alignment;
+
+ public HiddenSequences(AlignmentI al)
+ {
+ alignment = al;
+ }
+
+ public int getSize()
+ {
+ return hiddenSequences == null ? 0 : hiddenSequences.size();
+ }
+
+ public int getWidth()
+ {
+ Enumeration en = hiddenSequences.elements();
+ int width = 0;
+ while(en.hasMoreElements())
+ {
+ SequenceI seq = (SequenceI)en.nextElement();
+ if(seq.getLength()>width)
+ width = seq.getLength();
+ }
+ return width;
+ }
+
+ public void hideSequence(SequenceI sequence)
+ {
+ if(hiddenSequences==null)
+ hiddenSequences = new Hashtable();
+
+ int alignmentIndex = alignment.findIndex(sequence);
+ alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
+
+ hiddenSequences.put(new Integer(alignmentIndex), sequence);
+
+ alignment.deleteSequence(sequence);
+ }
+
+ public Vector showAll()
+ {
+ Vector revealedSeqs = new Vector();
+ for(int i=0; i<alignment.getHeight()+hiddenSequences.size(); i++)
+ {
+ Vector tmp = showSequence(i);
+ for(int t=0; t<tmp.size(); t++)
+ revealedSeqs.addElement(tmp.elementAt(t));
+ }
+ return revealedSeqs;
+ }
+
+ public Vector showSequence(int alignmentIndex)
+ {
+ Vector revealedSeqs = new Vector();
+ SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
+ if(repSequence!=null
+ && repSequence.getHiddenSequences()==null
+ && alignmentIndex>0)
+ repSequence = alignment.getSequenceAt(alignmentIndex-1);
+
+ if(repSequence!=null
+ && repSequence.getHiddenSequences()==null)
+ repSequence = null;
+
+ int start = adjustForHiddenSeqs(alignmentIndex-1);
+ int end = adjustForHiddenSeqs(alignmentIndex);
+
+ for(int index = end; index > start; index--)
+ {
+ SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
+ index));
+
+
+ if(seq!=null)
+ {
+ revealedSeqs.addElement(seq);
+ alignment.getSequences().insertElementAt(seq, alignmentIndex);
+ if(repSequence!=null)
+ {
+ repSequence.showHiddenSequence(seq);
+ }
+ }
+ }
+
+ return revealedSeqs;
+ }
+
+ public Hashtable getHiddenSequences()
+ {
+ return hiddenSequences;
+ }
+
+ public SequenceI getHiddenSequence(int alignmentIndex)
+ {
+ return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
+ }
+
+ public int findIndexWithoutHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ int hiddenSeqs = 0;
+ while(index <= alignmentIndex)
+ {
+ if(hiddenSequences.containsKey(new Integer(index)))
+ {
+ hiddenSeqs ++;
+ }
+ index ++;
+ };
+
+ return (alignmentIndex - hiddenSeqs) ;
+ }
+
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ while(index <= alignmentIndex)
+ {
+ if(hiddenSequences.containsKey(new Integer(index)))
+ {
+ alignmentIndex ++;
+ }
+ index ++;
+ };
+
+ return alignmentIndex ;
+ }
+
+ public AlignmentI getFullAlignment()
+ {
+ int isize = alignment.getHeight()+hiddenSequences.size();
+ SequenceI [] seq = new Sequence[isize];
+
+ Enumeration en = hiddenSequences.keys();
+ while(en.hasMoreElements())
+ {
+ Integer key = (Integer)en.nextElement();
+ seq[key.intValue()] = (SequenceI)hiddenSequences.get(key);
+ }
+
+ int index = 0;
+ for(int i=0; i<isize; i++)
+ {
+ if(seq[i]!=null)
+ {
+ continue;
+ }
+
+ seq[i] = alignment.getSequenceAt(index);
+ index++;
+ }
+
+ return new Alignment(seq);
+ }
+
+ public boolean isHidden(SequenceI seq)
+ {
+ return hiddenSequences.contains(seq);
+ }
+}