python/pymethylprocess/utils.py
def create_external_validation_set(train_pkl,query_pkl, output_pkl, cpg_replace_method):
    """Create external validation set containing same CpGs as training set."""
    import numpy as np, pandas as pd
    os.makedirs(output_pkl[:output_pkl.rfind('/')],exist_ok=True)
    ref_methyl_array=MethylationArray.from_pickle(train_pkl)
    ref_cpgs=np.array(list(ref_methyl_array.beta))
    query_methyl_array=MethylationArray.from_pickle(query_pkl)
    query_cpgs=np.array(list(query_methyl_array.beta))
    cpg_diff=np.setdiff1d(ref_cpgs,query_cpgs)
    if cpg_replace_method == 'mid':
        background=np.ones((query_methyl_array.beta.shape[0],len(cpg_diff)))*0.5
    elif cpg_replace_method == 'background':
        background = np.ones((query_methyl_array.beta.shape[0],len(cpg_diff)))*query_methyl_array.beta.mean().mean()
    concat_df=pd.DataFrame(background,index=query_methyl_array.beta.index,columns=cpg_diff)
    query_methyl_array.beta=pd.concat([query_methyl_array.beta.loc[:,np.intersect1d(ref_cpgs,query_cpgs)],concat_df],axis=1).loc[:,ref_cpgs]
    query_methyl_array.write_pickle(output_pkl)
Create external validation set containing same CpGs as training set.
Create external validation set containing same CpGs as training set.
Create external validation set containing same CpGs as training set .
def create_external_validation_set(train_pkl,query_pkl, output_pkl, cpg_replace_method):
    import numpy as np, pandas as pd
    os.makedirs(output_pkl[:output_pkl.rfind('/')],exist_ok=True)
    ref_methyl_array=MethylationArray.from_pickle(train_pkl)
    ref_cpgs=np.array(list(ref_methyl_array.beta))
    query_methyl_array=MethylationArray.from_pickle(query_pkl)
    query_cpgs=np.array(list(query_methyl_array.beta))
    cpg_diff=np.setdiff1d(ref_cpgs,query_cpgs)
    if cpg_replace_method == 'mid':
        background=np.ones((query_methyl_array.beta.shape[0],len(cpg_diff)))*0.5
    elif cpg_replace_method == 'background':
        background = np.ones((query_methyl_array.beta.shape[0],len(cpg_diff)))*query_methyl_array.beta.mean().mean()
    concat_df=pd.DataFrame(background,index=query_methyl_array.beta.index,columns=cpg_diff)
    query_methyl_array.beta=pd.concat([query_methyl_array.beta.loc[:,np.intersect1d(ref_cpgs,query_cpgs)],concat_df],axis=1).loc[:,ref_cpgs]
    query_methyl_array.write_pickle(output_pkl)
def create_external_validation_set ( train_pkl , query_pkl , output_pkl , cpg_replace_method ) : import numpy as np , pandas as pd os . makedirs ( output_pkl [ : output_pkl . rfind ( '/' ) ] , exist_ok = True ) ref_methyl_array = MethylationArray . from_pickle ( train_pkl ) ref_cpgs = np . array ( list ( ref_methyl_array . beta ) ) query_methyl_array = MethylationArray . from_pickle ( query_pkl ) query_cpgs = np . array ( list ( query_methyl_array . beta ) ) cpg_diff = np . setdiff1d ( ref_cpgs , query_cpgs ) if cpg_replace_method == 'mid' : background = np . ones ( ( query_methyl_array . beta . shape [ 0 ] , len ( cpg_diff ) ) ) * 0.5 elif cpg_replace_method == 'background' : background = np . ones ( ( query_methyl_array . beta . shape [ 0 ] , len ( cpg_diff ) ) ) * query_methyl_array . beta . mean ( ) . mean ( ) concat_df = pd . DataFrame ( background , index = query_methyl_array . beta . index , columns = cpg_diff ) query_methyl_array . beta = pd . concat ( [ query_methyl_array . beta . loc [ : , np . intersect1d ( ref_cpgs , query_cpgs ) ] , concat_df ] , axis = 1 ) . loc [ : , ref_cpgs ] query_methyl_array . write_pickle ( output_pkl )
Create external validation set containing same CpGs as training set.
Create external validation set containing same CpGs as training set .
"""Create external validation set containing same CpGs as training set."""
train_pkl
query_pkl
output_pkl
cpg_replace_method