From ad85c28d8fbb6419ff66527d6b4feb1063f26927 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 16 Mar 2006 15:20:31 +0000 Subject: [PATCH] Keeps a record of hidden sequences --- src/jalview/datamodel/HiddenSequences.java | 114 ++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 src/jalview/datamodel/HiddenSequences.java diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java new file mode 100755 index 0000000..3a5946c --- /dev/null +++ b/src/jalview/datamodel/HiddenSequences.java @@ -0,0 +1,114 @@ +/* + * 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 ; + } +} -- 1.7.10.2