-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 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
- public SequenceI[] hiddenSequences;\r
- AlignmentI alignment;\r
-\r
- public HiddenSequences(AlignmentI al)\r
- {\r
- alignment = al;\r
- }\r
-\r
- public int getSize()\r
- {\r
- if (hiddenSequences == null)\r
- {\r
- return 0;\r
- }\r
- int count = 0;\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] != null)\r
- {\r
- count++;\r
- }\r
- }\r
-\r
- return count;\r
- }\r
-\r
- public int getWidth()\r
- {\r
- int width = 0;\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] != null && hiddenSequences[i].getLength() > width)\r
- {\r
- width = hiddenSequences[i].getLength();\r
- }\r
- }\r
-\r
- return width;\r
- }\r
-\r
- /**\r
- * Call this method if sequences are removed from the\r
- * main alignment\r
- */\r
- public void adjustHeightSequenceDeleted(int seqIndex)\r
- {\r
- if (hiddenSequences == null)\r
- {\r
- return;\r
- }\r
-\r
- int alHeight = alignment.getHeight();\r
-\r
- SequenceI[] tmp = new SequenceI[alHeight + getSize()];\r
- int deletionIndex = adjustForHiddenSeqs(seqIndex);\r
-\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] == null)\r
- {\r
- continue;\r
- }\r
-\r
- if (i > deletionIndex)\r
- {\r
- tmp[i - 1] = hiddenSequences[i];\r
- }\r
- else\r
- {\r
- tmp[i] = hiddenSequences[i];\r
- }\r
- }\r
-\r
- hiddenSequences = tmp;\r
-\r
- }\r
-\r
- /**\r
- * Call this method if sequences are added to or removed from the\r
- * main alignment\r
- */\r
- public void adjustHeightSequenceAdded()\r
- {\r
- if (hiddenSequences == null)\r
- {\r
- return;\r
- }\r
-\r
- int alHeight = alignment.getHeight();\r
-\r
- SequenceI[] tmp = new SequenceI[alHeight + getSize()];\r
- System.arraycopy(hiddenSequences, 0, tmp, 0, hiddenSequences.length);\r
- hiddenSequences = tmp;\r
- }\r
-\r
- public void hideSequence(SequenceI sequence)\r
- {\r
- if (hiddenSequences == null)\r
- {\r
- hiddenSequences = new SequenceI[alignment.getHeight()];\r
- }\r
-\r
- int alignmentIndex = alignment.findIndex(sequence);\r
- alignmentIndex = adjustForHiddenSeqs(alignmentIndex);\r
-\r
- if (hiddenSequences[alignmentIndex] != null)\r
- {\r
- System.out.println("ERROR!!!!!!!!!!!");\r
- }\r
-\r
- hiddenSequences[alignmentIndex] = sequence;\r
-\r
- alignment.deleteSequence(sequence);\r
- }\r
-\r
- public Vector showAll(Hashtable hiddenReps)\r
- {\r
- Vector revealedSeqs = new Vector();\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] != null)\r
- {\r
- Vector tmp = showSequence(i, hiddenReps);\r
- for (int t = 0; t < tmp.size(); t++)\r
- {\r
- revealedSeqs.addElement(tmp.elementAt(t));\r
- }\r
- }\r
- }\r
- return revealedSeqs;\r
- }\r
-\r
- public Vector showSequence(int alignmentIndex, Hashtable hiddenReps)\r
- {\r
- Vector revealedSeqs = new Vector();\r
- SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);\r
- if (repSequence != null &&\r
- hiddenReps != null\r
- && hiddenReps.containsKey(repSequence))\r
- {\r
- hiddenReps.remove(repSequence);\r
- revealedSeqs.addElement(repSequence);\r
- }\r
-\r
- int start = adjustForHiddenSeqs(alignmentIndex - 1);\r
- int end = adjustForHiddenSeqs(alignmentIndex);\r
- if (end >= hiddenSequences.length)\r
- {\r
- end = hiddenSequences.length - 1;\r
- }\r
-\r
- for (int index = end; index > start; index--)\r
- {\r
- SequenceI seq = hiddenSequences[index];\r
- hiddenSequences[index] = null;\r
-\r
- if (seq != null)\r
- {\r
- if (seq.getLength() > 0)\r
- {\r
- revealedSeqs.addElement(seq);\r
- alignment.getSequences().insertElementAt(seq, alignmentIndex);\r
- }\r
- else\r
- {\r
- System.out.println(seq.getName() + " has been deleted whilst hidden");\r
- }\r
- }\r
-\r
- }\r
-\r
- return revealedSeqs;\r
- }\r
-\r
- public SequenceI getHiddenSequence(int alignmentIndex)\r
- {\r
- return hiddenSequences[alignmentIndex];\r
- }\r
-\r
- public int findIndexWithoutHiddenSeqs(int alignmentIndex)\r
- {\r
- int index = 0;\r
- int hiddenSeqs = 0;\r
- if (hiddenSequences.length <= alignmentIndex)\r
- {\r
- alignmentIndex = hiddenSequences.length - 1;\r
- }\r
-\r
- while (index <= alignmentIndex)\r
- {\r
- if (hiddenSequences[index] != null)\r
- {\r
- hiddenSeqs++;\r
- }\r
- index++;\r
- }\r
- ;\r
-\r
- return (alignmentIndex - hiddenSeqs);\r
- }\r
-\r
- public int adjustForHiddenSeqs(int alignmentIndex)\r
- {\r
- int index = 0;\r
- int hSize = hiddenSequences.length;\r
- while (index <= alignmentIndex && index < hSize)\r
- {\r
- if (hiddenSequences[index] != null)\r
- {\r
- alignmentIndex++;\r
- }\r
- index++;\r
- }\r
- ;\r
-\r
- return alignmentIndex;\r
- }\r
-\r
- public AlignmentI getFullAlignment()\r
- {\r
- int isize = hiddenSequences.length;\r
- SequenceI[] seq = new Sequence[isize];\r
-\r
- int index = 0;\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] != null)\r
- {\r
- seq[i] = hiddenSequences[i];\r
- }\r
- else\r
- {\r
- seq[i] = alignment.getSequenceAt(index);\r
- index++;\r
- }\r
- }\r
-\r
- return new Alignment(seq);\r
- }\r
-\r
- public boolean isHidden(SequenceI seq)\r
- {\r
- for (int i = 0; i < hiddenSequences.length; i++)\r
- {\r
- if (hiddenSequences[i] != null && hiddenSequences[i] == seq)\r
- {\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 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
+{
+ /**
+ * holds a list of hidden sequences associated with an alignment.
+ */
+ public SequenceI[] hiddenSequences;
+ AlignmentI alignment;
+
+ public HiddenSequences(AlignmentI al)
+ {
+ alignment = al;
+ }
+
+ public int getSize()
+ {
+ if (hiddenSequences == null)
+ {
+ return 0;
+ }
+ int count = 0;
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] != null)
+ {
+ count++;
+ }
+ }
+
+ return count;
+ }
+
+ public int getWidth()
+ {
+ int width = 0;
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] != null && hiddenSequences[i].getLength() > width)
+ {
+ width = hiddenSequences[i].getLength();
+ }
+ }
+
+ return width;
+ }
+
+ /**
+ * Call this method if sequences are removed from the
+ * main alignment
+ */
+ public void adjustHeightSequenceDeleted(int seqIndex)
+ {
+ if (hiddenSequences == null)
+ {
+ return;
+ }
+
+ int alHeight = alignment.getHeight();
+
+ SequenceI[] tmp = new SequenceI[alHeight + getSize()];
+ int deletionIndex = adjustForHiddenSeqs(seqIndex);
+
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] == null)
+ {
+ continue;
+ }
+
+ if (i > deletionIndex)
+ {
+ tmp[i - 1] = hiddenSequences[i];
+ }
+ else
+ {
+ tmp[i] = hiddenSequences[i];
+ }
+ }
+
+ hiddenSequences = tmp;
+
+ }
+
+ /**
+ * Call this method if sequences are added to or removed from the
+ * main alignment
+ */
+ public void adjustHeightSequenceAdded()
+ {
+ if (hiddenSequences == null)
+ {
+ return;
+ }
+
+ int alHeight = alignment.getHeight();
+
+ SequenceI[] tmp = new SequenceI[alHeight + getSize()];
+ System.arraycopy(hiddenSequences, 0, tmp, 0, hiddenSequences.length);
+ hiddenSequences = tmp;
+ }
+
+ public void hideSequence(SequenceI sequence)
+ {
+ if (hiddenSequences == null)
+ {
+ hiddenSequences = new SequenceI[alignment.getHeight()];
+ }
+
+ int alignmentIndex = alignment.findIndex(sequence);
+ alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
+
+ if (hiddenSequences[alignmentIndex] != null)
+ {
+ System.out.println("ERROR!!!!!!!!!!!");
+ }
+
+ hiddenSequences[alignmentIndex] = sequence;
+
+ alignment.deleteSequence(sequence);
+ }
+
+ public Vector showAll(Hashtable hiddenReps)
+ {
+ Vector revealedSeqs = new Vector();
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] != null)
+ {
+ Vector tmp = showSequence(i, hiddenReps);
+ for (int t = 0; t < tmp.size(); t++)
+ {
+ revealedSeqs.addElement(tmp.elementAt(t));
+ }
+ }
+ }
+ return revealedSeqs;
+ }
+
+ public Vector showSequence(int alignmentIndex, Hashtable hiddenReps)
+ {
+ Vector revealedSeqs = new Vector();
+ SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
+ if (repSequence != null &&
+ hiddenReps != null
+ && hiddenReps.containsKey(repSequence))
+ {
+ hiddenReps.remove(repSequence);
+ revealedSeqs.addElement(repSequence);
+ }
+
+ int start = adjustForHiddenSeqs(alignmentIndex - 1);
+ int end = adjustForHiddenSeqs(alignmentIndex);
+ if (end >= hiddenSequences.length)
+ {
+ end = hiddenSequences.length - 1;
+ }
+
+ for (int index = end; index > start; index--)
+ {
+ SequenceI seq = hiddenSequences[index];
+ hiddenSequences[index] = null;
+
+ if (seq != null)
+ {
+ if (seq.getLength() > 0)
+ {
+ revealedSeqs.addElement(seq);
+ alignment.getSequences().insertElementAt(seq, alignmentIndex);
+ }
+ else
+ {
+ System.out.println(seq.getName() + " has been deleted whilst hidden");
+ }
+ }
+
+ }
+
+ return revealedSeqs;
+ }
+
+ public SequenceI getHiddenSequence(int alignmentIndex)
+ {
+ return hiddenSequences[alignmentIndex];
+ }
+
+ public int findIndexWithoutHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ int hiddenSeqs = 0;
+ if (hiddenSequences.length <= alignmentIndex)
+ {
+ alignmentIndex = hiddenSequences.length - 1;
+ }
+
+ while (index <= alignmentIndex)
+ {
+ if (hiddenSequences[index] != null)
+ {
+ hiddenSeqs++;
+ }
+ index++;
+ }
+ ;
+
+ return (alignmentIndex - hiddenSeqs);
+ }
+
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ int index = 0;
+ int hSize = hiddenSequences.length;
+ while (index <= alignmentIndex && index < hSize)
+ {
+ if (hiddenSequences[index] != null)
+ {
+ alignmentIndex++;
+ }
+ index++;
+ }
+ ;
+
+ return alignmentIndex;
+ }
+
+ public AlignmentI getFullAlignment()
+ {
+ int isize = hiddenSequences.length;
+ SequenceI[] seq = new Sequence[isize];
+
+ int index = 0;
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] != null)
+ {
+ seq[i] = hiddenSequences[i];
+ }
+ else
+ {
+ seq[i] = alignment.getSequenceAt(index);
+ index++;
+ }
+ }
+
+ return new Alignment(seq);
+ }
+
+ public boolean isHidden(SequenceI seq)
+ {
+ for (int i = 0; i < hiddenSequences.length; i++)
+ {
+ if (hiddenSequences[i] != null && hiddenSequences[i] == seq)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}