/usr/lib/python2.7/dist-packages/biotools/analysis/report.py is in python-biotools 1.2.12-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 | import matplotlib.pyplot as plt
import biotools.analysis.plot as bap
from os import sep, mkdir
# report areas of high conservation or variation
def report(plotdata, **kwargs):
pass
# wraps biotools.analysis.plot.plot()
def plot(plotdata, directory, bottom=True, side=True, legend=True,
save=True, filename='untitled.pdf', upperbound=0.05, factor=21,
fig=plt.figure(None, facecolor='w', edgecolor='w'), **kwargs):
ranges = report(plotdata, **kwargs)
try:
mkdir(directory)
except OSError:
pass
lowerbound = -upperbound / 6
# smooth the data
snt = smoothed(snpdata['nt']['var'], factor)
lnt = len(snpdata['nt']['var'])
saa = smoothed(snpdata['aa']['var'], factor)
laa = len(snpdata['aa']['var'])
# generate x-ranges so that amino acids
# and nucleotides align
xnt = np.arange(lnt) * (0.0 + laa) / lnt + 1
xaa = np.arange(laa) + 1
# create the proper sized frame, depending on
# how we draw the plot
x = 0.09 if side else 0.02
y = 0.09 if bottom else 0.04
ax = fig.add_axes([x, y, 0.98 - x, 0.98 - y], xlim=[0, laa * 1.06],
ylim=[lowerbound, upperbound])
ax.minorticks_on()
ax.tick_params(axis='x', which='minor', length=3)
for loc, spine in ax.spines.items():
if loc in ['right', 'top']:
spine.set_color('none')
continue
if loc == 'bottom':
ax.xaxis.set_ticks_position('bottom')
if bottom:
ax.set_xlabel("Amino acids")
continue
if loc == 'left':
if side:
ax.set_ylabel("Sequence variance")
ax.yaxis.set_ticks_position('left')
else:
spine.set_color('none')
ax.tick_params('y', which='both', color='none',
labelcolor='none')
ax.hlines(ax.get_yticks(), 0, laa * 1.06, color='0.75', linestyle='dashed')
ax.hlines(0, 0, laa * 1.06, color='k', linestyle='solid')
nt_lines = ax.plot(xnt, snt, color='#0000ff', linestyle='solid')
aa_lines = ax.plot(xaa, saa, color='#00ff00', linestyle='solid')
starts = snpdata['aa']['starts']
ends = snpdata['aa']['ends']
counts = snpdata['aa']['count']
scale = laa / max(ends)
ys = (np.arange(len(starts)) + 1) * lowerbound / 3
ax.hlines(ys, starts, ends, colors='k', lw=4, linestyle='solid')
for i, c in zip(range(len(counts)), counts):
ax.text(laa + 10, lowerbound / 3 * (i + 1.25), c)
if legend:
fig.legend((nt_lines, aa_lines), ('Nucleotide', 'Amino acid'),
'upper right')
if save:
fig.savefig(directory + filename)
print('=============', filename, '=============')
print('Average variance: ')
print('\t', sum(snpdata['nt']['var']) / lnt, 'per base pair')
print('\t', sum(snpdata['aa']['var']) / laa, 'per amino acid')
|