# Path Configuration from tools.preprocess import * # Processing context trait = "Allergies" cohort = "GSE230164" # Input paths in_trait_dir = "../DATA/GEO/Allergies" in_cohort_dir = "../DATA/GEO/Allergies/GSE230164" # Output paths out_data_file = "./output/preprocess/1/Allergies/GSE230164.csv" out_gene_data_file = "./output/preprocess/1/Allergies/gene_data/GSE230164.csv" out_clinical_data_file = "./output/preprocess/1/Allergies/clinical_data/GSE230164.csv" json_path = "./output/preprocess/1/Allergies/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. Gene Expression Data Availability is_gene_available = True # Based on the "Gene expression profiling" title # 2. Variable Availability and Data Type Conversion # From the sample characteristics, we only see key=0 for "gender: female" and "gender: male". # Therefore: trait_row = None # "Allergies" not found age_row = None # Age not found gender_row = 0 # Found under key=0 # Conversion Functions def convert_trait(value: str): # Since we don't have trait data, return None if called (function is here for completeness) return None def convert_age(value: str): # Since we don't have age data, return None if called (function is here for completeness) return None def convert_gender(value: str): # Split at ':' and pick the last portion, then convert to 0/1 val = value.split(':')[-1].strip().lower() if val == 'female': return 0 elif val == 'male': return 1 return None # 3. Initial Filtering and Saving Metadata # trait_row is None => trait data is not available 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. Clinical Feature Extraction is skipped because trait_row is None # 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]) # These identifiers (e.g., ILMN_1343291) are Illumina probe IDs rather than standard gene symbols. # Therefore, they need to be mapped to 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. Select the columns from the gene_annotation dataframe for probe ID and gene symbol. # From the preview, the "ID" column matches the probe identifiers and "Symbol" stores the gene symbols. mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol") # 2. Apply the mapping to convert probe-level data into gene-level data. gene_data = apply_gene_mapping(gene_data, mapping_df) # (Optional) Peek at the results print("Gene expression dataframe shape:", gene_data.shape) print("First 10 gene symbols:", list(gene_data.index[:10])) import pandas as pd # STEP 7: Data Normalization and Linking # In this dataset, the trait is unavailable (trait_row was None), so we cannot proceed with linking or final processing # that relies on clinical trait data. Instead, we record the dataset's unavailability without performing final validation. # We still have a gene_data DataFrame from the previous steps. Let's normalize and save it. # Although the clinical data is not usable (no trait), we can still provide the normalized gene data CSV # for reference purposes. # 1. Normalize gene symbols in the obtained gene expression data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file, index=True) print(f"Saved normalized gene data to {out_gene_data_file}") # 2. Since trait data is unavailable, we skip linking and downstream processing. # 3. Record that the trait is missing via validate_and_save_cohort_info with is_final=False. # This avoids the requirement to provide 'df' and 'is_biased' parameters. validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=True, # We do have gene expression data is_trait_available=False, # No trait data note="Trait data not available; further steps were skipped." ) print("Trait data was missing, so final linking and downstream steps were skipped.")