r1191: fixed wrong reverse() and revcomp()

due to k8 incompatibility. Resolves #1161
This commit is contained in:
Heng Li
2024-03-11 22:09:01 -04:00
parent fcd4df2a73
commit ba60aac6f6
+21 -1
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env k8 #!/usr/bin/env k8
var paftools_version = '2.26-r1189-dirty'; var paftools_version = '2.26-r1191-dirty';
/***************************** /*****************************
***** Library functions ***** ***** Library functions *****
@@ -193,11 +193,20 @@ function fasta_free(fa)
Bytes.prototype.reverse = function() Bytes.prototype.reverse = function()
{ {
if (typeof k8_version === "undefined") { // k8-0.x
for (var i = 0; i < this.length>>1; ++i) { for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[i]; var tmp = this[i];
this[i] = this[this.length - i - 1]; this[i] = this[this.length - i - 1];
this[this.length - i - 1] = tmp; 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;
}
}
} }
// reverse complement a DNA string // reverse complement a DNA string
@@ -211,6 +220,7 @@ Bytes.prototype.revcomp = function()
for (var i = 0; i < s1.length; ++i) for (var i = 0; i < s1.length; ++i)
Bytes.rctab[s1.charCodeAt(i)] = s2.charCodeAt(i); Bytes.rctab[s1.charCodeAt(i)] = s2.charCodeAt(i);
} }
if (typeof k8_version === "undefined") { // k8-0.x
for (var i = 0; i < this.length>>1; ++i) { for (var i = 0; i < this.length>>1; ++i) {
var tmp = this[this.length - i - 1]; var tmp = this[this.length - i - 1];
this[this.length - i - 1] = Bytes.rctab[this[i]]; this[this.length - i - 1] = Bytes.rctab[this[i]];
@@ -218,6 +228,16 @@ Bytes.prototype.revcomp = function()
} }
if (this.length&1) if (this.length&1)
this[this.length>>1] = Bytes.rctab[this[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]];
}
} }
/******************** /********************