diff --git a/Figures/Methylation/Methylation_Fig4a.html b/Figures/Methylation/Methylation_Fig4a.html new file mode 100644 index 0000000..86f77b2 --- /dev/null +++ b/Figures/Methylation/Methylation_Fig4a.html @@ -0,0 +1,7640 @@ + + + + + +Methylation_Fig4a + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+
+ + diff --git a/Figures/Methylation/Methylation_Fig4a.md b/Figures/Methylation/Methylation_Fig4a.md new file mode 100644 index 0000000..255450e --- /dev/null +++ b/Figures/Methylation/Methylation_Fig4a.md @@ -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) + + diff --git a/Figures/Methylation/Methylation_Fig4a.pdf b/Figures/Methylation/Methylation_Fig4a.pdf index d545c2a..e83ebf8 100644 Binary files a/Figures/Methylation/Methylation_Fig4a.pdf and b/Figures/Methylation/Methylation_Fig4a.pdf differ diff --git a/Figures/Methylation/Methylation_Fig4a_files/Methylation_Fig4a_5_0.png b/Figures/Methylation/Methylation_Fig4a_files/Methylation_Fig4a_5_0.png new file mode 100644 index 0000000..eaebe5e Binary files /dev/null and b/Figures/Methylation/Methylation_Fig4a_files/Methylation_Fig4a_5_0.png differ diff --git a/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.html b/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.html new file mode 100644 index 0000000..e63e5d3 --- /dev/null +++ b/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.html @@ -0,0 +1,7908 @@ + + + + + +HR_gene_methylation_HRDetect_correlation + + + + + + + + + + + + +
+ +
+ +
+ + +
+ +
+
+ + diff --git a/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.md b/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.md new file mode 100644 index 0000000..32b6277 --- /dev/null +++ b/Figures/ts_methylation/HR_gene_methylation_HRDetect_correlation.md @@ -0,0 +1,379 @@ +```python +import pandas as pd +import logging +import numpy as np +import matplotlib.collections as mcollections +from matplotlib.pylab import plt +import seaborn as sns +from matplotlib.lines import Line2D +import warnings +%matplotlib inline + +warnings.filterwarnings("ignore") + +params = {"font.family":"Arial", +"legend.fontsize": 10, + "axes.labelsize": 12, + "axes.titlesize": 12, + "xtick.labelsize": 12, + "ytick.labelsize": 12, + "svg.fonttype": 'none'} +plt.rcParams.update(params) + +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + +### COLORS FOR ALTERATIONS +cmap_1 = plt.cm.get_cmap("Set2") +cmap_2 = plt.cm.get_cmap("tab20c") +GERMLINE_COLOR = cmap_1(5) +SOMATIC_COLOR = cmap_1(1) +GERMLINE_SOMATIC_COLOR = cmap_1(0) +BOXPLOT_COLOR = cmap_2(19) +NO_ALT_COLOR = cmap_2(17) + + +PALETTE = {"no alt":NO_ALT_COLOR, "germline+somatic":GERMLINE_SOMATIC_COLOR, "germline":GERMLINE_COLOR, "somatic":SOMATIC_COLOR} +OFFSET_METHYLATED = {"BRCA1": 0.65, + "RAD51C": 0.55} +``` + + +```python +########################################################################################### +##### correlate fraction of methylation sites in HR genes and HRDetect results ############ +########################################################################################### + +def generate_HRDetect_plot_BRC_OVA(df_methyl_BRC_OVA, df_methyl_non_BRC_OVA, palette, offset_methylated): + + tumour_types = ["BRC_OVA", "non_BRC_OVA"] + + for tumour_type in tumour_types: + if tumour_type == "BRC_OVA": + ### Figure5a + logger.info("generating HRDetect plots for BRC and OVA samples") + df_methyl = df_methyl_BRC_OVA + else: + ### Ex Figure 5a + logger.info("generating HRDetect plots for non BRC and OVA samples") + df_methyl = df_methyl_non_BRC_OVA + + goi = ["BRCA1", "RAD51C"] + + fig_HRDetect, ax_HRDetect = plt.subplots(1, 2, sharex = False, sharey = False, figsize = (8.5, 4.5), dpi = 600) + ax_HRDetect = ax_HRDetect.flatten() + ### dummy figure + fig_swarm, ax_swarm = plt.subplots(1, 2, sharex = False, sharey = True, figsize = (8.5, 4.5), dpi = 150) + ax_swarm= ax_swarm.flatten() + + for gene_index, gene in enumerate(goi): + logger.info(gene) + df_plot_offset = df_methyl.copy() + loh_column = gene+"_loh" + + for i in df_plot_offset.index: + if gene == "BRCA1": + if df_plot_offset.loc[i, gene] >= offset_methylated[gene]: + df_plot_offset.loc[i, "methylated"] = "yes" + else: + df_plot_offset.loc[i, "methylated"] = "no" + else: + if df_plot_offset.loc[i, gene] >= offset_methylated[gene]: + df_plot_offset.loc[i, "methylated"] = "yes" + else: + df_plot_offset.loc[i, "methylated"] = "no" + + df_plot_offset["LOH"] = np.nan + for i in df_plot_offset.index: + if "LOH" in df_plot_offset.loc[i, loh_column]: + df_plot_offset.loc[i, "LOH"] = "yes" + else: + df_plot_offset.loc[i, "LOH"] = "no" + + swarm = sns.swarmplot(x="methylated", y = "HRDetect", data=df_plot_offset, ax = ax_swarm[gene_index]) + artists = swarm.get_children() + offsets = {} + for index, a in enumerate(artists): + if (type(a) is mcollections.PathCollection) and len(a.get_offsets()) > 0: + offsets[index] = a.get_offsets() + + plt.close(fig_swarm) + + for index in df_plot_offset.index: + if df_plot_offset.loc[index, "methylated"] == "no": + offset_index = 0 + else: + offset_index = 1 + + minx = offsets[offset_index][0, 0] + miny = offsets[offset_index][0, 1] + for (x, y) in offsets[offset_index]: + + hrd = df_plot_offset.loc[index, "HRDetect"] + + if abs(miny - hrd) > abs(y - hrd): + miny = y + minx = x + + df_plot_offset.loc[index, "x"] = minx + df_plot_offset.loc[index, "y"] = miny + + sns.boxplot(x= "methylated", y = "HRDetect", data = df_plot_offset, ax = ax_HRDetect[gene_index], fliersize =2, linewidth = 0.6, color = "white") + alt = None + color = None + for pog in df_plot_offset.index: + alt = df_plot_offset.loc[pog, "HR_alt"] + color = palette[alt] + if df_plot_offset.loc[pog, "LOH"] == "yes": + ax_HRDetect[gene_index].scatter(df_plot_offset.loc[pog, "x"], df_plot_offset.loc[pog, "y"], marker = "o", s = 40, facecolors = "none", edgecolors = color, linewidth = 1.2) + else: + ax_HRDetect[gene_index].scatter(df_plot_offset.loc[pog, "x"], df_plot_offset.loc[pog, "y"], marker = "o", s = 40, facecolors = color, edgecolors = color, linewidth = 1.0) + + somatic_circle = Line2D([0], [0], marker="o", color="w", label="somatic", markerfacecolor=SOMATIC_COLOR, markersize=8) + germline_somatic_circle = Line2D([0], [0], marker="o", color="w", label="germline&somatic", markerfacecolor=GERMLINE_SOMATIC_COLOR, markersize=8) + no_alt_circle = Line2D([0], [0], marker="o", color="w", label="no alteration", markerfacecolor=NO_ALT_COLOR, markersize=8) + loh_circle = Line2D([0], [0], marker="o", color="w", label="w LOH", markerfacecolor="white", markeredgecolor=NO_ALT_COLOR, markersize=6) + no_loh_circle = Line2D([0], [0], marker="o", color="w", label="wo LOH", markerfacecolor=NO_ALT_COLOR, markersize=8) + + ax_HRDetect[gene_index].spines["right"].set_visible(False) + ax_HRDetect[gene_index].spines["top"].set_visible(False) + + ax_HRDetect[gene_index].set_title(gene) + ax_HRDetect[gene_index].set_xticks(range(0,2)) + + + ax_HRDetect[gene_index].set_ylabel(None) + ax_HRDetect[gene_index].set_xlabel(None) + + if gene_index == 0: + ax_HRDetect[gene_index].set_ylabel("HRDetect score") + + ax_HRDetect[gene_index].set_xlabel("promoter methylation") + + if gene_index == 1: + ax_HRDetect[gene_index].set_yticklabels("") + + fig_HRDetect.legend(handles = [no_alt_circle, somatic_circle, germline_somatic_circle, loh_circle, no_loh_circle], frameon=False, ncol= 5, loc="lower center", bbox_to_anchor=(0.5, -0.05), handletextpad=0.05, columnspacing=0.2) + fig_HRDetect.tight_layout() + + +def generate_TPM_plot_BRCA_OVA(df_methyl_BRC_OVA, df_BRCA1_RAD51C_logTPM, palette): + logger.info("generating TPM plots for BRC and OVA samples") + + goi = ["BRCA1", "RAD51C"] + fig_TPM_BRC_OVA, ax_TPM_BRC_OVA = plt.subplots(1, 2, sharex = False, sharey = False, figsize = (8.5, 4.5), dpi = 600) + ax_TPM_BRC_OVA = ax_TPM_BRC_OVA.flatten() + ### dummy figure + fig_swarm, ax_swarm = plt.subplots(1, 2, sharex = False, sharey = False, figsize = (9, 5), dpi = 150) + ax_swarm= ax_swarm.flatten() + + for gene_index, gene in enumerate(goi): + logger.info(gene) + loh_column = gene+"_loh" + df_fraction_plot = df_methyl_BRC_OVA[gene].to_frame() + df_TPM_plot = df_BRCA1_RAD51C_logTPM[gene].to_frame() + + df_TPM_fraction = df_fraction_plot.merge(df_TPM_plot, how = "left", left_index = True, right_index = True) + df_TPM_fraction.columns = ["fraction", "log2(TPM)"] + + for i in df_TPM_fraction.index: + if gene == "BRCA1": + if df_TPM_fraction.loc[i, "fraction"] >= 0.65: + df_TPM_fraction.loc[i, "methylated"] = "yes" + else: + df_TPM_fraction.loc[i, "methylated"] = "no" + else: + if df_TPM_fraction.loc[i, "fraction"] >= 0.55: + df_TPM_fraction.loc[i, "methylated"] = "yes" + else: + df_TPM_fraction.loc[i, "methylated"] = "no" + + for pog in df_TPM_fraction.index: + HR_alt = df_methyl_BRC_OVA.loc[pog, "HR_alt"] + BRCA1_loh = df_methyl_BRC_OVA.loc[pog, "BRCA1_loh"] + RAD51C_loh = df_methyl_BRC_OVA.loc[pog, "RAD51C_loh"] + df_TPM_fraction.loc[pog, "HR_alt"] = HR_alt + df_TPM_fraction.loc[pog, "BRCA1_loh"] = BRCA1_loh + df_TPM_fraction.loc[pog, "RAD51C_loh"] = RAD51C_loh + + df_TPM_fraction["LOH"] = np.nan + for i in df_TPM_fraction.index: + if "LOH" in df_TPM_fraction.loc[i, loh_column]: + df_TPM_fraction.loc[i, "LOH"] = "yes" + else: + df_TPM_fraction.loc[i, "LOH"] = "no" + + swarm = sns.swarmplot(x="methylated", y = "log2(TPM)", data=df_TPM_fraction, ax = ax_swarm[gene_index]) + artists = swarm.get_children() + offsets = {} + for index, a in enumerate(artists): + if (type(a) is mcollections.PathCollection) and len(a.get_offsets()) > 0: + offsets[index] = a.get_offsets() + + plt.close(fig_swarm) + + for index in df_TPM_fraction.index: + if df_TPM_fraction.loc[index, "methylated"] == "no": + offset_index = 0 + else: + offset_index = 1 + + minx = offsets[offset_index][0, 0] + miny = offsets[offset_index][0, 1] + for (x, y) in offsets[offset_index]: + + tpm = df_TPM_fraction.loc[index, "log2(TPM)"] + + if abs(miny - tpm) > abs(y - tpm): + miny = y + minx = x + + df_TPM_fraction.loc[index, "x"] = minx + df_TPM_fraction.loc[index, "y"] = miny + + sns.boxplot(x= "methylated", y = "log2(TPM)", data = df_TPM_fraction, ax = ax_TPM_BRC_OVA[gene_index], fliersize =2, linewidth = 0.6, color = "white") + alt = None + color = None + for pog in df_TPM_fraction.index: + alt = df_TPM_fraction.loc[pog, "HR_alt"] + color = palette[alt] + if df_TPM_fraction.loc[pog, "LOH"] == "yes": + ax_TPM_BRC_OVA[gene_index].scatter(df_TPM_fraction.loc[pog, "x"], df_TPM_fraction.loc[pog, "y"], marker = "o", s= 40, facecolors = "none", edgecolors = color, linewidth = 1.2) + else: + ax_TPM_BRC_OVA[gene_index].scatter(df_TPM_fraction.loc[pog, "x"], df_TPM_fraction.loc[pog, "y"], marker = "o", s= 40, facecolors = color, edgecolors = color, linewidth = 1.0) + + somatic_circle = Line2D([0], [0], marker="o", color="w", label="somatic", markerfacecolor=SOMATIC_COLOR, markersize=8) + germline_somatic_circle = Line2D([0], [0], marker="o", color="w", label="germline&somatic", markerfacecolor=GERMLINE_SOMATIC_COLOR, markersize=8) + no_alt_circle = Line2D([0], [0], marker="o", color="w", label="no alteration", markerfacecolor=NO_ALT_COLOR, markersize=8) + loh_circle = Line2D([0], [0], marker="o", color="w", label="w LOH", markerfacecolor="white", markeredgecolor=NO_ALT_COLOR, markersize=6) + no_loh_circle = Line2D([0], [0], marker="o", color="w", label="wo LOH", markerfacecolor=NO_ALT_COLOR, markersize=8) + + ax_TPM_BRC_OVA[gene_index].spines["right"].set_visible(False) + ax_TPM_BRC_OVA[gene_index].spines["top"].set_visible(False) + + ax_TPM_BRC_OVA[gene_index].set_title(gene) + ax_TPM_BRC_OVA[gene_index].set_xticks(range(0,2)) + + ax_TPM_BRC_OVA[gene_index].set_ylabel(None) + ax_TPM_BRC_OVA[gene_index].set_xlabel(None) + + ax_TPM_BRC_OVA[gene_index].set_yticks(range(0,8)) + ax_TPM_BRC_OVA[gene_index].set_ylim(-1.2, 6) + + if gene_index == 0: + ax_TPM_BRC_OVA[gene_index].set_ylabel("log2(TPM)") + + if gene_index == 1: + # ax_TPM_BRC_OVA[gene_index].spines["left"].set_visible(False) + ax_TPM_BRC_OVA[gene_index].set_yticklabels("") + # ax_TPM_BRC_OVA[gene_index].set_yticks([]) + + ax_TPM_BRC_OVA[gene_index].set_xlabel("promoter methylation") + + fig_TPM_BRC_OVA.legend(handles = [no_alt_circle, somatic_circle, germline_somatic_circle, loh_circle, no_loh_circle], frameon=False, ncol= 5, loc="lower center", bbox_to_anchor=(0.5, -0.05), handletextpad=0.05, columnspacing=0.2) + fig_TPM_BRC_OVA.tight_layout() + +``` + + +```python +def main(): + filename_methyl_fraction_BRC_OVA =r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation//BRCA1_RAD51C_fraction_of_methylated_sites_BRC_OVA.tsv" + filename_methyl_fraction_non_BRC_OVA = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation//BRCA1_RAD51C_fraction_of_methylated_sites_non_BRC_OVA.tsv" + filename_BRCA1_RAD51C_logTPM = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation//BRCA1_RAD51C_logTPM.tsv" + + df_methyl_BRC_OVA = pd.read_csv(filename_methyl_fraction_BRC_OVA, sep = "\t", index_col = "tumour_original_source") + df_methyl_non_BRC_OVA = pd.read_csv(filename_methyl_fraction_non_BRC_OVA, sep = "\t", index_col = "tumour_original_source") + df_BRCA1_RAD51C_logTPM = pd.read_csv(filename_BRCA1_RAD51C_logTPM, sep = "\t", index_col = "tumour_original_source") + + + generate_HRDetect_plot_BRC_OVA(df_methyl_BRC_OVA, df_methyl_non_BRC_OVA, PALETTE, OFFSET_METHYLATED) + + generate_TPM_plot_BRCA_OVA(df_methyl_BRC_OVA, df_BRCA1_RAD51C_logTPM, PALETTE) + +if __name__ == "__main__": + try: + main() + except Exception as err: + logger.critical("Failure: %s", err, exc_info=True) +``` + + CRITICAL:__main__:Failure: + Traceback (most recent call last): + File "/opt/conda/lib/python3.11/urllib/request.py", line 1348, in do_open + h.request(req.get_method(), req.selector, req.data, headers, + File "/opt/conda/lib/python3.11/http/client.py", line 1286, in request + self._send_request(method, url, body, headers, encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1332, in _send_request + self.endheaders(body, encode_chunked=encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1281, in endheaders + self._send_output(message_body, encode_chunked=encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1041, in _send_output + self.send(msg) + File "/opt/conda/lib/python3.11/http/client.py", line 979, in send + self.connect() + File "/opt/conda/lib/python3.11/http/client.py", line 1458, in connect + self.sock = self._context.wrap_socket(self.sock, + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/ssl.py", line 517, in wrap_socket + return self.sslsocket_class._create( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/ssl.py", line 1108, in _create + self.do_handshake() + File "/opt/conda/lib/python3.11/ssl.py", line 1379, in do_handshake + self._sslobj.do_handshake() + ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1006) + + During handling of the above exception, another exception occurred: + + Traceback (most recent call last): + File "/tmp/ipykernel_147/4130098315.py", line 17, in + main() + File "/tmp/ipykernel_147/4130098315.py", line 6, in main + df_methyl_BRC_OVA = pd.read_csv(filename_methyl_fraction_BRC_OVA, sep = "\t", index_col = "tumour_original_source") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1026, in read_csv + return _read(filepath_or_buffer, kwds) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 620, in _read + parser = TextFileReader(filepath_or_buffer, **kwds) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1620, in __init__ + self._engine = self._make_engine(f, self.engine) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1880, in _make_engine + self.handles = get_handle( + ^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 728, in get_handle + ioargs = _get_filepath_or_buffer( + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 384, in _get_filepath_or_buffer + with urlopen(req_info) as req: + ^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 289, in urlopen + return urllib.request.urlopen(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 216, in urlopen + return opener.open(url, data, timeout) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 519, in open + response = self._open(req, data) + ^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 536, in _open + result = self._call_chain(self.handle_open, protocol, protocol + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 496, in _call_chain + result = func(*args) + ^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 1391, in https_open + return self.do_open(http.client.HTTPSConnection, req, + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 1351, in do_open + raise URLError(err) + urllib.error.URLError: + + + +```python + +``` diff --git a/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.html b/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.html new file mode 100644 index 0000000..43a239a --- /dev/null +++ b/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.html @@ -0,0 +1,8077 @@ + + + + + +haplotype_specific_methylation_DNA_repair + + + + + + + + + + + + +
+
+ + diff --git a/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.md b/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.md new file mode 100644 index 0000000..81f8ba2 --- /dev/null +++ b/Figures/ts_methylation/haplotype_specific_methylation_DNA_repair.md @@ -0,0 +1,540 @@ +```python +import pandas as pd +import logging +import numpy as np +from matplotlib.pylab import plt +from statsmodels.nonparametric.smoothers_lowess import lowess +%matplotlib inline + +params = {"font.family":"Arial", +"legend.fontsize": 10, + "axes.labelsize": 12, + "axes.titlesize": 12, + "xtick.labelsize": 12, + "ytick.labelsize": 12, + "svg.fonttype": 'none'} +# plt.rcParams['svg.fonttype'] = 'none' +plt.rcParams.update(params) + +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + +### COLORS #### +TUMOUR_COLOR_HP1 = "#7C3A88" +TUMOUR_COLOR_HP2 = "#8A7EC7" +NORMAL_COLOR_HP1= "#69BDC3" +NORMAL_COLOR_HP2 = "#0B8892" + +### CASES WITH PROMOTER METHYLATION +BRCA1_METHYLATED_CASES_BRC_OVA = ["POG804", "POG507", "POG425"] +BRCA1_METHYLATED_CASES_NON_BRC_OVA = ["POG277", "POG1041", "POG650"] +BRCA1_LOH_CASES = ["POG804", "POG507", "POG425", "POG1041", "POG650"] + +RAD51C_METHYLATED_CASES_BRC_OVA = ["POG356", "POG894", "POG846"] +RAD51C_METHYLATED_CASES_NON_BRC_OVA = ["POG785", "POG266", "POG044"] +RAD51C_LOH_CASES = ["POG356", "POG894", "POG846"] +MLH1_METHYLATED_CASES = ["POG986", "POG041"] +MLH1_LOH_CASE = ["POG986"] +``` + + +```python +################ +#### BRCA1 ##### +################ + +def generate_BRCA1_haplotype_plots(BRCA1_files, BRCA1_methylated_cases_BRC_OVA, BRCA1_methylated_cases_non_BRC_OVA, BRCA1_loh_cases): + + tumour_types = ["BRC_OVA", "non_BRC_OVA"] + + for tumour_type in tumour_types: + df_blood = pd.DataFrame() + df_tumour = pd.DataFrame() + + if tumour_type == "BRC_OVA": + ### Figure 5c + case_list = BRCA1_methylated_cases_BRC_OVA + + else: + ### Ex Fig 5b + case_list = BRCA1_methylated_cases_non_BRC_OVA + + files_BRCA1 = BRCA1_files[tumour_type] + logger.info("generating BRCA1 haplotype plots for {}".format(tumour_type)) + + if len(files_BRCA1[0]) >0: + df_blood = pd.read_csv(files_BRCA1[0], sep = "\t", index_col = ["gene","start", "end"]) + if len(files_BRCA1[1])>0: + df_tumour = pd.read_csv(files_BRCA1[1], sep = "\t", index_col = ["gene","start", "end"]) + + + fig_BRCA1, ax_BRCA1 = plt.subplots(ncols=1, nrows=3, sharex = True, figsize = (8.5, 4.2), dpi = 600) + + for patient_index, patient in enumerate(case_list): + + LOH = "" + + hp1_column = f"{patient}_HP1" + hp2_column = f"{patient}_HP2" + + if patient in BRCA1_loh_cases: + LOH = "yes" + + if not df_tumour.empty: + hp1 = df_tumour[hp1_column] + hp2 = df_tumour[hp2_column] + xpos = [value[1] for value in df_tumour.index] + + ### LOESS SMOOTHING TUMOUR + filtered_hp1 = lowess(hp1, xpos, is_sorted=True, frac=0.25, it=0) + x_hp1 = filtered_hp1[:, 0] + y_hp1 = filtered_hp1[:, 1] + + filtered_hp2 = lowess(hp2, xpos, is_sorted=True, frac=0.25, it=0) + x_hp2 = filtered_hp2[:, 0] + y_hp2 = filtered_hp2[:, 1] + + if not df_blood.empty: + if hp1_column in df_blood.columns: + hp1_blood = df_blood[hp1_column] + hp2_blood = df_blood[hp2_column] + xpos_blood = [value[1] for value in df_blood.index] + + ### LOESS SMOOTHING BLOOD + filtered_hp1_blood = lowess(hp1_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp1_blood = filtered_hp1_blood[:, 0] + y_hp1_blood = filtered_hp1_blood[:, 1] + + filtered_hp2_blood = lowess(hp2_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp2_blood = filtered_hp2_blood[:, 0] + y_hp2_blood = filtered_hp2_blood[:, 1] + + if not df_tumour.empty: + if LOH == "yes": + if patient != "POG507": + ax_BRCA1[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_BRCA1[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor="none", mec = TUMOUR_COLOR_HP2, mew = 0.5, marker="o", markersize = 4.5, linewidth = 0.8, label = "HP2_tumour") + + ### flipping color because the haplotype was aribitary set for the cases + else: + ax_BRCA1[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_BRCA1[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP2, markerfacecolor="none", mec = TUMOUR_COLOR_HP2, mew = 0.5, marker="o", markersize = 4.5, linewidth = 0.8, label = "HP2_tumour") + else: + ax_BRCA1[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_BRCA1[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor=TUMOUR_COLOR_HP2, mec = TUMOUR_COLOR_HP2, marker="o", markersize = 4, linewidth = 0.8, label = "HP2_tumour") + + if not df_blood.empty: + ax_BRCA1[patient_index].plot(x_hp1_blood, y_hp1_blood, "-", color = NORMAL_COLOR_HP1, markerfacecolor=NORMAL_COLOR_HP1, mec = NORMAL_COLOR_HP1, marker="^", markersize = 4, linewidth = 0.8, label = "HP1_blood") + ax_BRCA1[patient_index].plot(x_hp2_blood, y_hp2_blood, "-", color = NORMAL_COLOR_HP2, markerfacecolor=NORMAL_COLOR_HP2, mec = NORMAL_COLOR_HP2, marker="^", markersize = 4, linewidth = 0.8, label = "HP2_blood") + + + ax_BRCA1[patient_index].set_ylim(-0.05, 1.1) + + xlims = plt.gca().get_xlim() + + xticks = ax_BRCA1[patient_index].get_xticks() + xticks = np.linspace(*xlims, 6) + ax_BRCA1[patient_index].set_xticks(xticks) + + + if patient_index >1: + + xticks = [str(int(value)) for value in xticks] + ax_BRCA1[patient_index].set_xticklabels(xticks) + + yticks = [0.0, 0.5, 1.0] + ax_BRCA1[patient_index].set_yticks(yticks) + yticks = [str(float(value)) for value in yticks] + ax_BRCA1[patient_index].set_yticklabels(yticks) + + ax_BRCA1[patient_index].tick_params(axis="both") + ax_BRCA1[patient_index].set_xlabel("genomic coordinates") + ax_BRCA1[patient_index].spines["right"].set_visible(False) + ax_BRCA1[patient_index].spines["top"].set_visible(False) + + else: + ax_BRCA1[patient_index].set_xticklabels("") + + yticks = [0.0, 0.5, 1.0] + ax_BRCA1[patient_index].set_yticks(yticks) + yticks = [str(float(value)) for value in yticks] + ax_BRCA1[patient_index].set_yticklabels(yticks) + + ax_BRCA1[patient_index].tick_params(axis="both") + + if patient_index == 1: + ax_BRCA1[patient_index].set_ylabel("methyl frequencies") + + ax_BRCA1[patient_index].set_ylim(-0.1, 1.05) + ax_BRCA1[patient_index].spines["right"].set_visible(False) + ax_BRCA1[patient_index].spines["top"].set_visible(False) + + ax_BRCA1[patient_index].text(43126965, -0.05, patient, size = "medium", weight = "bold") + + for i in range(3): + ax_BRCA1[i].set_xlim(ax_BRCA1[i].get_xlim()[::-1]) + + plt.legend(frameon=False, loc="lower left", bbox_to_anchor=(0.9, -0.05)) + plt.tight_layout() + +``` + + +```python +################### +##### RAD51C ###### +################### + +def generate_RAD51C_haplotype_plots(RAD51C_files, RAD51C_methylated_cases_BRC_OVA, RAD51C_methylated_cases_non_BRC_OVA, RAD51C_loh_cases): + + tumour_types = ["BRC_OVA", "non_BRC_OVA"] + + for tumour_type in tumour_types: + df_blood = pd.DataFrame() + df_tumour = pd.DataFrame() + + if tumour_type == "BRC_OVA": + ### Figure 5d + case_list = RAD51C_methylated_cases_BRC_OVA + + else: + ### Ex Fig 5c + case_list = RAD51C_methylated_cases_non_BRC_OVA + + files_RAD51C = RAD51C_files[tumour_type] + + if len(files_RAD51C[0]) >0: + df_blood = pd.read_csv(files_RAD51C[0], sep = "\t", index_col = ["gene","start", "end"]) + if len(files_RAD51C[1])>0: + df_tumour = pd.read_csv(files_RAD51C[1], sep = "\t", index_col = ["gene","start", "end"]) + + logger.info("generating RAD51C haplotype plots for {}".format(tumour_type)) + + fig_RAD51C, ax_RAD51C = plt.subplots(ncols=1, nrows=3,sharex = True, figsize = (8.5, 4.2), dpi = 600) + + for patient_index, patient in enumerate(case_list): + LOH = "" + hp1_column = f"{patient}_HP1" + hp2_column = f"{patient}_HP2" + + if patient in RAD51C_loh_cases: + LOH = "yes" + + + if not df_tumour.empty: + + hp1 = df_tumour[hp1_column] + hp2 = df_tumour[hp2_column] + xpos = [value[1] for value in df_tumour.index] + + ### LOESS SMOOTHING TUMOUR + filtered_hp1 = lowess(hp1, xpos, is_sorted=True, frac=0.25, it=0) + x_hp1 = filtered_hp1[:, 0] + y_hp1 = filtered_hp1[:, 1] + + filtered_hp2 = lowess(hp2, xpos, is_sorted=True, frac=0.25, it=0) + x_hp2 = filtered_hp2[:, 0] + y_hp2 = filtered_hp2[:, 1] + + if not df_blood.empty: + if hp1_column in df_blood.columns: + hp1_blood = df_blood[hp1_column] + hp2_blood = df_blood[hp2_column] + xpos_blood = [value[1] for value in df_blood.index] + + ### LOESS SMOOTHING BLOOD + filtered_hp1_blood = lowess(hp1_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp1_blood = filtered_hp1_blood[:, 0] + y_hp1_blood = filtered_hp1_blood[:, 1] + + filtered_hp2_blood = lowess(hp2_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp2_blood = filtered_hp2_blood[:, 0] + y_hp2_blood = filtered_hp2_blood[:, 1] + else: + x_hp1_blood = [] + y_hp1_blood = [] + x_hp2_blood = [] + y_hp2_blood = [] + + if not df_tumour.empty: + if LOH == "yes": + ax_RAD51C[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_RAD51C[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor="none", mec = TUMOUR_COLOR_HP2, mew = 0.5, marker="o", markersize = 4.5, linewidth = 0.8, label = "HP2_tumour") + else: + ax_RAD51C[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_RAD51C[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor=TUMOUR_COLOR_HP2, mec = TUMOUR_COLOR_HP2, marker="o", markersize = 4, linewidth = 0.8, label = "HP2_tumour") + if not df_blood.empty: + ax_RAD51C[patient_index].plot(x_hp1_blood, y_hp1_blood, "-", color = NORMAL_COLOR_HP1, markerfacecolor=NORMAL_COLOR_HP1, mec = NORMAL_COLOR_HP1, marker="^", markersize = 4, linewidth = 0.8, label = "HP1_blood") + ax_RAD51C[patient_index].plot(x_hp2_blood, y_hp2_blood, "-", color = NORMAL_COLOR_HP2, markerfacecolor=NORMAL_COLOR_HP2, mec = NORMAL_COLOR_HP2, marker="^", markersize = 4, linewidth = 0.8, label = "HP2_blood") + + ax_RAD51C[patient_index].set_ylim(-0.05, 1.2) + + xlims = plt.gca().get_xlim() + xticks = ax_RAD51C[patient_index].get_xticks() + xticks = np.linspace(*xlims, 6) + ax_RAD51C[patient_index].set_xticks(xticks) + + if patient_index >1: + + xticks = [str(int(value)) for value in xticks] + ax_RAD51C[patient_index].set_xticklabels(xticks) + + yticks = [0.0, 0.5, 1.0] + ax_RAD51C[patient_index].set_yticks(yticks) + yticks = [str(float(value)) for value in yticks] + ax_RAD51C[patient_index].set_yticklabels(yticks) + + ax_RAD51C[patient_index].tick_params(axis="both") + ax_RAD51C[patient_index].set_xlabel("genomic coordinates") + ax_RAD51C[patient_index].spines["right"].set_visible(False) + ax_RAD51C[patient_index].spines["top"].set_visible(False) + else: + ax_RAD51C[patient_index].set_xticklabels("") + + yticks = [0.0, 0.5, 1.0] + ax_RAD51C[patient_index].set_yticks(yticks) + yticks = [str(float(value)) for value in yticks] + ax_RAD51C[patient_index].set_yticklabels(yticks) + + ax_RAD51C[patient_index].tick_params(axis="both") + + + if patient_index == 1: + ax_RAD51C[patient_index].set_ylabel("methyl frequencies") + # ax[patient_index].legend(bbox_to_anchor=(1.04, 0.5), loc = "center left", fontsize = 9) + + ax_RAD51C[patient_index].set_ylim(-0.1, 1.05) + ax_RAD51C[patient_index].spines["right"].set_visible(False) + ax_RAD51C[patient_index].spines["top"].set_visible(False) + + ax_RAD51C[patient_index].text(58690993, -0.05, patient, size = "medium", weight = "bold") + + plt.legend(frameon=False, loc="lower left", bbox_to_anchor=(0.9, -0.05)) + plt.tight_layout() +``` + + +```python +################## +##### MLH1 ####### +################## + +def generate_MLH1_haplotype_plots(filename_MLH1_blood, filename_MLH1_tumour, MLH1_methylated_cases, MLH1_loh_case): + + logger.info("generating MLH1 haplotype plots") + + df_blood = pd.read_csv(filename_MLH1_blood, sep = "\t", index_col = ["gene","start", "end"]) + df_tumour = pd.read_csv(filename_MLH1_tumour, sep = "\t", index_col = ["gene","start", "end"]) + + fig_MLH1, ax_MLH1 = plt.subplots(ncols=1, nrows=2, sharex = True, figsize = (5.2, 4), dpi = 600) + + for patient_index, patient in enumerate(MLH1_methylated_cases): + LOH = "" + if patient in MLH1_loh_case: + LOH = "yes" + + if not df_tumour.empty: + hp1_column = f"{patient}_HP1" + hp2_column = f"{patient}_HP2" + + hp1 = df_tumour[hp1_column] + hp2 = df_tumour[hp2_column] + xpos = [value[1] for value in df_tumour.index] + + filtered_hp1 = lowess(hp1, xpos, is_sorted=True, frac=0.25, it=0) + x_hp1 = filtered_hp1[:, 0] + y_hp1 = filtered_hp1[:, 1] + + filtered_hp2 = lowess(hp2, xpos, is_sorted=True, frac=0.25, it=0) + x_hp2 = filtered_hp2[:, 0] + y_hp2 = filtered_hp2[:, 1] + + + if not df_blood.empty: + if hp1_column in df_blood.columns: + hp1_blood = df_blood[hp1_column] + hp2_blood = df_blood[hp2_column] + xpos_blood = [value[1] for value in df_blood.index] + + ### LOESS SMOOTHING BLOOD + filtered_hp1_blood = lowess(hp1_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp1_blood = filtered_hp1_blood[:, 0] + y_hp1_blood = filtered_hp1_blood[:, 1] + + filtered_hp2_blood = lowess(hp2_blood, xpos_blood, is_sorted=True, frac=0.25, it=0) + x_hp2_blood = filtered_hp2_blood[:, 0] + y_hp2_blood = filtered_hp2_blood[:, 1] + else: + x_hp1_blood = [] + y_hp1_blood = [] + x_hp2_blood = [] + y_hp2_blood = [] + + if LOH == "yes": + + if not df_tumour.empty: + ax_MLH1[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor="none", mec = TUMOUR_COLOR_HP1, mew = 0.5, marker="o", markersize = 4.5, linewidth = 0.8, label = "HP1_tumour") + ax_MLH1[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor=TUMOUR_COLOR_HP2, mec = TUMOUR_COLOR_HP2, marker="o", markersize = 4, linewidth = 0.8, label = "HP2_tumour") + + if not df_blood.empty: + ax_MLH1[patient_index].plot(x_hp2_blood, y_hp2_blood, "-", color = NORMAL_COLOR_HP1, markerfacecolor=NORMAL_COLOR_HP1, mec = NORMAL_COLOR_HP1, marker="^", markersize = 4, linewidth = 0.8, label = "HP1_blood") + ax_MLH1[patient_index].plot(x_hp1_blood, y_hp1_blood, "-", color = NORMAL_COLOR_HP2, markerfacecolor=NORMAL_COLOR_HP2, mec = NORMAL_COLOR_HP2, marker="^", markersize = 4, linewidth = 0.8, label = "HP2_blood") + + else: + if not df_tumour.empty: + ax_MLH1[patient_index].plot(x_hp1, y_hp1, "-", color = TUMOUR_COLOR_HP1, markerfacecolor=TUMOUR_COLOR_HP1, mec = TUMOUR_COLOR_HP1, marker="o", markersize = 4, linewidth = 0.8, label = "HP1_tumour") + ax_MLH1[patient_index].plot(x_hp2, y_hp2, "-", color = TUMOUR_COLOR_HP2, markerfacecolor=TUMOUR_COLOR_HP2, mec = TUMOUR_COLOR_HP2, marker="o", markersize = 4, linewidth = 0.8, label = "HP2_tumour") + + if not df_blood.empty: + ax_MLH1[patient_index].plot(x_hp2_blood, y_hp2_blood, "-", color = NORMAL_COLOR_HP1, markerfacecolor=NORMAL_COLOR_HP1, mec = NORMAL_COLOR_HP1, marker="^", markersize = 4, linewidth = 0.8, label = "HP1_blood") + ax_MLH1[patient_index].plot(x_hp1_blood, y_hp1_blood, "-", color = NORMAL_COLOR_HP2, markerfacecolor=NORMAL_COLOR_HP2, mec = NORMAL_COLOR_HP2, marker="^", markersize = 4, linewidth = 0.8, label = "HP2_blood") + + ax_MLH1[patient_index].set_ylim(-0.05, 1.1) + + ax_MLH1[patient_index].set_ylabel("methyl frequencies") + + xlims = plt.gca().get_xlim() + xticks = ax_MLH1[patient_index].get_xticks() + xticks = np.linspace(*xlims, 5) + ax_MLH1[patient_index].set_xticks(xticks) + + if patient_index >0: + + xticks = [str(int(value)) for value in xticks] + ax_MLH1[patient_index].set_xticklabels(xticks) + ax_MLH1[patient_index].tick_params(axis="both") + ax_MLH1[patient_index].set_xlabel("genomic coordinates") + ax_MLH1[patient_index].spines["right"].set_visible(False) + ax_MLH1[patient_index].spines["top"].set_visible(False) + else: + ax_MLH1[patient_index].set_xticklabels("") + ax_MLH1[patient_index].tick_params(axis="both") + + ax_MLH1[patient_index].spines["right"].set_visible(False) + ax_MLH1[patient_index].spines["top"].set_visible(False) + ax_MLH1[patient_index].text(36991870, -0.03, patient, size = "medium", weight = "bold") + + plt.legend(frameon=False, loc="lower left", bbox_to_anchor=(0.75, -0.05)) + plt.tight_layout() +``` + + +```python +def main(): + + ### BRCA1 Fig 5c + filename_BRCA1_BRC_OVA_blood = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/BRCA1_blood_haplotype_methyl_freq_BRC_OVA.tsv" + filename_BRCA1_BRC_OVA_tumour = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/BRCA1_tumour_haplotype_methyl_freq_BRC_OVA.tsv" + ### BRCA1 Ex Fig5b + filename_BRCA1_non_BRC_OVA_blood = r"" + filename_BRCA1_non_BRC_OVA_tumour = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation//BRCA1_tumour_haplotype_methyl_freq_non_BRC_OVA.tsv" + + BRCA1_files = {"BRC_OVA": [filename_BRCA1_BRC_OVA_blood, filename_BRCA1_BRC_OVA_tumour], + "non_BRC_OVA":[filename_BRCA1_non_BRC_OVA_blood, filename_BRCA1_non_BRC_OVA_tumour]} + + + generate_BRCA1_haplotype_plots(BRCA1_files, BRCA1_METHYLATED_CASES_BRC_OVA, BRCA1_METHYLATED_CASES_NON_BRC_OVA, BRCA1_LOH_CASES) + + ### RAD51C Fig 5d + filename_RAD51C_BRC_OVA_blood = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/RAD51C_blood_haplotype_methyl_freq_BRC_OVA.tsv" + filename_RAD51C_BRC_OVA_tumour = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/RAD51C_tumour_haplotype_methyl_freq_BRC_OVA.tsv" + ### RAD51C Ex Fig5c + filename_RAD51C_non_BRC_OVA_blood = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/RAD51C_blood_haplotype_methyl_freq_non_BRC_OVA.tsv" + filename_RAD51C_non_BRC_OVA_tumour = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/RAD51C_tumour_haplotype_methyl_freq_non_BRC_OVA.tsv" + + RAD51C_files = {"BRC_OVA": [filename_RAD51C_BRC_OVA_blood, filename_RAD51C_BRC_OVA_tumour], + "non_BRC_OVA":[filename_RAD51C_non_BRC_OVA_blood, filename_RAD51C_non_BRC_OVA_tumour]} + + + generate_RAD51C_haplotype_plots(RAD51C_files, RAD51C_METHYLATED_CASES_BRC_OVA, RAD51C_METHYLATED_CASES_NON_BRC_OVA, RAD51C_LOH_CASES) + + ### MLH1 Fig 5f + filename_MLH1_blood = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/MLH1_blood_haplotype_methyl_freq.tsv" + filename_MLH1_tumour = r"https://www.bcgsc.ca/downloads/nanopore_pog/ts_methylation/MLH1_tumour_haplotype_methyl_freq.tsv" + + generate_MLH1_haplotype_plots(filename_MLH1_blood, filename_MLH1_tumour, MLH1_METHYLATED_CASES, MLH1_LOH_CASE) + +if __name__ == "__main__": + try: + main() + except Exception as err: + logger.critical("Failure: %s", err, exc_info=True) +``` + + INFO:__main__:generating BRCA1 haplotype plots for BRC_OVA + CRITICAL:__main__:Failure: + Traceback (most recent call last): + File "/opt/conda/lib/python3.11/urllib/request.py", line 1348, in do_open + h.request(req.get_method(), req.selector, req.data, headers, + File "/opt/conda/lib/python3.11/http/client.py", line 1286, in request + self._send_request(method, url, body, headers, encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1332, in _send_request + self.endheaders(body, encode_chunked=encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1281, in endheaders + self._send_output(message_body, encode_chunked=encode_chunked) + File "/opt/conda/lib/python3.11/http/client.py", line 1041, in _send_output + self.send(msg) + File "/opt/conda/lib/python3.11/http/client.py", line 979, in send + self.connect() + File "/opt/conda/lib/python3.11/http/client.py", line 1458, in connect + self.sock = self._context.wrap_socket(self.sock, + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/ssl.py", line 517, in wrap_socket + return self.sslsocket_class._create( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/ssl.py", line 1108, in _create + self.do_handshake() + File "/opt/conda/lib/python3.11/ssl.py", line 1379, in do_handshake + self._sslobj.do_handshake() + ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1006) + + During handling of the above exception, another exception occurred: + + Traceback (most recent call last): + File "/tmp/ipykernel_186/2671134438.py", line 37, in + main() + File "/tmp/ipykernel_186/2671134438.py", line 14, in main + generate_BRCA1_haplotype_plots(BRCA1_files, BRCA1_METHYLATED_CASES_BRC_OVA, BRCA1_METHYLATED_CASES_NON_BRC_OVA, BRCA1_LOH_CASES) + File "/tmp/ipykernel_186/1885639513.py", line 25, in generate_BRCA1_haplotype_plots + df_blood = pd.read_csv(files_BRCA1[0], sep = "\t", index_col = ["gene","start", "end"]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1026, in read_csv + return _read(filepath_or_buffer, kwds) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 620, in _read + parser = TextFileReader(filepath_or_buffer, **kwds) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1620, in __init__ + self._engine = self._make_engine(f, self.engine) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1880, in _make_engine + self.handles = get_handle( + ^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 728, in get_handle + ioargs = _get_filepath_or_buffer( + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 384, in _get_filepath_or_buffer + with urlopen(req_info) as req: + ^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/site-packages/pandas/io/common.py", line 289, in urlopen + return urllib.request.urlopen(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 216, in urlopen + return opener.open(url, data, timeout) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 519, in open + response = self._open(req, data) + ^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 536, in _open + result = self._call_chain(self.handle_open, protocol, protocol + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 496, in _call_chain + result = func(*args) + ^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 1391, in https_open + return self.do_open(http.client.HTTPSConnection, req, + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/opt/conda/lib/python3.11/urllib/request.py", line 1351, in do_open + raise URLError(err) + urllib.error.URLError: +