X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FCigarBase.java;h=2508717e08e476530fbf9be38e73d9bbb3ecde17;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=2f20c00159cbd24ef07756db3695ec2be7d1a997;hpb=2de8acfae59aced665e4c37ad0f7dcc2ed68818e;p=jalview.git diff --git a/src/jalview/datamodel/CigarBase.java b/src/jalview/datamodel/CigarBase.java index 2f20c00..2508717 100644 --- a/src/jalview/datamodel/CigarBase.java +++ b/src/jalview/datamodel/CigarBase.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) - * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, 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 file is part of Jalview. * - * 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. + * Jalview 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 3 of the License, or (at your option) any later version. * - * 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 + * Jalview 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 Jalview. If not, see . */ package jalview.datamodel; @@ -35,7 +34,8 @@ public abstract class CigarBase protected int length = 0; protected int _inc_length = 10; // extension range for addition of new - // operations + + // operations protected char[] operation = null; @@ -63,11 +63,11 @@ public abstract class CigarBase * and the deletion regions as an array of int pairs May return null for an * empty cigar string. May return null for deletion ranges if there are none. * - * @param reference - - * the symbol sequence to apply the cigar operations to (or - * null if no sequence) - * @param GapChar - - * the symbol to use for Insert operations + * @param reference + * - the symbol sequence to apply the cigar operations to (or null if + * no sequence) + * @param GapChar + * - the symbol to use for Insert operations * @return Object[] { String, int[] {start, startcol, end, endcol}, int[][3] * {start, end, col} or null} the gapped sequence, first and last * residue index, and the deletion ranges on the reference sequence @@ -187,11 +187,11 @@ public abstract class CigarBase * turn a cigar string into a series of operation range pairs * * @param cigarString - * String + * String * @return object[] {char[] operation, int[] range} * @throws java.lang.Exception - * for improperly formated cigar strings or ones with unknown - * operations + * for improperly formated cigar strings or ones with unknown + * operations */ public static Object[] parseCigarString(String cigarString) throws Exception @@ -254,9 +254,9 @@ public abstract class CigarBase * add an operation to cigar string * * @param op - * char + * char * @param range - * int + * int */ public void addOperation(char op, int range) { @@ -316,60 +316,61 @@ public abstract class CigarBase * M, Ds changed to M. (ie "5I5M".insert(4,M,3)->"4I8M") - effectively shifts * sequence left by 1 residue and extends it by 3 ( * "10D5M".insert(-1,M,3)->"3M7D5M") ( "10D5M".insert(0,M,3)->"7D8M") ( - * "10D5M".insert(1,M,3)->"10D8M") - * ( "1M10D5M".insert(0,M,3)->"1M10D8M") ( "1M10D5M".insert(1,M,3)->" + * "10D5M".insert(1,M,3)->"10D8M") ( "1M10D5M".insert(0,M,3)->"1M10D8M") ( + * "1M10D5M".insert(1,M,3)->" * * if pos is beyond width - I operations are added before the operation * * @param pos - * int -1, 0-length of visible region, or greater to append new - * ops (with insertions in between) + * int -1, 0-length of visible region, or greater to append new ops + * (with insertions in between) * @param op - * char + * char * @param range - * int public void addOperationAt(int pos, char op, int range) { - * int cursor = -1; // mark the position for the current - * operation being edited. int o = 0; boolean last_d = false; // - * previous op was a deletion. if (pos < -1) throw new - * Error("pos<-1 is not supported."); while (o0) - * addInsertion(pos-cursor); // then just add the new - * operation. Regardless of what it is. addOperation(op, - * range); } else { int diff = pos - cursor; + * int public void addOperationAt(int pos, char op, int range) { int + * cursor = -1; // mark the position for the current operation being + * edited. int o = 0; boolean last_d = false; // previous op was a + * deletion. if (pos < -1) throw new + * Error("pos<-1 is not supported."); while (o0) addInsertion(pos-cursor); + * // then just add the new operation. Regardless of what it is. + * addOperation(op, range); } else { int diff = pos - cursor; * - * int e_length = length-o; // new edit operation array length. // diff<0 - - * can only happen before first insertion or match. - affects op and all - * following // dif==0 - only when at first position of existing op - // - * diff>0 - must preserve some existing operations int[] e_range = new - * int[e_length]; System.arraycopy(this.range, o, e_range, 0, e_length); - * char[] e_op = new char[e_length]; System.arraycopy(this.operation, o, e_op, - * 0, e_length); length = o; // can now use add_operation to extend list. int - * e_o=0; // current operation being edited. switch (op) { case M: switch - * (e_op[e_o]) { case M: if (last_d && diff <= 0) { // reduce D's, if possible - * if (range<=this.range[o-1]) { this.range[o - 1] -= range; } else { - * this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose this op. } - * e_range[e_o] += range; // just add more matched residues break; case I: // - * change from insertion to match if (last_d && diff<=0) { // reduce D's, if - * possible if (range<=this.range[o-1]) { this.range[o - 1] -= range; } else { - * this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose this op. } - * e_range[e_o] break; default: throw new Inp } + * int e_length = length-o; // new edit operation array length. // + * diff<0 - can only happen before first insertion or match. - + * affects op and all following // dif==0 - only when at first + * position of existing op - // diff>0 - must preserve some existing + * operations int[] e_range = new int[e_length]; + * System.arraycopy(this.range, o, e_range, 0, e_length); char[] e_op + * = new char[e_length]; System.arraycopy(this.operation, o, e_op, 0, + * e_length); length = o; // can now use add_operation to extend + * list. int e_o=0; // current operation being edited. switch (op) { + * case M: switch (e_op[e_o]) { case M: if (last_d && diff <= 0) { // + * reduce D's, if possible if (range<=this.range[o-1]) { this.range[o + * - 1] -= range; } else { this.range[o-1]=0; } if + * (this.range[o-1]==0) o--; // lose this op. } e_range[e_o] += + * range; // just add more matched residues break; case I: // change + * from insertion to match if (last_d && diff<=0) { // reduce D's, if + * possible if (range<=this.range[o-1]) { this.range[o - 1] -= range; + * } else { this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose + * this op. } e_range[e_o] break; default: throw new Inp } * - * break; case I: break; case D: } break; default: throw new - * Error("Implementation Error: Unknown operation in addOperation!"); } // - * finally, add remaining ops. while (e_o