Skip to content

Commit

Permalink
r1180: paftools.js call compatibility with k8-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed Oct 28, 2023
1 parent ce03fbc commit 9506e7a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 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-r1175';
var paftools_version = '2.26-r1180-dirty';

/*****************************
***** Library functions *****
Expand Down Expand Up @@ -133,38 +133,35 @@ Interval.find_ovlp = function(a, st, en)

function fasta_read(fn)
{
var h = {}, gt = '>'.charCodeAt(0);
var h = {};
var file = fn == '-'? new File() : new File(fn);
var buf = new Bytes(), seq = null, name = null, seqlen = [];
while (file.readline(buf) >= 0) {
if (buf[0] == gt) {
var line = buf.toString();
if (line[0] == '>') {
if (seq != null && name != null) {
seqlen.push([name, seq.length]);
h[name] = seq;
h[name] = seq.toString();
seq.destroy();
name = seq = null;
}
var m, line = buf.toString();
var m;
if ((m = /^>(\S+)/.exec(line)) != null) {
name = m[1];
seq = new Bytes();
}
} else seq.set(buf);
} else seq.set(line);
}
if (seq != null && name != null) {
seqlen.push([name, seq.length]);
h[name] = seq;
h[name] = seq.toString();
seq.destroy();
}
buf.destroy();
file.close();
return [h, seqlen];
}

function fasta_free(fa)
{
for (var name in fa)
fa[name].destroy();
}

Bytes.prototype.reverse = function()
{
for (var i = 0; i < this.length>>1; ++i) {
Expand Down Expand Up @@ -379,7 +376,7 @@ function paf_call(args)
} else if (o[1] > 0) { // shouldn't happen in theory
if (fa[o[0]] == null) throw Error('sequence "' + o[0] + '" is absent from the reference FASTA');
if (o[1] >= fa[o[0]].length) throw Error('position ' + o[1] + ' exceeds the length of sequence "' + o[0] + '"');
var ref = String.fromCharCode(fa[o[0]][o[1]-1]).toUpperCase();
var ref = fa[o[0]][o[1]-1].toUpperCase();
if (o[5] == '-') // insertion
v = [o[0], o[1], '.', ref, ref + o[6].toUpperCase()];
else // deletion
Expand Down Expand Up @@ -560,7 +557,6 @@ function paf_call(args)

buf.destroy();
file.close();
if (fa != null) fasta_free(fa);
}

function paf_asmstat(args)
Expand Down

0 comments on commit 9506e7a

Please sign in to comment.