| |
| from tools.preprocess import * |
|
|
| |
| trait = "Endometrioid_Cancer" |
| cohort = "GSE94523" |
|
|
| |
| in_trait_dir = "../DATA/GEO/Endometrioid_Cancer" |
| in_cohort_dir = "../DATA/GEO/Endometrioid_Cancer/GSE94523" |
|
|
| |
| out_data_file = "./output/z2/preprocess/Endometrioid_Cancer/GSE94523.csv" |
| out_gene_data_file = "./output/z2/preprocess/Endometrioid_Cancer/gene_data/GSE94523.csv" |
| out_clinical_data_file = "./output/z2/preprocess/Endometrioid_Cancer/clinical_data/GSE94523.csv" |
| json_path = "./output/z2/preprocess/Endometrioid_Cancer/cohort_info.json" |
|
|
|
|
| |
| from tools.preprocess import * |
| |
| soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
| |
| background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design'] |
| clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1'] |
| background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes) |
|
|
| |
| sample_characteristics_dict = get_unique_values_by_row(clinical_data) |
|
|
| |
| print("Background Information:") |
| print(background_info) |
| print("Sample Characteristics Dictionary:") |
| print(sample_characteristics_dict) |
|
|
| |
| |
| is_gene_available = True |
|
|
| |
|
|
| |
| trait_row = None |
| age_row = None |
| gender_row = None |
|
|
| |
| def convert_trait(value): |
| """Convert trait values to binary (0/1)""" |
| if value is None: |
| return None |
| value = str(value).split(':')[-1].strip().lower() |
| if 'endometrioid' in value or 'adenocarcinoma' in value: |
| return 1 |
| else: |
| return 0 |
|
|
| def convert_age(value): |
| """Convert age to continuous numeric values""" |
| if value is None: |
| return None |
| try: |
| value = str(value).split(':')[-1].strip() |
| return float(value) |
| except: |
| return None |
|
|
| def convert_gender(value): |
| """Convert gender to binary (0=female, 1=male)""" |
| if value is None: |
| return None |
| value = str(value).split(':')[-1].strip().lower() |
| if 'female' in value or 'f' in value: |
| return 0 |
| elif 'male' in value or 'm' in value: |
| return 1 |
| else: |
| return None |
|
|
| |
| is_trait_available = trait_row is not None |
| save_cohort_info = validate_and_save_cohort_info( |
| is_final=False, |
| cohort=cohort, |
| info_path=json_path, |
| is_gene_available=is_gene_available, |
| is_trait_available=is_trait_available |
| ) |
|
|
| |
| |
|
|
| |
| |
| gene_data = get_genetic_data(matrix_file) |
|
|
| |
| print(gene_data.index[:20]) |
|
|
| |
| |
| gene_identifiers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'] |
|
|
| |
| |
| |
| print("Sample gene identifiers:", gene_identifiers[:10]) |
|
|
| |
| |
| |
|
|
| requires_gene_mapping = True |
|
|
| |
| |
| gene_annotation = get_gene_annotation(soft_file) |
|
|
| |
| print("Gene annotation preview:") |
| print(preview_df(gene_annotation)) |
|
|
| |
| |
| prob_col = 'ID' |
| gene_col = 'HUGO' |
|
|
| |
| gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col) |
|
|
| |
| gene_data = apply_gene_mapping(gene_data, gene_mapping) |
|
|
| print(f"Gene expression data shape after mapping: {gene_data.shape}") |
| print(f"First few gene symbols: {gene_data.index[:10].tolist()}") |
|
|
| |
| |
| normalized_gene_data = normalize_gene_symbols_in_index(gene_data) |
| normalized_gene_data.to_csv(out_gene_data_file) |
|
|
| |
| |
| clinical_data_empty = pd.DataFrame() |
| linked_data = normalized_gene_data.T |
|
|
| |
| |
| linked_data = linked_data.fillna(linked_data.mean()) |
|
|
| |
| |
| is_trait_biased = True |
| unbiased_linked_data = linked_data |
|
|
| |
| is_usable = validate_and_save_cohort_info( |
| is_final=True, |
| cohort=cohort, |
| info_path=json_path, |
| is_gene_available=True, |
| is_trait_available=False, |
| is_biased=is_trait_biased, |
| df=unbiased_linked_data, |
| note="INFO: Dataset contains only constant trait values (all endometrioid adenocarcinoma), not suitable for associative studies" |
| ) |
|
|
| |
| if is_usable: |
| unbiased_linked_data.to_csv(out_data_file) |