In [1]:
%run ../../shared_setup.ipynb
In [2]:
chrom_offset = dict()
for i, chrom in enumerate(CHROMOSOMES):
chrom_offset[chrom] = sum(len(fasta[str(c, 'ascii')]) for c in CHROMOSOMES[:i])
chrom_offset
Out[2]:
In [3]:
tbl_co = (
etl
.frompickle(os.path.join(PUBLIC_DIR, 'tbl_co.pickle'))
.addfield('pos_abs', lambda row: chrom_offset[row.chrom] + row.co_pos_mid)
.sort('pos_abs')
)
display_with_nrows(tbl_co, caption='CO events')
In [4]:
tbl_nco = (etl
.frompickle(os.path.join(PUBLIC_DIR, 'tbl_conversion_tracts.pickle'))
.eq('tract_type', 'NCO')
# exclude the really long outliers
.lt('tract_length_min', 18000)
.addfield('pos_abs', lambda row: chrom_offset[row.chrom] + row.tract_start_max)
.sort('pos_abs')
)
display_with_nrows(tbl_nco, caption='NCO tracts')
In [5]:
totsize = sum(len(fasta[str(chrom, 'ascii')]) for chrom in CHROMOSOMES)
totsize
Out[5]:
In [6]:
fig, ax = plt.subplots(figsize=(7, 1))
x = tbl_nco.values('pos_abs').array()
ax.vlines(x, 0, 1)
ax.set_xlim(0, totsize);
In [7]:
fig, ax = plt.subplots(figsize=(7, 1))
x = tbl_co.values('pos_abs').array()
ax.vlines(x, 0, 1)
ax.set_xlim(0, totsize);
In [8]:
v = tbl_co.values('pos_abs').array()
y, windows = allel.stats.windowed_count(v, 5000, start=0, stop=totsize)
x = windows.mean(axis=1)
fig, ax = plt.subplots(figsize=(7, 1))
sns.despine(ax=ax, offset=5)
ax.plot(x, y, lw=.2)
ax.set_xlim(0, totsize);
In [9]:
v = tbl_nco.values('pos_abs').array()
y, windows = allel.stats.windowed_count(v, 5000, start=0, stop=totsize)
x = windows.mean(axis=1)
fig, ax = plt.subplots(figsize=(7, 1))
sns.despine(ax=ax, offset=5)
ax.plot(x, y)
ax.set_xlim(0, totsize);
In [10]:
v1 = tbl_co.values('pos_abs').array()
y1, windows = allel.stats.windowed_count(v1, 20000, start=0, stop=totsize)
v2 = tbl_nco.values('pos_abs').array()
y2, windows = allel.stats.windowed_count(v2, 20000, start=0, stop=totsize)
x = windows.mean(axis=1)
fig, ax = plt.subplots(figsize=(7, 1))
sns.despine(ax=ax, offset=5)
ax.fill_between(x, 0, y1, color='b', lw=0.5)
ax.fill_between(x, y1, y1+y2, color='r', lw=0.5)
ax.set_xlim(0, totsize);
In [11]:
window_size = 50000
v1 = tbl_co.values('pos_abs').array()
y1, windows = allel.stats.windowed_count(v1, window_size, start=0, stop=totsize)
v2 = tbl_nco.values('pos_abs').array()
y2, windows = allel.stats.windowed_count(v2, window_size, start=0, stop=totsize)
x = windows.mean(axis=1)
fig, ax = plt.subplots(figsize=(7, 1))
sns.despine(ax=ax, offset=5)
ax.bar(left=windows[:, 0], height=y2, width=window_size, color='b', lw=0)
ax.bar(left=windows[:, 0], height=y1, bottom=y2, width=window_size, color='r', lw=0)
ax.set_xlim(0, totsize);
In [12]:
max_chr_size = max(len(fasta[str(chrom, 'ascii')]) for chrom in CHROMOSOMES)
fig = plt.figure(figsize=(7, 9))
gs = mpl.gridspec.GridSpec(4*14, 1, height_ratios=[1, 1, 1, 1]*14)
gs.update(hspace=0)
for i, chrom in enumerate(CHROMOSOMES):
ax = fig.add_subplot(gs[i*4+0])
sns.despine(ax=ax, left=True, bottom=True)
x = tbl_co.eq('chrom', chrom).values('co_pos_mid').array()
ax.vlines(x, 0, 1)
ax.set_yticks([])
ax.set_xticks([])
ax.set_xlim(-5000, max_chr_size)
ax.set_ylabel('CO', rotation=0, ha='right', va='center', fontsize=8)
ax = fig.add_subplot(gs[i*4+1])
sns.despine(ax=ax, left=True, bottom=True)
x = tbl_nco.eq('chrom', chrom).values('tract_start_max').array()
ax.vlines(x, 0, 1)
ax.set_yticks([])
ax.set_xticks([])
ax.set_xlim(-5000, max_chr_size)
ax.set_ylabel('NCO', rotation=0, ha='right', va='center', fontsize=8)
chrom = str(chrom, 'ascii')
ax = fig.add_subplot(gs[i*4+2])
plot_accessibility(ax, chrom, linewidth=.5)
ax.set_xlim(-5000, max_chr_size)
chrnum = int(chrom[6:8])
ax.set_ylabel(chrnum, ha='right', va='center', rotation=0)
fig.tight_layout()
fn = '../../artwork/supp/recombination_map.{dpi}.{fmt}'
for fmt in 'jpeg', 'png':
for dpi in 120, 300:
fig.savefig(fn.format(dpi=dpi, fmt=fmt), dpi=dpi, jpeg_quality=100)
In [13]:
max_chr_size = max(len(fasta[str(chrom, 'ascii')]) for chrom in CHROMOSOMES)
fig = plt.figure(figsize=(7, 9))
gs = mpl.gridspec.GridSpec(4*14, 1, height_ratios=[1, 1, 1, 1]*14)
gs.update(hspace=0)
for i, chrom in enumerate(CHROMOSOMES):
ax = fig.add_subplot(gs[i*4+0])
sns.despine(ax=ax, left=True, bottom=True)
x = tbl_co.eq('chrom', chrom).values('co_pos_mid').array()
ax.vlines(x, 0, 1)
ax.set_yticks([])
ax.set_xticks([])
ax.set_xlim(-5000, max_chr_size)
ax.set_ylabel('CO', rotation=0, ha='right', va='center', fontsize=8)
ax = fig.add_subplot(gs[i*4+1])
sns.despine(ax=ax, left=True, bottom=True)
x = tbl_nco.eq('chrom', chrom).values('tract_start_max').array()
ax.vlines(x, 0, 1)
ax.set_yticks([])
ax.set_xticks([])
ax.set_xlim(-5000, max_chr_size)
ax.set_ylabel('NCO', rotation=0, ha='right', va='center', fontsize=8)
chrom = str(chrom, 'ascii')
ax = fig.add_subplot(gs[i*4+2])
plot_accessibility(ax, chrom, linewidth=.5)
ax.set_xlim(-5000, max_chr_size)
chrnum = int(chrom[6:8])
ax.set_ylabel(chrnum, ha='right', va='center', rotation=0)
fig.tight_layout()
# fn = '../../artwork/supp/genome_regions_map.{dpi}.{fmt}'
# for fmt in 'jpeg', 'png':
# for dpi in 120, 300:
# fig.savefig(fn.formatm(dpi=dpi, fmt=fmt), dpi=dpi, jpeg_quality=100)
In [ ]:
In [14]:
cmp = ['SC05/PG0019-C/ERR019051', '7C126/PG0047-C/ERR015452']
tbl_co.valuecounts('sample').selectin('sample', cmp).displayall(caption='CO')
tbl_nco.valuecounts('sample').selectin('sample', cmp).displayall(caption='NCO')
tbl_nco.selectin('sample', cmp).displayall(caption='NCO')
In [15]:
tbl_nco.valuecounts('sample').displayall()
In [ ]: