# Path Configuration from tools.preprocess import * # Processing context trait = "Bladder_Cancer" cohort = "GSE185264" # Input paths in_trait_dir = "../DATA/GEO/Bladder_Cancer" in_cohort_dir = "../DATA/GEO/Bladder_Cancer/GSE185264" # Output paths out_data_file = "./output/preprocess/1/Bladder_Cancer/GSE185264.csv" out_gene_data_file = "./output/preprocess/1/Bladder_Cancer/gene_data/GSE185264.csv" out_clinical_data_file = "./output/preprocess/1/Bladder_Cancer/clinical_data/GSE185264.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 # This dataset appears to be RNA expression data. # 2. Variable Availability # Check the sample characteristics dictionary for trait, age, and gender. # The dictionary key for the trait "Bladder_Cancer" has only one unique value ("Bladder Cancer"), # meaning there is no variability in the trait values. So trait_row is None. trait_row = None # There is no apparent age information in the sample characteristics, so age_row is None. age_row = None # Gender data is available at key 7: ["Sex: F", "Sex: M"] gender_row = 7 # 2.2 Data Type Conversion def convert_trait(x: str): """ Convert the trait variable, but we have no variability in this dataset. We'll parse for demonstration, but it returns None because trait is not available. """ return None def convert_age(x: str): """ Convert age to continuous values if it existed. In this dataset, age is not available, so return None. """ return None def convert_gender(x: str): """ Convert gender to binary (female -> 0, male -> 1). Unknown values -> None """ parts = x.split(":") if len(parts) < 2: return None val = parts[1].strip().upper() if val == 'F': return 0 elif val == 'M': return 1 else: return None # 3. Save Metadata (Initial filtering) # Trait data availability is determined by whether trait_row 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 # 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]) # Observing the provided gene identifiers: # - "53BP1" is an alias (official symbol is "TP53BP1"), and "AKT" is not fully resolved. # Thus, they are not all in official HGNC symbol form. We recommend mapping to ensure correctness. 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 which columns store the same kind of identifiers as in our gene_data # and which store gene symbols. In this dataset, "ID" matches the row index # in gene_data (e.g., "53BP1", "ABCD3"), but there is no additional column # for gene symbols. We'll create a new column "Sym" (duplicate of "ID") so # that get_gene_mapping can operate without renaming the same column. gene_annotation['Sym'] = gene_annotation['ID'] # 2. Obtain the gene mapping dataframe by extracting our primary ID column ("ID") # and our new "Sym" column. Then convert from probe-level to gene-level data. gene_mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Sym") gene_data = apply_gene_mapping(gene_data, gene_mapping_df) # For quick verification, let's print the shape and some index entries of the resulting gene_data: print("Mapped gene_data shape:", gene_data.shape) print("First 20 gene identifiers after mapping:") print(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)