| |
| from tools.preprocess import * |
|
|
| |
| trait = "Adrenocortical_Cancer" |
| cohort = "GSE68950" |
|
|
| |
| in_trait_dir = "../DATA/GEO/Adrenocortical_Cancer" |
| in_cohort_dir = "../DATA/GEO/Adrenocortical_Cancer/GSE68950" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/GSE68950.csv" |
| out_gene_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/gene_data/GSE68950.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/clinical_data/GSE68950.csv" |
| json_path = "./output/z1/preprocess/Adrenocortical_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) |
|
|
| |
| import os |
| import math |
| import pandas as pd |
|
|
| |
| is_gene_available = True |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| trait_row = 1 |
| age_row = None |
| gender_row = None |
|
|
| |
| def _post_colon(value): |
| if value is None: |
| return None |
| s = str(value) |
| if ':' in s: |
| s = s.split(':', 1)[1] |
| s = s.strip() |
| if s == '': |
| return None |
| return s |
|
|
| def convert_trait(v): |
| s = _post_colon(v) |
| if s is None: |
| return None |
| t = s.lower() |
| if t in {'na', 'n/a', '#n/a', 'unknown'}: |
| return None |
| |
| |
| if ('adrenocortical' in t and 'carcin' in t) \ |
| or (('adrenal' in t) and ('cortical' in t) and ('carcin' in t)) \ |
| or (('adrenal' in t) and ('cortex' in t) and ('carcin' in t)) \ |
| or ('adrenal cortical carcinoma' in t) \ |
| or ('adrenocortical carcinoma' in t) \ |
| or ('adrenal cortex carcinoma' in t): |
| return 1 |
| return 0 |
|
|
| def convert_age(v): |
| s = _post_colon(v) |
| if s is None: |
| return None |
| t = s.lower().replace('years', '').replace('year', '').replace('yrs', '').replace('yr', '').strip() |
| try: |
| val = float(t) |
| if math.isnan(val): |
| return None |
| return val |
| except Exception: |
| return None |
|
|
| def convert_gender(v): |
| s = _post_colon(v) |
| if s is None: |
| return None |
| t = s.strip().lower() |
| if t in {'female', 'f', 'woman', 'women', 'girl'}: |
| return 0 |
| if t in {'male', 'm', 'man', 'men', 'boy'}: |
| return 1 |
| return None |
|
|
| |
| is_trait_available = False |
| if trait_row is not None: |
| |
| try: |
| mapped = clinical_data.loc[trait_row].apply(convert_trait) |
| unique_vals = set([x for x in mapped if x is not None]) |
| |
| if unique_vals == {0, 1}: |
| is_trait_available = True |
| else: |
| |
| trait_row = None |
| except Exception: |
| |
| trait_row = None |
|
|
| |
| |
| _ = 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 |
| ) |
|
|
| |
| if trait_row is not None: |
| selected_clinical_df = geo_select_clinical_features( |
| clinical_df=clinical_data, |
| trait=trait, |
| trait_row=trait_row, |
| convert_trait=convert_trait, |
| age_row=age_row, |
| convert_age=convert_age, |
| gender_row=gender_row, |
| convert_gender=convert_gender |
| ) |
| preview = preview_df(selected_clinical_df) |
| print("Preview of selected clinical features:", preview) |
|
|
| os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True) |
| selected_clinical_df.to_csv(out_clinical_data_file) |
| else: |
| print("INFO: Trait is not available for association analysis in this cohort (constant or absent). Skipping clinical feature extraction. This is a cell line compendium without age or gender.") |