| |
| from tools.preprocess import * |
|
|
| |
| trait = "Epilepsy" |
| cohort = "GSE273630" |
|
|
| |
| in_trait_dir = "../DATA/GEO/Epilepsy" |
| in_cohort_dir = "../DATA/GEO/Epilepsy/GSE273630" |
|
|
| |
| out_data_file = "./output/z3/preprocess/Epilepsy/GSE273630.csv" |
| out_gene_data_file = "./output/z3/preprocess/Epilepsy/gene_data/GSE273630.csv" |
| out_clinical_data_file = "./output/z3/preprocess/Epilepsy/clinical_data/GSE273630.csv" |
| json_path = "./output/z3/preprocess/Epilepsy/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 _extract_value(cell): |
| if cell is None: |
| return None |
| if isinstance(cell, str): |
| parts = cell.split(":", 1) |
| return parts[1].strip() if len(parts) == 2 else cell.strip() |
| return cell |
|
|
| def convert_trait(x): |
| |
| val = _extract_value(x) |
| if val is None: |
| return None |
| s = str(val).strip().lower() |
| |
| positive_kw = ["epilep", "seizure", "ictal", "sz"] |
| |
| negative_kw = ["no epilepsy", "non-epilep", "without epilepsy", "seizure-free", "no seizure", "none"] |
| if any(k in s for k in negative_kw): |
| return 0 |
| if any(k in s for k in positive_kw): |
| |
| if "no " in s or "not " in s: |
| return 0 |
| return 1 |
| return None |
|
|
| def convert_age(x): |
| val = _extract_value(x) |
| if val is None: |
| return None |
| s = str(val) |
| |
| import re |
| m = re.search(r"(-?\d+\.?\d*)", s) |
| if m: |
| try: |
| return float(m.group(1)) |
| except: |
| return None |
| return None |
|
|
| def convert_gender(x): |
| val = _extract_value(x) |
| if val is None: |
| return None |
| s = str(val).strip().lower() |
| if s in ["male", "m", "man", "boy"]: |
| return 1 |
| if s in ["female", "f", "woman", "girl"]: |
| return 0 |
| |
| if "male" in s: |
| return 1 |
| if "female" in s: |
| return 0 |
| 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) |
|
|
| |
| |
|
|
| |
| |
| gene_data = get_genetic_data(matrix_file) |
|
|
| |
| print(gene_data.index[:20]) |
|
|
| |
| requires_gene_mapping = False |
| print(f"requires_gene_mapping = {requires_gene_mapping}") |
|
|
| |
| |
| normalized_gene_data = normalize_gene_symbols_in_index(gene_data) |
| normalized_gene_data.to_csv(out_gene_data_file) |
|
|
| |
| if (locals().get('selected_clinical_data') is not None) and (locals().get('trait_row') is not None): |
| |
| linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data) |
|
|
| |
| linked_data = handle_missing_values(linked_data, trait) |
|
|
| |
| is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
| |
| is_usable = validate_and_save_cohort_info( |
| is_final=True, |
| cohort=cohort, |
| info_path=json_path, |
| is_gene_available=True, |
| is_trait_available=True, |
| is_biased=is_trait_biased, |
| df=unbiased_linked_data, |
| note="INFO: Clinical features extracted and linked successfully." |
| ) |
|
|
| |
| if is_usable: |
| unbiased_linked_data.to_csv(out_data_file) |
| else: |
| |
| print("No clinical trait data available; skipping linking and final validation for this cohort.") |