# Path Configuration from tools.preprocess import * # Processing context trait = "Bladder_Cancer" cohort = "GSE162253" # Input paths in_trait_dir = "../DATA/GEO/Bladder_Cancer" in_cohort_dir = "../DATA/GEO/Bladder_Cancer/GSE162253" # Output paths out_data_file = "./output/preprocess/1/Bladder_Cancer/GSE162253.csv" out_gene_data_file = "./output/preprocess/1/Bladder_Cancer/gene_data/GSE162253.csv" out_clinical_data_file = "./output/preprocess/1/Bladder_Cancer/clinical_data/GSE162253.csv" json_path = "./output/preprocess/1/Bladder_Cancer/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 title and context, this dataset likely contains gene expression data. # 2. Variable Availability and Data Type Conversion # Checking sample characteristics, we see no mention of "Bladder_Cancer", age, or gender data. # Therefore, these are not available. trait_row = None age_row = None gender_row = None # Define conversion functions (though they will not be used here since trait_row, age_row, and gender_row are None). def convert_trait(value: str): return None # No trait data available def convert_age(value: str): return None # No age data available def convert_gender(value: str): return None # No gender data available # 3. Initial filtering and saving metadata # Trait data is considered available if trait_row is not None. Here it is None. 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 # Skip this step because trait_row is None (no clinical data to extract). # 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]) # The provided IDs (e.g., '11715100_at') appear to be Affymetrix probe set identifiers, # not standard human gene symbols. They therefore require mapping to standard gene symbols. print("They appear to be Affymetrix probe set IDs.") 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. From the annotation preview, we see the column "ID" matches the probe identifiers in the gene_data index, # and "Gene Symbol" stores the gene symbols. probe_col = "ID" symbol_col = "Gene Symbol" # 2. Get a gene mapping dataframe using the library function get_gene_mapping. gene_mapping = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=symbol_col) # 3. Convert the probe-level measurements in gene_data to a gene-level expression dataframe. gene_data = apply_gene_mapping(gene_data, gene_mapping) # (Optional) Inspect the shape of the remapped gene_data for a sanity check. print(f"Remapped gene_data shape: {gene_data.shape}") # STEP 5 # 1) Normalize the gene expression data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # Since there is no trait data (trait_row was None), we cannot link clinical features or perform bias checks. # We still must do final validation to record that trait data is unavailable. # Provide a placeholder for is_biased; it won't matter because is_trait_available is False. is_biased_placeholder = False # 5) Perform final validation and save metadata is_usable = validate_and_save_cohort_info( is_final=True, cohort=cohort, info_path=json_path, is_gene_available=True, # We do have gene expression data is_trait_available=False, # Trait data is unavailable is_biased=is_biased_placeholder, df=normalized_gene_data, # We pass the gene data but there's no trait column note="No trait data; cannot complete linking or bias checks." ) # 6) If the dataset is deemed usable, save the final linked data # In this scenario, is_usable will be False because the trait is not available. if is_usable: normalized_gene_data.to_csv(out_data_file)