python/pymethylprocess/PreProcessDataTypes.py
def format_tcga(self, mapping_file="idat_filename_case.txt"):
        """Format clinical sheets if downloaded tcga idats.

        Parameters
        ----------
        mapping_file
            Maps uuids to proper tcga sample names, should be downloaded with tcga clinical information."""
        def decide_case_control(barcode):
            case_control_num = int(barcode.split('-')[3][:2])
            if case_control_num < 10:
                return 'case'
            elif case_control_num < 20:
                return 'normal'
            else:
                return 'control'
            return 0
        idats = glob.glob("{}/*.idat".format(self.idat_dir))
        barcode_mappings = pd.read_csv(mapping_file,sep='\t')
        barcode_mappings['barcodes'] = np.vectorize(lambda x: '-'.join(x.split('-')[:3]))(barcode_mappings['cases'])
        barcode_mappings['idats'] = barcode_mappings['file_name'].map(lambda x: x[:x.rfind('_')])
        barcode_mappings_d1 = dict(barcode_mappings[['barcodes','idats']].values.tolist())
        barcode_mappings['case_controls']= barcode_mappings['cases'].map(decide_case_control)
        barcode_mappings_d2 = dict(barcode_mappings[['barcodes','case_controls']].values.tolist())
        self.pheno_sheet['Basename'] = self.pheno_sheet['bcr_patient_barcode'].map(barcode_mappings_d1)
        self.pheno_sheet['case_control'] = self.pheno_sheet['bcr_patient_barcode'].map(barcode_mappings_d2)
        idat_basenames = np.unique(np.vectorize(lambda x: '_'.join(x.split('/')[-1].split('_')[:2]))(idats))
        self.pheno_sheet = self.pheno_sheet[self.pheno_sheet['Basename'].isin(idat_basenames)]
        self.pheno_sheet.loc[:,['Basename']] = self.pheno_sheet['Basename'].map(lambda x: self.idat_dir+x)
        self.pheno_sheet = self.pheno_sheet[['Basename', 'bcr_patient_barcode', 'disease', 'tumor_stage', 'vital_status', 'age_at_diagnosis', 'gender', 'race', 'ethnicity','case_control']].rename(columns={'tumor_stage':'stage','bcr_patient_barcode':'PatientID','vital_status':'vital','gender':'Sex','age_at_diagnosis':'age'})
Format clinical sheets if downloaded tcga idats.

        Parameters
        ----------
        mapping_file
            Maps uuids to proper tcga sample names, should be downloaded with tcga clinical information.
Format clinical sheets if downloaded tcga idats.
Parameters

mapping_file
Maps uuids to proper tcga sample names, should be downloaded with tcga clinical information.
Format clinical sheets if downloaded tcga idats . Parameters mapping_file Maps uuids to proper tcga sample names should be downloaded with tcga clinical information .
def format_tcga(self, mapping_file="idat_filename_case.txt"):
        def decide_case_control(barcode):
            case_control_num = int(barcode.split('-')[3][:2])
            if case_control_num < 10:
                return 'case'
            elif case_control_num < 20:
                return 'normal'
            else:
                return 'control'
            return 0
        idats = glob.glob("{}/*.idat".format(self.idat_dir))
        barcode_mappings = pd.read_csv(mapping_file,sep='\t')
        barcode_mappings['barcodes'] = np.vectorize(lambda x: '-'.join(x.split('-')[:3]))(barcode_mappings['cases'])
        barcode_mappings['idats'] = barcode_mappings['file_name'].map(lambda x: x[:x.rfind('_')])
        barcode_mappings_d1 = dict(barcode_mappings[['barcodes','idats']].values.tolist())
        barcode_mappings['case_controls']= barcode_mappings['cases'].map(decide_case_control)
        barcode_mappings_d2 = dict(barcode_mappings[['barcodes','case_controls']].values.tolist())
        self.pheno_sheet['Basename'] = self.pheno_sheet['bcr_patient_barcode'].map(barcode_mappings_d1)
        self.pheno_sheet['case_control'] = self.pheno_sheet['bcr_patient_barcode'].map(barcode_mappings_d2)
        idat_basenames = np.unique(np.vectorize(lambda x: '_'.join(x.split('/')[-1].split('_')[:2]))(idats))
        self.pheno_sheet = self.pheno_sheet[self.pheno_sheet['Basename'].isin(idat_basenames)]
        self.pheno_sheet.loc[:,['Basename']] = self.pheno_sheet['Basename'].map(lambda x: self.idat_dir+x)
        self.pheno_sheet = self.pheno_sheet[['Basename', 'bcr_patient_barcode', 'disease', 'tumor_stage', 'vital_status', 'age_at_diagnosis', 'gender', 'race', 'ethnicity','case_control']].rename(columns={'tumor_stage':'stage','bcr_patient_barcode':'PatientID','vital_status':'vital','gender':'Sex','age_at_diagnosis':'age'})
def format_tcga ( self , mapping_file = "idat_filename_case.txt" ) : def decide_case_control ( barcode ) : case_control_num = int ( barcode . split ( '-' ) [ 3 ] [ : 2 ] ) if case_control_num < 10 : return 'case' elif case_control_num < 20 : return 'normal' else : return 'control' return 0 idats = glob . glob ( "{}/*.idat" . format ( self . idat_dir ) ) barcode_mappings = pd . read_csv ( mapping_file , sep = '\t' ) barcode_mappings [ 'barcodes' ] = np . vectorize ( lambda x : '-' . join ( x . split ( '-' ) [ : 3 ] ) ) ( barcode_mappings [ 'cases' ] ) barcode_mappings [ 'idats' ] = barcode_mappings [ 'file_name' ] . map ( lambda x : x [ : x . rfind ( '_' ) ] ) barcode_mappings_d1 = dict ( barcode_mappings [ [ 'barcodes' , 'idats' ] ] . values . tolist ( ) ) barcode_mappings [ 'case_controls' ] = barcode_mappings [ 'cases' ] . map ( decide_case_control ) barcode_mappings_d2 = dict ( barcode_mappings [ [ 'barcodes' , 'case_controls' ] ] . values . tolist ( ) ) self . pheno_sheet [ 'Basename' ] = self . pheno_sheet [ 'bcr_patient_barcode' ] . map ( barcode_mappings_d1 ) self . pheno_sheet [ 'case_control' ] = self . pheno_sheet [ 'bcr_patient_barcode' ] . map ( barcode_mappings_d2 ) idat_basenames = np . unique ( np . vectorize ( lambda x : '_' . join ( x . split ( '/' ) [ - 1 ] . split ( '_' ) [ : 2 ] ) ) ( idats ) ) self . pheno_sheet = self . pheno_sheet [ self . pheno_sheet [ 'Basename' ] . isin ( idat_basenames ) ] self . pheno_sheet . loc [ : , [ 'Basename' ] ] = self . pheno_sheet [ 'Basename' ] . map ( lambda x : self . idat_dir + x ) self . pheno_sheet = self . pheno_sheet [ [ 'Basename' , 'bcr_patient_barcode' , 'disease' , 'tumor_stage' , 'vital_status' , 'age_at_diagnosis' , 'gender' , 'race' , 'ethnicity' , 'case_control' ] ] . rename ( columns = { 'tumor_stage' : 'stage' , 'bcr_patient_barcode' : 'PatientID' , 'vital_status' : 'vital' , 'gender' : 'Sex' , 'age_at_diagnosis' : 'age' } )
Format clinical sheets if downloaded tcga idats.
Format clinical sheets if downloaded tcga idats .
"""Format clinical sheets if downloaded tcga idats.

        Parameters
        ----------
        mapping_file
            Maps uuids to proper tcga sample names, should be downloaded with tcga clinical information."""
self
mapping_file