Keeps a record of hidden sequences
authoramwaterhouse <Andrew Waterhouse>
Thu, 16 Mar 2006 15:20:31 +0000 (15:20 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 16 Mar 2006 15:20:31 +0000 (15:20 +0000)
src/jalview/datamodel/HiddenSequences.java [new file with mode: 0755]

diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java
new file mode 100755 (executable)
index 0000000..3a5946c
--- /dev/null
@@ -0,0 +1,114 @@
+/*\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