the alignment in hidden regions.
{
if (!seqcigararray.isSeqCigarArray())
throw new Error("Implementation Error - can only make an alignment view from a CigarArray of sequences.");
- contigs = seqcigararray.applyDeletions();
+ //contigs = seqcigararray.applyDeletions();
+ contigs = seqcigararray.getDeletedRegions();
sequences = seqcigararray.getSeqCigarArray();
}
public Object[] getAlignmentAndColumnSelection(char gapCharacter) {
ColumnSelection colsel = new ColumnSelection();
- return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel), colsel};
+ return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel};
}
/**
* getSequenceStrings
* applyDeletions\r
* edits underlying refCigars to propagate deleted regions, and removes deletion\r
* operations from CigarArray operation list.\r
- * @return int[] position where deletion occured in cigarArray or null if none occured\r
+ * @return int[] position after deletion occured and range of deletion in cigarArray or null if none occured\r
*/\r
public int[] applyDeletions()\r
{\r
return null;\r
int cursor=0; // range counter for deletions\r
int vcursor=0; // visible column index\r
- for (int i=0; i<length; i++) {\r
+ int offset=0; // shift in visible column index as deletions are made\r
+ int i=0;\r
+ while (i<length) {\r
if (operation[i]!=D) {\r
if (operation[i]==M)\r
cursor+=range[i];\r
- vcursor+=range[i];\r
+ vcursor+=range[i++];\r
}\r
else\r
{\r
if (delpos==null)\r
delpos=new java.util.Vector();\r
int delstart=cursor, delend=cursor+range[i]-1; // inclusive\r
- delpos.addElement(new Integer(vcursor-1)); // index of left hand column of hidden region boundary\r
+ delpos.addElement(new int[] { vcursor+offset, range[i]}); // index of right hand column after hidden region boundary\r
+ offset+=range[i]-1; // shift in visible column coordinates\r
System.arraycopy(operation, i+1, operation, i, length-i);\r
System.arraycopy(range, i+1, range, i, length-i);\r
length--;\r
+ /* int dmax=0;\r
+ for (int s=0; s<refCigars.length; s++) {\r
+ int d = refCigars[s].deleteRange(delstart, delend);\r
+ if (d>dmax)\r
+ dmax=d;\r
+ }\r
+ offset+=dmax; // shift in visible column coordinates\r
+ */\r
for (int s=0; s<refCigars.length; s++) {\r
- refCigars[s].deleteRange(delstart, delend);\r
+ int d = refCigars[s].deleteRange(delstart, delend);\r
}\r
+\r
}\r
}\r
if (delpos!=null)\r
{\r
- int[] pos=new int[delpos.size()];\r
+ int[] pos=new int[delpos.size()*2];\r
for (int k = 0, l = delpos.size(); k < l; k++) {\r
- pos[k] = ((Integer) delpos.elementAt(k)).intValue();\r
+ int[] dr = ((int[]) delpos.elementAt(k));\r
+ pos[k*2] = dr[0];\r
+ pos[k*2+1] = dr[1];\r
delpos.setElementAt(null,k);\r
}\r
delpos=null;\r
package jalview.datamodel;
+import java.util.Vector;
+
public abstract class CigarBase
{
/**
new int[] {
start, startpos, end, endpos}, trunc_deletions};
}
-
+ protected void compact_operations() {
+ int i=1;
+ if (operation==null)
+ return;
+ char last = operation[0];
+ while (i<length) {
+ if (last==operation[i]) {
+ range[i-1]+=range[i];
+ int r = length-i;
+ if (r>0) {
+ System.arraycopy(range, i + 1, range, i, r);
+ System.arraycopy(operation, i + 1, operation, i, r);
+ }
+ length--;
+ } else {
+ last = operation[i++];
+ }
+ }
+ }
/**
* turn a cigar string into a series of operation range pairs
* @param cigarString String
* Mark residues from start to end (inclusive) as deleted from the alignment, and removes any insertions.
* @param start int
* @param end int
+ * @return deleted int - number of symbols marked as deleted
*/
- public void deleteRange(int start, int end) {
+ public int deleteRange(int start, int end) {
+ int deleted=0;
if (length==0) {
// nothing to do here
- return;
+ return deleted;
}
if (start<0 || start>end)
throw new Error("Implementation Error: deleteRange out of bounds: start must be non-negative and less than end.");
length=0;
operation = null;
range = null;
+ compact_operations();
while (o<oldlen && cursor<=end && rlength>0) {
if (oldops[o] == D) {
// absorbed into new deleted region.
case M:
if (rlength>remain) {
addDeleted(remain);
+ deleted+=remain;
} else {
+ deleted+=rlength;
addDeleted(rlength);
if (remain-rlength>0)
this.addOperation(M,remain-rlength); // add remaining back.
// ran out of ops - nothing to do here ?
// addInsertion(start-cursor);
//}
+ return deleted;
+ }
+
+ /**
+ * 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; i<length ; i++)
+ {
+ if (operation[i] == D)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * enumerate the ranges on seq that are marked as deleted in this cigar
+ * @return int[] { vis_start, sym_start, length }
+ */
+ public int[] getDeletedRegions() {
+ if (length==0)
+ return null;
+ Vector dr = new Vector();
+ int cursor=0, vcursor=0;
+ for (int i=0;i<length;i++) {
+ switch (operation[i]) {
+ case M:
+ cursor+=range[i];
+ case I:
+ vcursor+=range[i];
+ break;
+ case D:
+ dr.add(new int[] { vcursor, cursor, range[i]});
+ cursor+=range[i];
+ }
+ }
+ if (dr.size()==0)
+ return null;
+ int[] delregions = new int[dr.size()*3];
+ for (int i=0,l=dr.size(); i<l; i++) {
+ int[] reg = (int[]) dr.get(i);
+ delregions[i*3] = reg[0];
+ delregions[i*3+1] = reg[1];
+ delregions[i*3+2] = reg[2];
+ }
+ return delregions;
}
/**
* sum of ranges in cigar string
* @return String
*/
public abstract String getSequenceString(char GapChar);
+
}
{
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
* @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];
}
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++)
}
}
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);
}
}
}
ref.getStart() + alseqs[i].start+bounds[2]);
seqs[i].setDatasetSequence(ref);
}
+ if (segments!=null) {
+ int delshift=0; // need to shift the segments to their absolute positions in the sequence cigar frame.
+ for (int i=0; i<segments.length; i+=3) {
+ //int start=shifts.shift(segments[i]-1)+1;
+ //int end=shifts.shift(segments[i]+segments[i+1]-1)-1;
+ colsel.hideColumns(delshift+segments[i], delshift+segments[i]+segments[i+2]-1);
+ delshift+=segments[i+2];
+ }
+ }
return seqs;
}
{
sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
int sl = sub_se_gp.getWidth();
- int st = sl - r - r;
+ int st = sl - 1 - r;
for (int rs = 0; rs < 10; rs++)
{
int e = st + rs;
sub_se_gp.deleteRange(st, e);
String ssgapedseq = sub_se_gp.getSeq('-').getSequence();
System.out.println(st + "," + e + "\t:" + ssgapedseq);
+ st -=3;
}
}
{