python/pymethylprocess/preprocess.py
def split_preprocess_input_by_subtype(idat_csv,disease_only,subtype_delimiter, subtype_output_dir):
    """Split preprocess input samplesheet by disease subtype."""
    from collections import defaultdict
    subtype_delimiter=subtype_delimiter.replace('"','').replace("'","")
    os.makedirs(subtype_output_dir,exist_ok=True)
    pData=PreProcessPhenoData(idat_csv,'')
    idat_csv_basename = idat_csv.split('/')[-1]
    group_by_key = (pData.split_key('disease',subtype_delimiter) if disease_only else 'disease')
    pData_grouped = pData.pheno_sheet.groupby(group_by_key)
    default_qc_df=[]
    for name, group in pData_grouped:
        name=name.replace(' ','')
        new_sheet = idat_csv_basename.replace('.csv','_{}.csv'.format(name))
        new_out_dir = '{}/{}/'.format(subtype_output_dir,name)
        os.makedirs(new_out_dir, exist_ok=True)
        print(new_out_dir)
        if 'Sex' in list(group):
            d=defaultdict(lambda:'NA')
            d.update({'M':'M','F':'F'})
            group.loc[:,'Sex'] = group['Sex'].map(d)
            if (group['Sex']==group['Sex'].mode().values[0][0]).all():
                group=group.rename(columns={'Sex':'gender'})
        group.to_csv('{}/{}'.format(new_out_dir,new_sheet))
        default_qc_df.append([name,-1,0.05,0.05,0.05,0.05,5,-2])
    pd.DataFrame(default_qc_df,columns=['subtype','n_pcs','p_beadnum_samples','p_detection_samples','p_beadnum_cpgs','p_detection_cpgs','sex_sd','sex_cutoff']).to_csv(os.path.join(subtype_output_dir,'pc_qc_parameters.csv'))
Split preprocess input samplesheet by disease subtype.
Split preprocess input samplesheet by disease subtype.
Split preprocess input samplesheet by disease subtype .
def split_preprocess_input_by_subtype(idat_csv,disease_only,subtype_delimiter, subtype_output_dir):
    from collections import defaultdict
    subtype_delimiter=subtype_delimiter.replace('"','').replace("'","")
    os.makedirs(subtype_output_dir,exist_ok=True)
    pData=PreProcessPhenoData(idat_csv,'')
    idat_csv_basename = idat_csv.split('/')[-1]
    group_by_key = (pData.split_key('disease',subtype_delimiter) if disease_only else 'disease')
    pData_grouped = pData.pheno_sheet.groupby(group_by_key)
    default_qc_df=[]
    for name, group in pData_grouped:
        name=name.replace(' ','')
        new_sheet = idat_csv_basename.replace('.csv','_{}.csv'.format(name))
        new_out_dir = '{}/{}/'.format(subtype_output_dir,name)
        os.makedirs(new_out_dir, exist_ok=True)
        print(new_out_dir)
        if 'Sex' in list(group):
            d=defaultdict(lambda:'NA')
            d.update({'M':'M','F':'F'})
            group.loc[:,'Sex'] = group['Sex'].map(d)
            if (group['Sex']==group['Sex'].mode().values[0][0]).all():
                group=group.rename(columns={'Sex':'gender'})
        group.to_csv('{}/{}'.format(new_out_dir,new_sheet))
        default_qc_df.append([name,-1,0.05,0.05,0.05,0.05,5,-2])
    pd.DataFrame(default_qc_df,columns=['subtype','n_pcs','p_beadnum_samples','p_detection_samples','p_beadnum_cpgs','p_detection_cpgs','sex_sd','sex_cutoff']).to_csv(os.path.join(subtype_output_dir,'pc_qc_parameters.csv'))
def split_preprocess_input_by_subtype ( idat_csv , disease_only , subtype_delimiter , subtype_output_dir ) : from collections import defaultdict subtype_delimiter = subtype_delimiter . replace ( '"' , '' ) . replace ( "'" , "" ) os . makedirs ( subtype_output_dir , exist_ok = True ) pData = PreProcessPhenoData ( idat_csv , '' ) idat_csv_basename = idat_csv . split ( '/' ) [ - 1 ] group_by_key = ( pData . split_key ( 'disease' , subtype_delimiter ) if disease_only else 'disease' ) pData_grouped = pData . pheno_sheet . groupby ( group_by_key ) default_qc_df = [ ] for name , group in pData_grouped : name = name . replace ( ' ' , '' ) new_sheet = idat_csv_basename . replace ( '.csv' , '_{}.csv' . format ( name ) ) new_out_dir = '{}/{}/' . format ( subtype_output_dir , name ) os . makedirs ( new_out_dir , exist_ok = True ) print ( new_out_dir ) if 'Sex' in list ( group ) : d = defaultdict ( lambda : 'NA' ) d . update ( { 'M' : 'M' , 'F' : 'F' } ) group . loc [ : , 'Sex' ] = group [ 'Sex' ] . map ( d ) if ( group [ 'Sex' ] == group [ 'Sex' ] . mode ( ) . values [ 0 ] [ 0 ] ) . all ( ) : group = group . rename ( columns = { 'Sex' : 'gender' } ) group . to_csv ( '{}/{}' . format ( new_out_dir , new_sheet ) ) default_qc_df . append ( [ name , - 1 , 0.05 , 0.05 , 0.05 , 0.05 , 5 , - 2 ] ) pd . DataFrame ( default_qc_df , columns = [ 'subtype' , 'n_pcs' , 'p_beadnum_samples' , 'p_detection_samples' , 'p_beadnum_cpgs' , 'p_detection_cpgs' , 'sex_sd' , 'sex_cutoff' ] ) . to_csv ( os . path . join ( subtype_output_dir , 'pc_qc_parameters.csv' ) )
Split preprocess input samplesheet by disease subtype.
Split preprocess input samplesheet by disease subtype .
"""Split preprocess input samplesheet by disease subtype."""
idat_csv
disease_only
subtype_delimiter
subtype_output_dir