# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:anaconda3]
#     language: python
#     name: conda-env-anaconda3-py
# ---

# ## methylprep v1.6.3: Comparing noob_meth / noob_unmeth with sesame and minfi

import methylprep
import pandas as pd
from pathlib import Path

PATH = '../example_data/'
meth = pd.read_csv(Path(PATH,'GSE69852/9247377085/9247377085/9247377085_R04C02_processed.csv')).set_index('IlmnID')[['beta_value']]
meth = meth.rename(columns={'beta_value':'9247377085_R04C02'})
ses = pd.read_csv(Path(PATH,'GSE69852/sesame_betas.csv')).set_index('Unnamed: 0')[['9247377085_R04C02']]
ses.index.name = 'IlmnID'
minfi = pd.read_csv(Path(PATH,'minfi/minfi_noob_betas.csv')).set_index('Unnamed: 0')[['9247377085_R04C02']]
minfi.index.name = 'IlmnID'
minfi = minfi.sort_index()
meth162 = pd.read_csv(Path(PATH,'GSE69852/test_v162/9247377085/9247377085_R04C02_processed.csv')).set_index('IlmnID')[['beta_value']]
meth162 = meth162.rename(columns={'beta_value':'9247377085_R04C02'})

(meth-ses).plot.hist(bins=300, xlim=(-0.05, 0.05), title="methylprep 1.6.3 vs sesame")
(meth162-ses).plot.hist(bins=300, xlim=(-0.05, 0.05), title="methylprep 1.6.2 vs sesame")
print((meth-ses).mean(), (meth-ses).min(), (meth-ses).max())
print((meth162-ses).mean(), (meth162-ses).min(), (meth162-ses).max())

import numpy as np
_filter = (meth - ses) > 0.3
meth[_filter].dropna()

ignore = meth[_filter].dropna().index
meth_revised = meth[ ~meth.index.isin(ignore) ]
ses_revised = ses[ ~ses.index.isin(ignore) ]
print((meth_revised-ses_revised).mean(), (meth_revised-ses_revised).min(), (meth_revised-ses_revised).max())

ses

minfi.sort_index()

(meth-minfi).plot.hist(bins=300, xlim=(-0.05, 0.05), title="methylprep 1.6.3 vs minfi")
(meth162-minfi).plot.hist(bins=300, xlim=(-0.05, 0.05), title="methylprep 1.6.2 vs minfi")
print((meth-minfi).mean(), (meth-minfi).min(), (meth-minfi).max())
print((meth162-minfi).mean(), (meth162-minfi).min(), (meth162-minfi).max())



StarcoderdataJupyterScriptsDedupFiltered