| |
| from tools.preprocess import * |
|
|
| |
| trait = "Allergies" |
| cohort = "GSE169149" |
|
|
| |
| in_trait_dir = "../DATA/GEO/Allergies" |
| in_cohort_dir = "../DATA/GEO/Allergies/GSE169149" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Allergies/GSE169149.csv" |
| out_gene_data_file = "./output/z1/preprocess/Allergies/gene_data/GSE169149.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Allergies/clinical_data/GSE169149.csv" |
| json_path = "./output/z1/preprocess/Allergies/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 _after_colon(x): |
| if x is None: |
| return None |
| if not isinstance(x, str): |
| x = str(x) |
| parts = x.split(":", 1) |
| v = parts[1] if len(parts) > 1 else parts[0] |
| return v.strip() |
|
|
| def convert_trait(x): |
| |
| v = _after_colon(x) |
| if v is None or v == "": |
| return None |
| s = v.lower() |
|
|
| |
| pos_terms = [ |
| "allergy", "allergies", "allergic", "atopy", "atopic", "asthma", |
| "hay fever", "rhinitis", "eczema", "urticaria" |
| ] |
| if any(term in s for term in pos_terms): |
| return 1 |
|
|
| |
| neg_terms = [ |
| "non-atopic", "healthy control", "control", "no allergy", "without allergies", |
| "none", "negative", "neg", "absent" |
| ] |
| if any(term in s for term in neg_terms): |
| return 0 |
|
|
| |
| if s in {"yes", "y", "true", "1", "positive", "pos", "present"}: |
| return 1 |
| if s in {"no", "n", "false", "0"}: |
| return 0 |
|
|
| return None |
|
|
| def convert_age(x): |
| v = _after_colon(x) |
| if v is None or v == "": |
| return None |
| s = v.lower().replace("years", "").replace("year", "").replace("yrs", "").replace("yr", "").strip() |
| |
| if s in {"na", "n/a", "unknown", "none"}: |
| return None |
| |
| try: |
| return float(s.split()[0].replace(",", "")) |
| except Exception: |
| |
| import re |
| m = re.search(r"[-+]?\d*\.?\d+", s) |
| if m: |
| try: |
| return float(m.group(0)) |
| except Exception: |
| return None |
| return None |
|
|
| def convert_gender(x): |
| |
| v = _after_colon(x) |
| if v is None or v == "": |
| return None |
| s = v.strip().lower() |
| |
| if s in {"female", "f", "woman", "women"}: |
| return 0 |
| if s in {"male", "m", "man", "men"}: |
| return 1 |
| |
| if s in {"0", "1"}: |
| return 1 if s == "1" else 0 |
| if s in {"na", "n/a", "unknown", "none"}: |
| return None |
| return None |
|
|
| |
| is_trait_available = trait_row is not 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_df(selected_clinical_df) |
| |
| os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True) |
| selected_clinical_df.to_csv(out_clinical_data_file) |