annotate PsiCLASS-1.0.2/samtools-0.1.19/misc/r2plot.lua @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #!/usr/bin/env luajit
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 function string:split(sep, n)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 local a, start = {}, 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5 sep = sep or "%s+";
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 repeat
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 local b, e = self:find(sep, start);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 if b == nil then
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 table.insert(a, self:sub(start));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 break
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 a[#a+1] = self:sub(start, b - 1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 start = e + 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 if n and #a == n then
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 table.insert(a, self:sub(start));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 break
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 until start > #self;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 return a;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 function io.xopen(fn, mode)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 mode = mode or 'r';
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 if fn == nil then return io.stdin;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 elseif fn == '-' then return (mode == 'r' and io.stdin) or io.stdout;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 elseif fn:sub(-3) == '.gz' then return (mode == 'r' and io.popen('gzip -dc ' .. fn, 'r')) or io.popen('gzip > ' .. fn, 'w');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 elseif fn:sub(-4) == '.bz2' then return (mode == 'r' and io.popen('bzip2 -dc ' .. fn, 'r')) or io.popen('bgzip2 > ' .. fn, 'w');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 else return io.open(fn, mode) end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 local eps = {};
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 function eps.func(fp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 fp = fp or io.stdout
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 fp:write("/C { dup 255 and 255 div exch dup -8 bitshift 255 and 255 div 3 1 roll -16 bitshift 255 and 255 div 3 1 roll setrgbcolor } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 fp:write("/L { 4 2 roll moveto lineto } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 fp:write("/LX { dup 4 -1 roll exch moveto lineto } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 fp:write("/LY { dup 4 -1 roll moveto exch lineto } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 fp:write("/LS { 3 1 roll moveto show } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 fp:write("/RS { dup stringwidth pop 4 -1 roll exch sub 3 -1 roll moveto show } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 fp:write("/B { 4 copy 3 1 roll exch 6 2 roll 8 -2 roll moveto lineto lineto lineto closepath } bind def\n")
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 function eps.font(ft, size, fp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 fp = fp or io.stdout
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 fp:write(string.format('/FS %d def\n', size));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 fp:write('/FS4 FS 4 div def\n');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 fp:write('/' .. ft .. ' findfont FS scalefont setfont\n');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 local scale = 8;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 if #arg == 0 then
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 print("Usage: r2plot.lua <in.txt>");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 os.exit(1)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 local fp = io.xopen(arg[1]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 local n = tonumber(fp:read());
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 print('%!PS-Adobe-3.0 EPSF-3.0');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 print('%%' .. string.format('BoundingBox: -%d -%d %.3f %.3f\n', 10*scale, scale, (n+1)*scale, (n+1)*scale));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 print(string.format('%.3f setlinewidth', scale));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 print(string.format('/plot { setgray moveto 0 %d rlineto } def', scale));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 print(string.format('/plothalf { setgray moveto 0 %.2f rlineto } def', scale/2));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 eps.func();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 eps.font('Helvetica', scale-1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 local i = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 for l in fp:lines() do
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 local t = l:split('\t');
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 print(string.format("%d %d FS4 add (%s) RS", (i-1)*scale-2, (i-1)*scale, t[1]));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 for j = 2, #t do
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74 if tonumber(t[j]) > 0.01 then
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 print(string.format('%.2f %.2f %.2f plot stroke', (i-1+.5)*scale, (j-2)*scale, 1.-t[j]));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78 i = i + 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80 for j = 1, 21 do
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 print(string.format('%.2f %.2f %.2f plothalf stroke', -8*scale, (j-1) * scale/2, 1.-(j-1)/20));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82 end
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 print('showpage');