From 608832fec5a504b4c56e5837b2b3dfc1993fe734 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 21 Aug 2006 13:03:28 +0000 Subject: [PATCH] removeGaps method can record changes in alignment columns to pass to ColumnSelection --- src/jalview/datamodel/Alignment.java | 18 +- src/jalview/datamodel/AlignmentI.java | 563 ++++++++++++++-------------- src/jalview/datamodel/ColumnSelection.java | 48 ++- 3 files changed, 346 insertions(+), 283 deletions(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index c839271..62852a2 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -172,11 +172,17 @@ public class Alignment implements AlignmentI { return groups; } - /** Takes out columns consisting entirely of gaps (-,.," ") */ - public void removeGaps() - { + public void removeGaps() { + removeGaps((ShiftList)null); + } + /** + * remove gaps in alignment - recording any frame shifts in shiftrecord + * intended to be passed to ColumnSelection.compensateForEdits(shiftrecord) + * @param shiftrecord + */ + public void removeGaps(ShiftList shiftrecord) { SequenceI[] seqs = getVisibleAndRepresentedSeqs(); int j, jSize = seqs.length; @@ -219,6 +225,9 @@ public class Alignment implements AlignmentI if (!delete && startCol > -1) { deleteColumns(seqs, startCol, endCol); + if (shiftrecord!=null) { + shiftrecord.addShift(startCol, 1+endCol-startCol); + } width -= (endCol - startCol); i -= (endCol - startCol); startCol = -1; @@ -229,6 +238,9 @@ public class Alignment implements AlignmentI if (delete && startCol > -1) { deleteColumns(seqs, startCol, endCol); + if (shiftrecord!=null) { + shiftrecord.addShift(startCol, 1+endCol-startCol); + } } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index e7b5ffb..4e5987d 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -1,279 +1,284 @@ -/* -* 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.*; - - -/** Data structure to hold and manipulate a multiple sequence alignment - */ -public interface AlignmentI -{ - /** - * Calculates the number of sequences in an alignment - * - * @return Number of sequences in alignment - */ - public int getHeight(); - - /** - * Calculates the maximum width of the alignment, including gaps. - * - * @return Greatest sequence length within alignment. - */ - public int getWidth(); - - /** - * Calculates the longest sequence Id of the alignment - * - * @return Number of characters in longest sequence Id. - */ - public int getMaxIdLength(); - - /** - * Calculates if this set of sequences is all the same length - * - * @return true if all sequences in alignment are the same length - */ - public boolean isAligned(); - - /** - * Gets sequences as a Vector - * - * @return All sequences in alignment. - */ - public Vector getSequences(); - - /** - * Gets sequences as a SequenceI[] - * - * @return All sequences in alignment. - */ - public SequenceI [] getSequencesArray(); - - /** - * Find a specific sequence in this alignment. - * - * @param i Index of required sequence. - * - * @return SequenceI at given index. - */ - public SequenceI getSequenceAt(int i); - - /** - * Add a new sequence to this alignment. - * - * @param seq New sequence will be added at end of alignment. - */ - public void addSequence(SequenceI seq); - - /** - * Used to set a particular index of the alignment with the given sequence. - * - * @param i Index of sequence to be updated. - * @param seq New sequence to be inserted. - */ - public void setSequenceAt(int i, SequenceI seq); - - /** - * Deletes a sequence from the alignment. - * - * @param s Sequence to be deleted. - */ - public void deleteSequence(SequenceI s); - - /** - * Deletes a sequence from the alignment. - * - * @param i Index of sequence to be deleted. - */ - public void deleteSequence(int i); - - /** - * Deletes all residues in every sequence of alignment within given columns. - * - * @param start Start index of columns to delete. - * @param end End index to columns to delete. - */ - public void deleteColumns(SequenceI seqs [], int start, int end); - - - /** - * Finds sequence in alignment using sequence name as query. - * - * @param name Id of sequence to search for. - * - * @return Sequence matching query, if found. If not found returns null. - */ - public SequenceI findName(String name); - - public SequenceI [] findSequenceMatch(String name); - - /** - * Finds index of a given sequence in the alignment. - * - * @param s Sequence to look for. - * - * @return Index of sequence within the alignment. - */ - public int findIndex(SequenceI s); - - /** - * All sequences will be cut from beginning to given index. - * - * @param i Remove all residues in sequences up to this column. - */ - public void trimLeft(int i); - - /** - * All sequences will be cut from given index. - * - * @param i Remove all residues in sequences beyond this column. - */ - public void trimRight(int i); - - /** - * Removes all columns containing entirely gap characters. - */ - public void removeGaps(); - - - - /** - * Finds group that given sequence is part of. - * - * @param s Sequence in alignment. - * - * @return First group found for sequence. WARNING : - * Sequences may be members of several groups. This method is incomplete. - */ - public SequenceGroup findGroup(SequenceI s); - - /** - * Finds all groups that a given sequence is part of. - * - * @param s Sequence in alignment. - * - * @return All groups containing given sequence. - */ - public SequenceGroup[] findAllGroups(SequenceI s); - - /** - * Adds a new SequenceGroup to this alignment. - * - * @param sg New group to be added. - */ - public void addGroup(SequenceGroup sg); - - /** - * Deletes a specific SequenceGroup - * - * @param g Group will be deleted from alignment. - */ - public void deleteGroup(SequenceGroup g); - - /** - * Get all the groups associated with this alignment. - * - * @return All groups as a Vector. - */ - public Vector getGroups(); - - /** - * Deletes all groups from this alignment. - */ - public void deleteAllGroups(); - - - /** - * Adds a new AlignmentAnnotation to this alignment - */ - public void addAnnotation(AlignmentAnnotation aa); - - - public void setAnnotationIndex(AlignmentAnnotation aa, int index); - - /** - * Deletes a specific AlignmentAnnotation from the alignment. - * - * @param aa DOCUMENT ME! - */ - public void deleteAnnotation(AlignmentAnnotation aa); - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public AlignmentAnnotation[] getAlignmentAnnotation(); - - /** - * DOCUMENT ME! - * - * @param gc DOCUMENT ME! - */ - public void setGapCharacter(char gc); - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public char getGapCharacter(); - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getAAFrequency(); - - /** - * Returns true if alignment is nucleotide sequence - * - * @return DOCUMENT ME! - */ - public boolean isNucleotide(); - - /** - * Set true if the alignment is a nucleotide sequence - * - * @return - */ - public void setNucleotide(boolean b); - - - public Alignment getDataset(); - - public void setDataset(Alignment dataset); - /** - * pads sequences with gaps (to ensure the set looks like an alignment) - * @return boolean true if alignment was modified - */ - public boolean padGaps(); - - public void adjustSequenceAnnotations(); - - public HiddenSequences getHiddenSequences(); - /** - * Compact representation of alignment - * @return CigarArray - */ - public CigarArray getCompactAlignment(); -} +/* +* 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 jalview.util.ShiftList; + +import java.util.*; + + +/** Data structure to hold and manipulate a multiple sequence alignment + */ +public interface AlignmentI +{ + /** + * Calculates the number of sequences in an alignment + * + * @return Number of sequences in alignment + */ + public int getHeight(); + + /** + * Calculates the maximum width of the alignment, including gaps. + * + * @return Greatest sequence length within alignment. + */ + public int getWidth(); + + /** + * Calculates the longest sequence Id of the alignment + * + * @return Number of characters in longest sequence Id. + */ + public int getMaxIdLength(); + + /** + * Calculates if this set of sequences is all the same length + * + * @return true if all sequences in alignment are the same length + */ + public boolean isAligned(); + + /** + * Gets sequences as a Vector + * + * @return All sequences in alignment. + */ + public Vector getSequences(); + + /** + * Gets sequences as a SequenceI[] + * + * @return All sequences in alignment. + */ + public SequenceI [] getSequencesArray(); + + /** + * Find a specific sequence in this alignment. + * + * @param i Index of required sequence. + * + * @return SequenceI at given index. + */ + public SequenceI getSequenceAt(int i); + + /** + * Add a new sequence to this alignment. + * + * @param seq New sequence will be added at end of alignment. + */ + public void addSequence(SequenceI seq); + + /** + * Used to set a particular index of the alignment with the given sequence. + * + * @param i Index of sequence to be updated. + * @param seq New sequence to be inserted. + */ + public void setSequenceAt(int i, SequenceI seq); + + /** + * Deletes a sequence from the alignment. + * + * @param s Sequence to be deleted. + */ + public void deleteSequence(SequenceI s); + + /** + * Deletes a sequence from the alignment. + * + * @param i Index of sequence to be deleted. + */ + public void deleteSequence(int i); + + /** + * Deletes all residues in every sequence of alignment within given columns. + * + * @param start Start index of columns to delete. + * @param end End index to columns to delete. + */ + public void deleteColumns(SequenceI seqs [], int start, int end); + + + /** + * Finds sequence in alignment using sequence name as query. + * + * @param name Id of sequence to search for. + * + * @return Sequence matching query, if found. If not found returns null. + */ + public SequenceI findName(String name); + + public SequenceI [] findSequenceMatch(String name); + + /** + * Finds index of a given sequence in the alignment. + * + * @param s Sequence to look for. + * + * @return Index of sequence within the alignment. + */ + public int findIndex(SequenceI s); + + /** + * All sequences will be cut from beginning to given index. + * + * @param i Remove all residues in sequences up to this column. + */ + public void trimLeft(int i); + + /** + * All sequences will be cut from given index. + * + * @param i Remove all residues in sequences beyond this column. + */ + public void trimRight(int i); + + /** + * Removes all columns containing entirely gap characters. + */ + public void removeGaps(); + /** + * remove gaps in alignment - recording any frame shifts in shiftrecord + * @param shiftrecord + */ + public void removeGaps(ShiftList shiftrecord); + + /** + * Finds group that given sequence is part of. + * + * @param s Sequence in alignment. + * + * @return First group found for sequence. WARNING : + * Sequences may be members of several groups. This method is incomplete. + */ + public SequenceGroup findGroup(SequenceI s); + + /** + * Finds all groups that a given sequence is part of. + * + * @param s Sequence in alignment. + * + * @return All groups containing given sequence. + */ + public SequenceGroup[] findAllGroups(SequenceI s); + + /** + * Adds a new SequenceGroup to this alignment. + * + * @param sg New group to be added. + */ + public void addGroup(SequenceGroup sg); + + /** + * Deletes a specific SequenceGroup + * + * @param g Group will be deleted from alignment. + */ + public void deleteGroup(SequenceGroup g); + + /** + * Get all the groups associated with this alignment. + * + * @return All groups as a Vector. + */ + public Vector getGroups(); + + /** + * Deletes all groups from this alignment. + */ + public void deleteAllGroups(); + + + /** + * Adds a new AlignmentAnnotation to this alignment + */ + public void addAnnotation(AlignmentAnnotation aa); + + + public void setAnnotationIndex(AlignmentAnnotation aa, int index); + + /** + * Deletes a specific AlignmentAnnotation from the alignment. + * + * @param aa DOCUMENT ME! + */ + public void deleteAnnotation(AlignmentAnnotation aa); + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AlignmentAnnotation[] getAlignmentAnnotation(); + + /** + * DOCUMENT ME! + * + * @param gc DOCUMENT ME! + */ + public void setGapCharacter(char gc); + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public char getGapCharacter(); + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Vector getAAFrequency(); + + /** + * Returns true if alignment is nucleotide sequence + * + * @return DOCUMENT ME! + */ + public boolean isNucleotide(); + + /** + * Set true if the alignment is a nucleotide sequence + * + * @return + */ + public void setNucleotide(boolean b); + + + public Alignment getDataset(); + + public void setDataset(Alignment dataset); + /** + * pads sequences with gaps (to ensure the set looks like an alignment) + * @return boolean true if alignment was modified + */ + public boolean padGaps(); + + public void adjustSequenceAnnotations(); + + public HiddenSequences getHiddenSequences(); + /** + * Compact representation of alignment + * @return CigarArray + */ + public CigarArray getCompactAlignment(); +} diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 3421c41..6b9f28d 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -18,6 +18,8 @@ */ package jalview.datamodel; +import jalview.util.ShiftList; + import java.util.*; /** @@ -202,7 +204,19 @@ public class ColumnSelection } } } - + public ShiftList compensateForEdits(ShiftList shiftrecord) { + if (shiftrecord!=null) { + Vector shifts = shiftrecord.shifts; + if (shifts!=null && shifts.size()>0) { + for (int i=0,j=shifts.size(); i