-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgraphpid.py
79 lines (55 loc) · 2.38 KB
/
graphpid.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import sys
from operator import attrgetter
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
from nucio import lineRecordIterator,M4Record, M4RecordTypes
from args import parseArgs, getHelpStr, CLArgument
description = ("Usage: graphpid.py [options] title alignments.m4\n\n"
"Graph Alignments from blasr's m4 output")
argument_list = [["tophist_maxy", "tophist_maxy", int, -1,
"Maximum y value for top histogram"]]
arguments = map(CLArgument._make, argument_list)
if not len(sys.argv) > 1:
sys.exit(getHelpStr(description, arguments) + "\n")
(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)
if not len(args_remaining) == 2:
sys.exit(getHelpStr(description, arguments) + "\n")
igetter = attrgetter("pctsimilarity", "qseqlength")
mpl.rc('font', family='normal',weight="normal",
size=10)
mpl.rc('xtick', labelsize=5)
mpl.rc('ytick', labelsize=5)
with open(args_remaining[1]) as fh:
records = lineRecordIterator(fh, M4Record, M4RecordTypes)
items = map(igetter, records)
(pctids, lens) = zip(*items)
pp = PdfPages("out.pdf")
(fig, axScatter) = plt.subplots(figsize=(8.5,5.5))
axScatter.scatter(lens, pctids, color="blue", s=0.001)
axScatter.set_xticks(range(0,80000,2000))
axScatter.set_yticks(range(0,100,5))
fig.suptitle(args_remaining[0])
plt.xlabel("Read Length (bp)")
plt.ylabel("Alignment Identity (%)")
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)
plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(), visible=False)
len_binsize=250
len_bins = np.arange(0,50000+len_binsize,len_binsize)
pid_binsize=0.1
pid_bins = np.arange(-100.0,100.0+pid_binsize,pid_binsize)
axHistx.hist(lens,bins=len_bins, color="orange")
(ax1,ax2,ay1,ay2) = axHistx.axis()
if p_arg_map["tophist_maxy"] > 0:
axHistx.axis((ax1,ax2,ay1,p_arg_map["tophist_maxy"]))
#axHistx.axis('off')
axHisty.hist(pctids, bins=pid_bins, orientation='horizontal', color="green")
axHisty.axis('off')
plt.savefig(pp, format="pdf")
pp.close()