# Path Configuration from tools.preprocess import * # Processing context trait = "Bladder_Cancer" cohort = "GSE201395" # Input paths in_trait_dir = "../DATA/GEO/Bladder_Cancer" in_cohort_dir = "../DATA/GEO/Bladder_Cancer/GSE201395" # Output paths out_data_file = "./output/preprocess/1/Bladder_Cancer/GSE201395.csv" out_gene_data_file = "./output/preprocess/1/Bladder_Cancer/gene_data/GSE201395.csv" out_clinical_data_file = "./output/preprocess/1/Bladder_Cancer/clinical_data/GSE201395.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 # Based on the background information ("Expression array data..."), this dataset contains gene expression data. is_gene_available = True # 2. Variable Availability and Data Type Conversion # The sample characteristics dictionary suggests that these are urothelial carcinoma cell lines # with no human subject-level information such as age or gender. # Additionally, the trait ("Bladder_Cancer") is constant for all samples (they are all bladder cancer cell lines). # Hence, no meaningful variation is present for trait, age, or gender. trait_row = None age_row = None gender_row = None # Since no data is available for trait, age, or gender, we do not need conversion functions. # We'll define empty placeholders for completeness (they won't be used). def convert_trait(x: str): return None def convert_age(x: str): return None def convert_gender(x: str): return None # 3. Save Metadata (Initial Filtering) # Trait data is considered absent if 'trait_row' is None. is_trait_available = (trait_row is not None) # Perform the initial filtering step and store the result in 'is_usable' 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 # This step is only performed if 'trait_row' is not None (i.e., trait data is available). # Since 'trait_row' is None, we skip this step. # 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]) print("\nrequires_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)) # STEP6: Gene Identifier Mapping # 1. Decide columns for mapping # Based on the preview, the 'ID' column of the annotation DataFrame corresponds to the probe identifiers, # and the 'gene_assignment' column appears to contain text related to gene symbols. mapping_df = get_gene_mapping( annotation=gene_annotation, prob_col="ID", gene_col="gene_assignment" ) # 2. Convert probe-level measurements to gene-level by applying the gene mapping gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df) # (Optional) Print shape or a small preview for verification print("Gene data shape after mapping:", gene_data.shape) print("First 20 gene symbols in the mapped data:", gene_data.index[:20]) # 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)