Skip to content

Commit e5066c7

Browse files
lh3claude
andcommitted
added sim2bed to convert simulated read names to BED
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f838175 commit e5066c7

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

misc/paftools.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,44 @@ function paf_mason2fq(args)
23482348
buf2.destroy();
23492349
}
23502350

2351+
// convert Mason read names to BED
2352+
function paf_sim2bed(args)
2353+
{
2354+
if (args.length == 0) {
2355+
print("Usage: paftools.js sim2bed <sim.txt>");
2356+
exit(1);
2357+
}
2358+
var buf = new Bytes();
2359+
var file = new File(args[0]);
2360+
var seen = {};
2361+
while (file.readline(buf) >= 0) {
2362+
var line = buf.toString();
2363+
var t = line.split("!");
2364+
if (t.length < 5) continue;
2365+
var chr = t[1], st, en, strand;
2366+
if (t[2].indexOf("_") >= 0) { // mason paired-end
2367+
var pos = t[2].split("_");
2368+
var end = t[3].split("_");
2369+
var m = /^(.)(.)\/([12])$/.exec(t[4]);
2370+
if (m == null) continue;
2371+
strand = m[3] == "1" ? m[1] : m[2];
2372+
var read_no = parseInt(m[3]) - 1;
2373+
st = parseInt(pos[read_no]);
2374+
en = parseInt(end[read_no]);
2375+
} else { // badread/pbsim long reads
2376+
st = parseInt(t[2]);
2377+
en = parseInt(t[3]);
2378+
strand = t[4];
2379+
}
2380+
if (st > en) { var tmp = st; st = en; en = tmp; }
2381+
if (seen[line]) continue;
2382+
seen[line] = 1;
2383+
print([chr, st, en, line, 0, strand].join("\t"));
2384+
}
2385+
file.close();
2386+
buf.destroy();
2387+
}
2388+
23512389
// convert pbsim MAF to FASTQ
23522390
function paf_pbsim2fq(args)
23532391
{
@@ -3750,6 +3788,7 @@ function main(args)
37503788
print(" mapeval evaluate mapping accuracy using mason2/PBSIM-simulated FASTQ");
37513789
print(" pafcmp compare two PAF files");
37523790
print(" mason2fq convert mason2-simulated SAM to FASTQ");
3791+
print(" sim2bed convert mason2-simulated read names to BED");
37533792
print(" pbsim2fq convert PBSIM-simulated MAF to FASTQ");
37543793
print(" badread2fa convert Baderead FASTQ to FASTA");
37553794
print(" junceval evaluate splice junction consistency with known annotations");
@@ -3776,6 +3815,7 @@ function main(args)
37763815
else if (cmd == 'pafcmp') paf_pafcmp(args);
37773816
else if (cmd == 'bedcov') paf_bedcov(args);
37783817
else if (cmd == 'mason2fq') paf_mason2fq(args);
3818+
else if (cmd == 'sim2bed') paf_sim2bed(args);
37793819
else if (cmd == 'pbsim2fq') paf_pbsim2fq(args);
37803820
else if (cmd == 'badread2fa') paf_badread2fa(args);
37813821
else if (cmd == 'junceval') paf_junceval(args);

0 commit comments

Comments
 (0)