Skip to content

Commit

Permalink
r1191: fixed wrong reverse() and revcomp()
Browse files Browse the repository at this point in the history
due to k8 incompatibility. Resolves #1161
  • Loading branch information
lh3 committed Mar 12, 2024
1 parent fcd4df2 commit ba60aac
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions misc/paftools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env k8

var paftools_version = '2.26-r1189-dirty';
var paftools_version = '2.26-r1191-dirty';

/*****************************
***** Library functions *****
Expand Down Expand Up @@ -193,10 +193,19 @@ function fasta_free(fa)

Bytes.prototype.reverse = function()
{
for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[i];
this[i] = this[this.length - i - 1];
this[this.length - i - 1] = tmp;
if (typeof k8_version === "undefined") { // k8-0.x
for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[i];
this[i] = this[this.length - i - 1];
this[this.length - i - 1] = tmp;
}
} else { // k8-1.x
var buf = new Uint8Array(this.buffer);
for (var i = 0; i < buf.length>>1; ++i) {
var tmp = buf[i];
buf[i] = buf[buf.length - i - 1];
buf[buf.length - i - 1] = tmp;
}
}
}

Expand All @@ -211,13 +220,24 @@ Bytes.prototype.revcomp = function()
for (var i = 0; i < s1.length; ++i)
Bytes.rctab[s1.charCodeAt(i)] = s2.charCodeAt(i);
}
for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[this.length - i - 1];
this[this.length - i - 1] = Bytes.rctab[this[i]];
this[i] = Bytes.rctab[tmp];
if (typeof k8_version === "undefined") { // k8-0.x
for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[this.length - i - 1];
this[this.length - i - 1] = Bytes.rctab[this[i]];
this[i] = Bytes.rctab[tmp];
}
if (this.length&1)
this[this.length>>1] = Bytes.rctab[this[this.length>>1]];
} else { // k8-1.x
var buf = new Uint8Array(this.buffer);
for (var i = 0; i < buf.length>>1; ++i) {
var tmp = buf[buf.length - i - 1];
buf[buf.length - i - 1] = Bytes.rctab[buf[i]];
buf[i] = Bytes.rctab[tmp];
}
if (buf.length&1)
buf[buf.length>>1] = Bytes.rctab[buf[buf.length>>1]];
}
if (this.length&1)
this[this.length>>1] = Bytes.rctab[this[this.length>>1]];
}

/********************
Expand Down

0 comments on commit ba60aac

Please sign in to comment.