/* * 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 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 void showAll() { 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) { alignment.getSequences().insertElementAt(seq, alignmentIndex); if(repSequence!=null) { repSequence.showHiddenSequence(seq); } } } } 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