# Path Configuration from tools.preprocess import * # Processing context trait = "Bladder_Cancer" cohort = "GSE245953" # Input paths in_trait_dir = "../DATA/GEO/Bladder_Cancer" in_cohort_dir = "../DATA/GEO/Bladder_Cancer/GSE245953" # Output paths out_data_file = "./output/preprocess/1/Bladder_Cancer/GSE245953.csv" out_gene_data_file = "./output/preprocess/1/Bladder_Cancer/gene_data/GSE245953.csv" out_clinical_data_file = "./output/preprocess/1/Bladder_Cancer/clinical_data/GSE245953.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. Decide whether gene expression data is available # Based on the background "Gene expression data from muscle-invasive bladder cancer" with a microarray platform, # we judge that it does provide gene expression data. is_gene_available = True # 2. Check sample characteristics for trait, age, and gender. # The dictionary provided is: # {0: ['condition: Muscle-invasive bladder cancer']} # There is only one unique value for the condition (i.e., it's constant across samples), # so, by instruction, we consider the trait not available. trait_row = None age_row = None gender_row = None # Prepare the conversion functions (though they will not be used since no data is available). def convert_trait(value: str): # Typically we handle 'value after colon' and convert to a binary or continuous type. # But no trait data is actually used here, so we'll just return None. return None def convert_age(value: str): # Similarly, no age data is present. Return None. return None def convert_gender(value: str): # Similarly, no gender data is present. Return None. return None # 3. Conduct initial filtering with validate_and_save_cohort_info is_trait_available = (trait_row is not None) # This is False 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 do NOT extract and save clinical features. # (We skip calling geo_select_clinical_features because the instructions say to skip when 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]) # Based on the observed probe identifiers (AFFX-BkGr-GC##_st), these are Affymetrix control probes, # not standard human gene symbols. They must 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. Decide which columns in the gene_annotation match the probe IDs from the gene_data # and which column contains the raw text from which gene symbols can be extracted. # From the preview, "ID" appears to match the probe-level identifiers, and "SPOT_ID.1" contains text with gene symbols. # 2. Get a gene mapping dataframe mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="SPOT_ID.1") # 3. Apply the gene mapping to convert probe-level data into gene-level data gene_data = apply_gene_mapping(gene_data, mapping_df) # STEP 7 # Since step 2 concluded that trait_row = None, there is no available (non-constant) trait data for this dataset. # Therefore, we cannot link clinical data or proceed with trait-based analyses. We only normalize and save gene data, # then mark the dataset as not usable for trait-based analysis (is_biased=True). # 1) Normalize gene symbols in the gene expression data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # 2) Because trait data is unavailable (trait_row=None), we skip linking to clinical data and all steps # dependent on the trait. We cannot do trait-based missing value handling or bias checks. # 3) Perform final quality validation and save relevant info. # We set is_trait_available=False to indicate no usable clinical trait data. # We must provide a boolean value for is_biased when is_final=True, so we'll set it to True # to indicate this dataset is too biased/unusable for trait-based studies. is_usable = validate_and_save_cohort_info( is_final=True, cohort=cohort, info_path=json_path, is_gene_available=True, is_trait_available=False, is_biased=True, df=normalized_gene_data, note="No non-constant trait data found. Dataset is not usable for trait-based analysis." ) # 4) If the dataset were usable, we would save the final linked data. Here, it's unusable, so we skip. if is_usable: # No final_data to save since trait data is unavailable. pass