modified: myjupyterlab.sh
[GalaxyCodeBases.git] / tools / lh3misc / seq / bc2rg.d
blob5f3dfc0a690cbbf27eea43cec4b88c479ad7a6af
1 #!/usr/bin/evn rdmd
3 import std.stdio, std.string, std.regex, klib;
5 void main(string[] args)
7 if (args.length < 4) {
8 writeln("Usage: rdmd bc2rg.d <sample> <barcode-list.txt> <aln.sam>");
9 return;
11 auto fp = new ZFile(args[2]);
12 ubyte[] l;
13 string[string] bc2rg;
14 char[] base = ['A', 'C', 'G', 'T', 'N'];
15 string[] rg;
16 while (fp.readto(l) >= 0) {
17 auto t = std.string.split(cast(string)l);
18 if (t.length == 0) continue;
19 string r = args[1] ~ '-' ~ t[0] ~ '-' ~ t[1];
20 rg ~= r;
21 for (auto i = 0; i < t[0].length; ++i) {
22 foreach (c; base) {
23 char[] s;
24 s.length = t[0].length;
25 s[] = cast(char[])t[0];
26 s[i] = c;
27 bc2rg[cast(string)s] = r;
31 fp.close();
32 fp = new ZFile(args[3]);
33 bool first = true;
34 auto re = regex(r"^\S+#([ACGTN]+)");
35 while (fp.readto(l) >= 0) {
36 if (l[0] != '@') {
37 if (first) {
38 foreach (p; rg)
39 writefln("@RG\tID:%s\tSM:%s\tLB:%s", p, args[1], p);
40 first = false;
42 auto c = match(cast(string)l, re).captures;
43 if (c[1] in bc2rg) writeln(cast(char[])l, "\tRG:Z:", bc2rg[c[1]]);
44 else writeln(cast(char[])l);
45 } else writeln(cast(char[])l);