# Path Configuration from tools.preprocess import * # Processing context trait = "Adrenocortical_Cancer" cohort = "GSE143383" # Input paths in_trait_dir = "../DATA/GEO/Adrenocortical_Cancer" in_cohort_dir = "../DATA/GEO/Adrenocortical_Cancer/GSE143383" # Output paths out_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/GSE143383.csv" out_gene_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/gene_data/GSE143383.csv" out_clinical_data_file = "./output/z1/preprocess/Adrenocortical_Cancer/clinical_data/GSE143383.csv" json_path = "./output/z1/preprocess/Adrenocortical_Cancer/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 re # 1) Gene expression data availability is_gene_available = True # Affymetrix PrimeView gene expression profiling (not miRNA/methylation) # 2) Variable availability based on Sample Characteristics Dictionary # Provided dictionary indicates only gender info at key 0 with multiple values. trait_row = None # ACC tumor-only cohort; trait is constant/not provided explicitly => not available age_row = None # No age field present gender_row = 0 # gender: F/M/unknown # 2.2) Conversion functions def _after_colon(val): if val is None: return None s = str(val) parts = s.split(":", 1) return parts[1].strip() if len(parts) == 2 else s.strip() def convert_trait(v): # Binary: 1 = Adrenocortical_Cancer (ACC/tumor), 0 = control/normal/benign x = _after_colon(v) if x is None or x == "": return None xl = x.lower() pos_terms = [ "adrenocortical carcinoma", "acc", "carcinoma", "tumor", "metastatic", "adrenocortical cancer" ] neg_terms = [ "normal", "control", "benign", "adjacent normal", "healthy", "adenoma", "hyperplasia" ] if any(term in xl for term in pos_terms): return 1 if any(term in xl for term in neg_terms): return 0 return None def convert_age(v): # Continuous: extract first numeric age in years x = _after_colon(v) if x is None or x == "": return None m = re.search(r"(\d+(\.\d+)?)", x) if not m: return None try: age = float(m.group(1)) if 0 <= age <= 120: return age except Exception: pass return None def convert_gender(v): # Binary: female=0, male=1, unknown=None x = _after_colon(v) if x is None or x == "": return None xl = x.strip().lower() if xl in {"f", "female", "woman", "women"}: return 0 if xl in {"m", "male", "man", "men"}: return 1 if xl in {"u", "unk", "unknown", "na", "n/a", "not available"}: return None # Heuristics if "female" in xl: return 0 if "male" in xl: return 1 return None # 3) Save metadata with initial filtering 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: skipped because trait_row is None (no usable trait variable)