From 19e35813ebb5102a69682857bd25f46955f17cbb Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 16 Mar 2006 15:21:58 +0000 Subject: [PATCH] Gethidden sequences --- src/jalview/datamodel/HistoryItem.java | 190 +++++++++++++++++++------------- 1 file changed, 111 insertions(+), 79 deletions(-) diff --git a/src/jalview/datamodel/HistoryItem.java b/src/jalview/datamodel/HistoryItem.java index eb4979d..0520bc0 100755 --- a/src/jalview/datamodel/HistoryItem.java +++ b/src/jalview/datamodel/HistoryItem.java @@ -29,96 +29,128 @@ import java.util.*; */ public class HistoryItem { - /** DOCUMENT ME!! */ - public static final int EDIT = 0; - - /** DOCUMENT ME!! */ - public static final int SORT = 1; - - /** DOCUMENT ME!! */ - public static final int HIDE = 2; - - /** DOCUMENT ME!! */ - public static final int PASTE = 3; - final int type; - Vector sequences; - Vector alignIndex; - String description; - Vector hiddenSeqs; - - /** - * Creates a new HistoryItem object. - * - * @param description DOCUMENT ME! - * @param al DOCUMENT ME! - * @param type DOCUMENT ME! - */ - public HistoryItem(String description, AlignmentI al, int type) - { - this.type = type; - this.description = description; - sequences = new Vector(); - alignIndex = new Vector(); - hiddenSeqs = new Vector(); + /** DOCUMENT ME!! */ + public static final int EDIT = 0; - for (int i = 0; i < al.getHeight(); i++) - { - SequenceI seq = al.getSequenceAt(i); - sequences.addElement(seq); - alignIndex.addElement(i + ""); - hiddenSeqs.addElement(seq.getSequence().toString()); - } - } + /** DOCUMENT ME!! */ + public static final int SORT = 1; - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getType() - { - return type; - } + /** DOCUMENT ME!! */ + public static final int HIDE = 2; + + /** DOCUMENT ME!! */ + public static final int PASTE = 3; + + final int type; - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getSequences() + AlignmentI alignment; + String description; + + Vector sequences; + Vector seqAsString; + Vector alignIndex; + + Vector hiddenSeqs; + Vector hiddenSeqsAsString; + + + /** + * Creates a new HistoryItem object. + * + * @param description DOCUMENT ME! + * @param al DOCUMENT ME! + * @param type DOCUMENT ME! + */ + public HistoryItem(String description, AlignmentI al, int type) + { + alignment = al; + this.type = type; + this.description = description; + sequences = new Vector(); + alignIndex = new Vector(); + seqAsString = new Vector(); + + for (int i = 0; i < al.getHeight(); i++) { - return sequences; + SequenceI seq = al.getSequenceAt(i); + sequences.addElement(seq); + alignIndex.addElement(i + ""); + seqAsString.addElement(seq.getSequence().toString()); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public String getDescription() + if(alignment.getHiddenSequences()!=null + && alignment.getHiddenSequences().getSize()>0) { - return description; + hiddenSeqs = new Vector(); + hiddenSeqsAsString = new Vector(); + Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements(); + while (en.hasMoreElements()) + { + SequenceI key = (SequenceI) en.nextElement(); + hiddenSeqs.addElement(key); + hiddenSeqsAsString.addElement(key.getSequence().toString()); + } } + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String getDescription() + { + return description; + } + - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getHidden() + public void restore() + { + if (type == HistoryItem.SORT) { - return hiddenSeqs; + for (int i = 0; i < sequences.size(); i++) + { + alignment.getSequences().setElementAt(sequences.elementAt(i), i); + } } - - /** - * DOCUMENT ME! - * - * @param seq DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getAlignIndex(int seq) + else { - return Integer.parseInt(alignIndex.elementAt(seq).toString()); + + for (int i = 0; i < sequences.size(); i++) + { + SequenceI restore = (SequenceI) sequences.elementAt(i); + + if (restore.getLength() == 0) + { + //This is for edits which remove all residues in a sequence + restore.setSequence(seqAsString.elementAt(i).toString()); + alignment.getSequences().insertElementAt(restore, + Integer.parseInt(alignIndex.elementAt(i).toString())); + } + else + { + restore.setSequence(seqAsString.elementAt(i).toString()); + } + } + + if(hiddenSeqs!=null) + { + for(int hs=0; hs (sequences.size() - 1); i--) + { + alignment.deleteSequence(i); + } + } } + + } } -- 1.7.10.2