# Path Configuration from tools.preprocess import * # Processing context trait = "Eczema" cohort = "GSE150797" # Input paths in_trait_dir = "../DATA/GEO/Eczema" in_cohort_dir = "../DATA/GEO/Eczema/GSE150797" # Output paths out_data_file = "./output/preprocess/1/Eczema/GSE150797.csv" out_gene_data_file = "./output/preprocess/1/Eczema/gene_data/GSE150797.csv" out_clinical_data_file = "./output/preprocess/1/Eczema/clinical_data/GSE150797.csv" json_path = "./output/preprocess/1/Eczema/cohort_info.json" # STEP1 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) # 1) Determine if gene expression data is available is_gene_available = True # From the background, it's a gene expression microarray study # 2) Identify the rows for the variables in the sample characteristics trait_row = None # Only one unique value: "Atopic dermatitis (AD) patient", so it's effectively not available age_row = None # No age information found gender_row = 1 # Row 1 has two unique values: "Male" / "Female" # 2.2) Define data conversion functions def convert_trait(x: str) -> int: # Not used in this dataset since trait_row is None, but we define it for completeness # Could parse something like "disease status: yes" -> 1, "disease status: no" -> 0 # For now, return None to indicate not used. return None def convert_age(x: str) -> float: # Not used in this dataset since age_row is None return None def convert_gender(x: str) -> int: # Parse the substring after the colon val = x.split(":", 1)[-1].strip().lower() if val == "male": return 1 elif val == "female": return 0 return None # 3) Perform initial filtering and save metadata is_trait_available = (trait_row is not None) is_usable = 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) Since trait_row is None, we skip clinical feature extraction # STEP3 # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined. gene_data = get_genetic_data(matrix_file) # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation. print(gene_data.index[:20]) # Based on the observed gene identifiers ("TC010000xxx.hg.1"), they are not recognized human gene symbols. # They seem to be probe identifiers that require mapping to official gene symbols. print("requires_gene_mapping = True") # STEP5 # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file. gene_annotation = get_gene_annotation(soft_file) # 2. Use the 'preview_df' function from the library to preview the data and print out the results. print("Gene annotation preview:") print(preview_df(gene_annotation)) # STEP: Gene Identifier Mapping # 1) Identify the annotation columns that match the gene expression data identifiers and contain gene symbols. # From our observations, 'ID' matches the gene expression index (e.g. "TC0100006437.hg.1"), # and 'SPOT_ID.1' stores the textual info from which human gene symbols can be extracted. # 2) Obtain the gene mapping dataframe from the annotation dataframe. mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='SPOT_ID.1') # 3) Convert probe-level measurements to gene-level expression by applying the gene mapping. gene_data = apply_gene_mapping(gene_data, mapping_df) # For confirmation, print the shape of the resulting gene_data. print("Gene expression data shape after mapping:", gene_data.shape) # STEP7 # 1) Normalize gene symbols and save normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # NOTE: From Step 2, we determined that trait_row is None, so there's no trait data. # Therefore, we cannot proceed with clinical-gene linking, missing-value handling, or bias checks. # 2) Perform an interim validation (not final) to record dataset unusability due to missing trait data. is_usable = validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=True, # This dataset does have gene expression data is_trait_available=False # No trait data available ) # 3) Since we do not have trait data, we skip the final linking and do not save any final linked data. # Pipeline ends here.