-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathzmwProductivityHeatmap.py
More file actions
61 lines (40 loc) · 1.46 KB
/
zmwProductivityHeatmap.py
File metadata and controls
61 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import sys
from operator import itemgetter,attrgetter
from itertools import imap, starmap, repeat,izip,ifilter
from pbcore.io import BasH5Reader
from collections import Counter
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
if not len(sys.argv) == 2:
sys.exit("zmwProductivityHeatmap.py input.bas.h5\n")
infile = sys.argv[1]
cell = BasH5Reader(infile)
get_prod = lambda o : getattr(o, "zmwMetric")("Productivity")
zmwgetters = map(itemgetter, cell.allSequencingZmws)
all_seq_zmws = list(starmap(apply,zip(zmwgetters, repeat([cell]))))
zmw_prods = map(get_prod, all_seq_zmws)
prod_lens = zip(zmw_prods, imap(lambda z: len(z.read()), all_seq_zmws))
prod1_lens = map(itemgetter(1), ifilter(lambda (p,l): p==1, prod_lens))
prod2_lens = map(itemgetter(1), ifilter(lambda (p,l): p==2, prod_lens))
xy = map(attrgetter("holeXY"), all_seq_zmws)
xyl = map(list,xy)
colors="rgy"
(x,y) = zip(*xyl)
cellname = infile.split(".")[0]
pp = PdfPages(cellname + ".pdf")
colormap = map(lambda c: colors[c], zmw_prods)
plt.scatter(x, y, marker='o', s=3,lw=0, c=colormap, edgecolor=colormap)
plt.suptitle(cellname)
plt.savefig(pp, format="pdf")
plt.legend()
plt.figure()
plt.hist([prod1_lens,prod2_lens],bins=100,normed=True, histtype='bar', label=["prod1", "prod2"])
plt.legend()
plt.xlabel("Read Length")
plt.ylabel("Frequency")
plt.suptitle(cellname)
plt.savefig(pp, format="pdf")
pp.close()