/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+* 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
if (seq=="")
return null;
int nstart = findPosition(start);
- int nend=findPosition(end-1)-1;
+ int nend=findPosition(end)-1;
// JBPNote - this is an incomplete copy.
SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
nseq.setDatasetSequence(getDatasetSequence());
}
/**
- * DOCUMENT ME!
+ * Returns an int array where indices correspond to each residue in the sequence and the element value gives its position in the alignment
*
- * @return DOCUMENT ME!
+ * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no residues in SequenceI object
*/
public int[] gapMap()
{
- // Returns an int array giving the position of each residue in the sequence in the alignment
String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequence);
int[] map = new int[seq.length()];
int j = 0;
sequence = newSeq.toString();
}
+ public SequenceI getSubSequence(int start)
+ {
+ int e=getLength();
+ if (start>=e)
+ return null;
+ return getSubSequence(start, getLength());
+ }
+
+ public int removeGaps() {
+ if (sequence!=null)
+ return removeGaps(0, getLength());
+ return 0;
+ }
+
+ public int removeGaps(int start, int end) {
+ int jSize = getLength();
+ int oSize=jSize;
+ if (jSize<=start)
+ return 0;
+ if (end>jSize)
+ end = jSize;
+
+ // Removing a range is much quicker than removing gaps
+ // one by one for long sequences
+ int j = start;
+ int rangeStart=-1, rangeEnd=-1;
+
+ do
+ {
+ if (jalview.util.Comparison.isGap(getCharAt(j)))
+ {
+ if(rangeStart==-1)
+ {
+ rangeStart = j;
+ rangeEnd = j+1;
+ }
+ else
+ {
+ rangeEnd++;
+ }
+ j++;
+ }
+ else
+ {
+ if(rangeStart>-1)
+ {
+ deleteChars(rangeStart, rangeEnd);
+ j-=rangeEnd-rangeStart;
+ jSize-=rangeEnd-rangeStart;
+ rangeStart = -1;
+ rangeEnd = -1;
+ }
+ else
+ j++;
+ }
+ }
+ while (j < end && j < jSize);
+ if(rangeStart>-1)
+ {
+ deleteChars(rangeStart, rangeEnd);
+ jSize-=rangeEnd-rangeStart;
+ }
+ return oSize-jSize; // number of deleted characters.
+ }
+
}