X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHiddenSequences.java;h=be7dbe209481c7a6c6e1ee36fc14581bc47e7071;hb=e894eb87d40be6e8452d19032ddffe80dad5f804;hp=3a5946c0552982ff91b3073c413881879b9552c7;hpb=0f71bfca98457c30f1051f142c31b6aaa3e23ead;p=jalview.git diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index 3a5946c..be7dbe2 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -1,114 +1,185 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 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 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 void showSequence(int alignmentIndex) - { - SequenceI repSequence = alignment.getSequenceAt(alignmentIndex); - if(repSequence.getHiddenSequences()==null && alignmentIndex>0) - repSequence = alignment.getSequenceAt(alignmentIndex-1); - if(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) - { - alignment.getSequences().insertElementAt(seq, alignmentIndex); - if(repSequence!=null) - { - repSequence.showHiddenSequence(seq); - } - } - } - } - - 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 ; - } -} +/* + * 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; i0) + 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