X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSeqCigar.java;h=7363e9ef334537956f1fc4d517d25b8ebae2e986;hb=201b18da026bf92f9cd611e549a9def463583c67;hp=c9b737d28c16d62323d8f4115bc177e827b34617;hpb=7570956d4b58f313d402cdd0507737c0628f1544;p=jalview.git diff --git a/src/jalview/datamodel/SeqCigar.java b/src/jalview/datamodel/SeqCigar.java index c9b737d..7363e9e 100644 --- a/src/jalview/datamodel/SeqCigar.java +++ b/src/jalview/datamodel/SeqCigar.java @@ -1,3 +1,21 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2006 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.analysis.*; @@ -41,7 +59,7 @@ public class SeqCigar public String getSequenceString(char GapChar) { return (length == 0) ? "" : - (String) getSequenceAndDeletions(refseq.getSequence().substring(start, end), GapChar)[0]; + (String) getSequenceAndDeletions(refseq.getSequenceAsString(start, end), GapChar)[0]; } /** @@ -55,18 +73,20 @@ public class SeqCigar { return null; } - Object[] edit_result = getSequenceAndDeletions(refseq.getSequence().substring(start,end), + Object[] edit_result = getSequenceAndDeletions(refseq.getSequenceAsString(start,end), GapChar); if (edit_result == null) { throw new Error( "Implementation Error - unexpected null from getSequenceAndDeletions"); } - + int bounds[] = (int[]) edit_result[1]; seq = new Sequence(refseq.getName(), (String) edit_result[0], - refseq.getStart() + start+( (int[]) edit_result[1])[0], - refseq.getStart() + start+( (int[]) edit_result[1])[2]); + refseq.getStart() + start+bounds[0], + refseq.getStart() + start+((bounds[2]==0) ? -1 : bounds[2])); + // seq.checkValidRange(); probably not needed seq.setDatasetSequence(refseq); + seq.setDescription(refseq.getDescription()); return seq; } @@ -94,7 +114,7 @@ public class SeqCigar } if (_s<0) throw new Error("Implementation Error: _s="+_s); - String seq_string = seq.getSequence(); + String seq_string = seq.getSequenceAsString(); if (_e==0 || _e<_s || _e>seq_string.length()) _e=seq_string.length(); // resolve start and end positions relative to ungapped reference sequence @@ -218,24 +238,6 @@ public class SeqCigar { this.addOperation(M, range); } - - /** - * Deleted regions mean that there will be discontinuous sequence numbering in the - * sequence returned by getSeq(char). - * @return true if there deletions - */ - public boolean hasDeletedRegions() - { - for (int i = 0, l = length; i < l; i++) - { - if (operation[i] == D) - { - return true; - } - } - return false; - } - /** * Adds * insertion and match operations based on seq to the cigar up to @@ -365,17 +367,16 @@ public class SeqCigar * @return SequenceI[] */ public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs, - char gapCharacter, ColumnSelection colsel) + char gapCharacter, ColumnSelection colsel, int[] segments) { SequenceI[] seqs = new SequenceI[alseqs.length]; - Vector hiddenRegions=new Vector(); StringBuffer[] g_seqs = new StringBuffer[alseqs.length]; String[] alseqs_string=new String[alseqs.length]; Object[] gs_regions = new Object[alseqs.length]; for (int i = 0; i < alseqs.length; i++) { alseqs_string[i]=alseqs[i].getRefSeq(). - getSequence().substring(alseqs[i].start,alseqs[i].end); + getSequenceAsString(alseqs[i].start,alseqs[i].end); gs_regions[i] = alseqs[i].getSequenceAndDeletions(alseqs_string[i], gapCharacter); // gapped sequence, {start, start col, end. endcol}, hidden regions {{start, end, col}}) if (gs_regions[i] == null) { @@ -384,7 +385,7 @@ public class SeqCigar } g_seqs[i] = new StringBuffer( (String) ( (Object[]) gs_regions[i])[0]); // the visible gapped sequence } - // Now account for insertions. + // Now account for insertions. (well - deletions) // this is complicated because we must keep track of shifted positions in each sequence ShiftList shifts = new ShiftList(); for (int i = 0; i < alseqs.length; i++) @@ -423,7 +424,9 @@ public class SeqCigar } } shifts.addShift(region[2], insert.length); // update shift in alignment frame of reference - colsel.hideColumns(inspos, inspos+insert.length-1); + if (segments==null) + // add a hidden column for this deletion + colsel.hideColumns(inspos, inspos+insert.length-1); } } } @@ -433,8 +436,16 @@ public class SeqCigar SequenceI ref = alseqs[i].getRefSeq(); seqs[i] = new Sequence(ref.getName(), g_seqs[i].toString(), ref.getStart() + alseqs[i].start+bounds[0], - ref.getStart() + alseqs[i].start+bounds[2]); + ref.getStart() + alseqs[i].start+(bounds[2]==0 ? -1 : bounds[2])); seqs[i].setDatasetSequence(ref); + seqs[i].setDescription(ref.getDescription()); + } + if (segments!=null) { + for (int i=0; i