def plot_frequencies(flu, gene, mutation=None, plot_regions=None, all_muts=False, ax=None, **kwargs):
import seaborn as sns
sns.set_style('whitegrid')
cols = sns.color_palette()
linestyles = ['-', '--', '-.', ':']
if plot_regions is None:
plot_regions=regions
pivots = flu.pivots
if ax is None:
plt.figure()
ax=plt.subplot(111)
if type(mutation)==int:
mutations = [x for x,freq in flu.mutation_frequencies[('global', gene)].iteritems()
if (x[0]==mutation)&(freq[0]<0.5 or all_muts)]
elif mutation is not None:
mutations = [mutation]
else:
mutations=None
if mutations is None:
for ri, region in enumerate(plot_regions):
count=flu.mutation_frequency_counts[region]
plt.plot(pivots, count, c=cols[ri%len(cols)], label=region)
else:
print("plotting mutations", mutations)
for ri,region in enumerate(plot_regions):
for mi,mut in enumerate(mutations):
if mut in flu.mutation_frequencies[(region, gene)]:
freq = flu.mutation_frequencies[(region, gene)][mut]
err = flu.mutation_frequency_confidence[(region, gene)][mut]
c=cols[ri%len(cols)]
label_str = str(mut[0]+1)+mut[1]+', '+region
plot_trace(ax, pivots, freq, err, c=c,
ls=linestyles[mi%len(linestyles)],label=label_str, **kwargs)
else:
print(mut, 'not found in region',region)
ax.ticklabel_format(useOffset=False)
ax.legend(loc=2)
评论列表
文章目录