-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c90082
commit 0dca27d
Showing
8 changed files
with
24,646 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
```python | ||
# Modules to import - get rid of any not used - add to dockfile in github | ||
import pandas as pd | ||
import scipy | ||
import datashader as ds | ||
from datashader.mpl_ext import dsshow | ||
import scipy.stats | ||
import matplotlib.pyplot as plt | ||
from matplotlib.colors import LinearSegmentedColormap | ||
import ssl | ||
from urllib.request import urlopen | ||
|
||
``` | ||
|
||
|
||
```python | ||
# import data - make sure to change to data from GSC website | ||
|
||
# use ssl to securely open csv before loading into pandas dataframe | ||
data_loc = 'https://www.bcgsc.ca/downloads/nanopore_pog/Methylation/POG044_BS_Nanopolish_Meth.bed.gz' | ||
|
||
context=ssl.create_default_context() | ||
context.set_ciphers("DEFAULT") | ||
result = urlopen(data_loc, context=context) | ||
|
||
POG044_BS_Nano_df = pd.read_csv(result, sep="\t",header=None, compression='gzip') | ||
|
||
``` | ||
|
||
|
||
```python | ||
# get columns of interest and drop null rows - i.e. BS methylation frequency and nanopore frequency | ||
POG044_BS_Nano_df_filt = POG044_BS_Nano_df.iloc[:,[2,3]].dropna() | ||
``` | ||
|
||
|
||
```python | ||
# calculate rho and value using pearson correlation for BS and Nanopolish frequencies | ||
r_BS_Nano, p_BS_Nano = scipy.stats.pearsonr(POG044_BS_Nano_df_filt[2].values, POG044_BS_Nano_df_filt[3].values) | ||
|
||
``` | ||
|
||
|
||
```python | ||
#Visualize Methylation Correlation using datashader - use figure axe | ||
def using_datashader(ax, x, y): | ||
|
||
# create dataframe | ||
df = pd.DataFrame(dict(x=x, y=y)) | ||
|
||
# plot data using viridis cmap and 1 to 1 scale | ||
dsartist = dsshow( | ||
df, | ||
ds.Point("x", "y"), | ||
ds.count(), | ||
norm="eq_hist", | ||
aspect="auto", | ||
cmap=viridis_cmap, | ||
width_scale=1, | ||
height_scale=1, | ||
ax=ax | ||
) | ||
|
||
#viridis cmap | ||
viridis_cmap = LinearSegmentedColormap.from_list('white_viridis', [ | ||
(0, '#440053'), | ||
(0.20, '#404388'), | ||
(0.40, '#2a788e'), | ||
(0.60, '#21a784'), | ||
(0.80, '#78d151'), | ||
(1, '#fde624'), | ||
], N=256) | ||
``` | ||
|
||
|
||
```python | ||
|
||
|
||
# Plot 5mC Results | ||
fig, ax = plt.subplots() | ||
using_datashader(ax, POG044_BS_Nano_df_filt[2], POG044_BS_Nano_df_filt[3]) | ||
# set background color and make aspect equal | ||
ax.set_facecolor('#440053') | ||
ax.set_aspect('equal', adjustable='box') | ||
# set lables | ||
plt.ylabel('WGBS', fontsize = 14, weight="bold") | ||
plt.xlabel('Nanopolish', fontsize = 14, weight="bold") | ||
plt.xlim(0,1) | ||
plt.ylim(0,1) | ||
plt.text(0.5, 1.1, f'Correlation: {round(r_BS_Nano,2)}', transform=ax.transAxes, ha='center', fontsize = 12, weight="bold") | ||
plt.text(0.5, 1.05, f'N: {len(POG044_BS_Nano_df_filt)}', transform=ax.transAxes, ha='center', fontsize = 12, weight="bold") | ||
ax.tick_params(axis='both', labelsize=12) | ||
plt.tight_layout() | ||
|
||
plt.savefig("Methylation_Fig4a.pdf", format="pdf", dpi = 70) | ||
``` | ||
|
||
|
||
|
||
![png](Methylation_Fig4a_files/Methylation_Fig4a_5_0.png) | ||
|
||
|
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.