# Path Configuration from tools.preprocess import * # Processing context trait = "Alcohol_Flush_Reaction" cohort = "GSE133228" # Input paths in_trait_dir = "../DATA/GEO/Alcohol_Flush_Reaction" in_cohort_dir = "../DATA/GEO/Alcohol_Flush_Reaction/GSE133228" # Output paths out_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/GSE133228.csv" out_gene_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/gene_data/GSE133228.csv" out_clinical_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/clinical_data/GSE133228.csv" json_path = "./output/z1/preprocess/Alcohol_Flush_Reaction/cohort_info.json" # Step 1: Initial Data Loading from tools.preprocess import * # 1. Identify the paths to the SOFT file and the matrix file soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) # 2. Read the matrix file to obtain background information and sample characteristics data 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) # 3. Obtain the sample characteristics dictionary from the clinical dataframe sample_characteristics_dict = get_unique_values_by_row(clinical_data) # 4. Explicitly print out all the background information and the sample characteristics dictionary print("Background Information:") print(background_info) print("Sample Characteristics Dictionary:") print(sample_characteristics_dict) # Step 2: Dataset Analysis and Clinical Feature Extraction import os import re import pandas as pd # 1) Gene expression availability judgment based on provided background: # SuperSeries focused on chromatin architecture (CTCF/STAG2, loop extrusion). No explicit gene expression evidence. # Treat as not containing usable gene expression matrix for our pipeline. is_gene_available = False # 2) Identify variable availability from the Sample Characteristics Dictionary provided: # Keys observed: # 0: gender: Male/Female # 1: age: integers # 2: tumor type: primary tumor (constant -> not useful) trait_row = None # Alcohol Flush Reaction not present or inferable age_row = 1 gender_row = 0 # 2.2 Converters def _after_colon(x): if x is None: return None s = str(x) parts = s.split(":", 1) v = parts[1] if len(parts) > 1 else parts[0] return v.strip() def convert_trait(x): # Binary: 1 = flusher/positive/yes/case, 0 = non-flusher/negative/no/control; unknown -> None v = _after_colon(x) if v is None or v == "": return None vl = v.strip().lower() if vl in {"na", "n/a", "not available", "unknown", "nan", "missing", "null"}: return None # Common synonyms positive_terms = { "yes", "y", "true", "positive", "pos", "case", "flusher", "with", "present", "af", "afr", "flush", "red face" } negative_terms = { "no", "n", "false", "negative", "neg", "control", "non-flusher", "without", "absent", "nonflusher", "none" } if vl in positive_terms: return 1 if vl in negative_terms: return 0 # Heuristics if "flusher" in vl or "flush" in vl or "red face" in vl: # infer flusher return 1 if "non" in vl and ("flusher" in vl or "flush" in vl): return 0 # Numeric fallback if vl.isdigit(): if vl == "1": return 1 if vl == "0": return 0 return None def convert_age(x): # Continuous age in years; extract first number v = _after_colon(x) if v is None or v == "": return None m = re.search(r"[-+]?\d*\.?\d+", v) if not m: return None try: return float(m.group()) except Exception: return None def convert_gender(x): # Binary: female=0, male=1 v = _after_colon(x) if v is None or v == "": return None vl = v.strip().lower() if vl in {"na", "n/a", "not available", "unknown", "nan", "missing", "null"}: return None if vl in {"male", "m", "man", "boy"}: return 1 if vl in {"female", "f", "woman", "girl"}: return 0 if vl == "1": return 1 if vl == "0": return 0 return None # 3) Initial filtering metadata save 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 ) # 4) Clinical feature extraction (only if trait is 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, n=5) print(preview) os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True) selected_clinical_df.to_csv(out_clinical_data_file)