python/pymethylprocess/preprocess.py
def meffil_encode(input_sample_sheet,output_sample_sheet):
    """Reformat file for meffil input."""
    from collections import defaultdict
    pheno=pd.read_csv(input_sample_sheet)
    sex_dict=defaultdict(lambda:'NA')
    sex_dict.update({'m':'M','f':'F','M':'M','F':'F','male':'M','female':'F','nan':'NA',np.nan:'NA'})
    k='Sex' if 'Sex' in list(pheno) else 'sex'
    if k in list(pheno):
        pheno.loc[:,k] = pheno[k].map(lambda x: sex_dict[str(x).lower()])
    pheno = pheno[[col for col in list(pheno) if not col.startswith('Unnamed:')]].rename(columns={'sex':'Sex'})
    if 'Sex' in list(pheno):
        d=defaultdict(lambda:'NA')
        d.update({'M':'M','F':'F'})
        pheno.loc[:,'Sex'] = pheno['Sex'].map(d)
        if (pheno['Sex']==pheno['Sex'].mode().values[0][0]).all():
            pheno=pheno.rename(columns={'Sex':'gender'})
    pheno.to_csv(output_sample_sheet)
Reformat file for meffil input.
Reformat file for meffil input.
Reformat file for meffil input .
def meffil_encode(input_sample_sheet,output_sample_sheet):
    from collections import defaultdict
    pheno=pd.read_csv(input_sample_sheet)
    sex_dict=defaultdict(lambda:'NA')
    sex_dict.update({'m':'M','f':'F','M':'M','F':'F','male':'M','female':'F','nan':'NA',np.nan:'NA'})
    k='Sex' if 'Sex' in list(pheno) else 'sex'
    if k in list(pheno):
        pheno.loc[:,k] = pheno[k].map(lambda x: sex_dict[str(x).lower()])
    pheno = pheno[[col for col in list(pheno) if not col.startswith('Unnamed:')]].rename(columns={'sex':'Sex'})
    if 'Sex' in list(pheno):
        d=defaultdict(lambda:'NA')
        d.update({'M':'M','F':'F'})
        pheno.loc[:,'Sex'] = pheno['Sex'].map(d)
        if (pheno['Sex']==pheno['Sex'].mode().values[0][0]).all():
            pheno=pheno.rename(columns={'Sex':'gender'})
    pheno.to_csv(output_sample_sheet)
def meffil_encode ( input_sample_sheet , output_sample_sheet ) : from collections import defaultdict pheno = pd . read_csv ( input_sample_sheet ) sex_dict = defaultdict ( lambda : 'NA' ) sex_dict . update ( { 'm' : 'M' , 'f' : 'F' , 'M' : 'M' , 'F' : 'F' , 'male' : 'M' , 'female' : 'F' , 'nan' : 'NA' , np . nan : 'NA' } ) k = 'Sex' if 'Sex' in list ( pheno ) else 'sex' if k in list ( pheno ) : pheno . loc [ : , k ] = pheno [ k ] . map ( lambda x : sex_dict [ str ( x ) . lower ( ) ] ) pheno = pheno [ [ col for col in list ( pheno ) if not col . startswith ( 'Unnamed:' ) ] ] . rename ( columns = { 'sex' : 'Sex' } ) if 'Sex' in list ( pheno ) : d = defaultdict ( lambda : 'NA' ) d . update ( { 'M' : 'M' , 'F' : 'F' } ) pheno . loc [ : , 'Sex' ] = pheno [ 'Sex' ] . map ( d ) if ( pheno [ 'Sex' ] == pheno [ 'Sex' ] . mode ( ) . values [ 0 ] [ 0 ] ) . all ( ) : pheno = pheno . rename ( columns = { 'Sex' : 'gender' } ) pheno . to_csv ( output_sample_sheet )
Reformat file for meffil input.
Reformat file for meffil input .
"""Reformat file for meffil input."""
input_sample_sheet
output_sample_sheet