From 7931bc3242f86a9fbd36f9910ba5fd3551bc6e0b Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 26 Oct 2006 13:09:20 +0000 Subject: [PATCH] Returns number of columns deleted --- src/jalview/commands/RemoveGapColCommand.java | 24 ++++++++++++++++++------ src/jalview/commands/TrimRegionCommand.java | 22 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/jalview/commands/RemoveGapColCommand.java b/src/jalview/commands/RemoveGapColCommand.java index 5bf5b61..2c3aced 100644 --- a/src/jalview/commands/RemoveGapColCommand.java +++ b/src/jalview/commands/RemoveGapColCommand.java @@ -22,6 +22,7 @@ import jalview.datamodel.*; public class RemoveGapColCommand extends EditCommand { + int columnsDeleted; public RemoveGapColCommand(String description, SequenceI[] seqs, int start, int end, char gapChar) @@ -31,12 +32,12 @@ public class RemoveGapColCommand extends EditCommand int j, jSize = seqs.length; int startCol = -1, endCol = -1; - int deletedCols = 0; + columnsDeleted=0; edits = new Edit[0]; boolean delete = true; - for (int i = start; i < end; i++) + for (int i = start; i <= end; i++) { delete = true; @@ -63,12 +64,12 @@ public class RemoveGapColCommand extends EditCommand if (!delete && startCol > -1) { this.appendEdit(DELETE_GAP, seqs, - startCol - deletedCols, + startCol - columnsDeleted, endCol - startCol, gapChar, false); - deletedCols += (endCol - startCol); + columnsDeleted += (endCol - startCol); startCol = -1; endCol = -1; } @@ -78,14 +79,25 @@ public class RemoveGapColCommand extends EditCommand { //This is for empty columns at the //end of the alignment + this.appendEdit(DELETE_GAP, seqs, - startCol - deletedCols, - end-startCol+1, + startCol - columnsDeleted, + end - startCol +1, gapChar, false); + + columnsDeleted += (end - startCol +1); } + performEdit(0); } + public int getSize() + { + //We're interested in the number of columns deleted, + //Not the number of sequence edits. + return columnsDeleted; + } + } diff --git a/src/jalview/commands/TrimRegionCommand.java b/src/jalview/commands/TrimRegionCommand.java index 5a5dcd1..8166ed6 100644 --- a/src/jalview/commands/TrimRegionCommand.java +++ b/src/jalview/commands/TrimRegionCommand.java @@ -38,6 +38,8 @@ public class TrimRegionCommand Vector deletedHiddenColumns; + int columnsDeleted; + public TrimRegionCommand(String description, String command, SequenceI[] seqs, @@ -51,12 +53,25 @@ public class TrimRegionCommand this.colSel = colSel; if (command.equalsIgnoreCase(TRIM_LEFT)) { + if(column==0) + return; + + columnsDeleted = column; + edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)}; } else if (command.equalsIgnoreCase(TRIM_RIGHT)) { + int width = al.getWidth()-column; + if(width<2) + { + return; + } + + columnsDeleted = width-1; + edits = new Edit[] - { new Edit(CUT, seqs, column+1, al.getWidth() - column, al)}; + { new Edit(CUT, seqs, column+1, width, al)}; } //We need to keep a record of the sequence start @@ -138,8 +153,11 @@ public class TrimRegionCommand colSel.hideColumns(region[0], region[1]); } } + } - + public int getSize() + { + return columnsDeleted; } } -- 1.7.10.2