# Path Configuration from tools.preprocess import * # Processing context trait = "Sickle_Cell_Anemia" cohort = "GSE84632" # Input paths in_trait_dir = "../DATA/GEO/Sickle_Cell_Anemia" in_cohort_dir = "../DATA/GEO/Sickle_Cell_Anemia/GSE84632" # Output paths out_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/GSE84632.csv" out_gene_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/gene_data/GSE84632.csv" out_clinical_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/clinical_data/GSE84632.csv" json_path = "./output/preprocess/1/Sickle_Cell_Anemia/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) Determine if gene expression data is available is_gene_available = True # Based on the background info "The gene expression of PBMC..." # 2) Determine data availability for trait, age, and gender # From the sample characteristics dictionary, we see only a single constant value for disease (Sickle cell disease) # and no info about age or gender. Therefore, set rows to None and treat them as not available. trait_row = None age_row = None gender_row = None # 2.2) Define data type conversion functions as placeholders def convert_trait(val: str) -> int: # No actual use because trait_row is None, but we still define the function return 1 # Arbitrary or pass def convert_age(val: str) -> float: # No actual use because age_row is None, but we still define the function return None def convert_gender(val: str) -> int: # No actual use because gender_row is None, but we still define the function return None # 3) Initial filtering and save metadata # Trait is not available because trait_row is None is_trait_available = 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, 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]) # Based on the given identifiers (e.g., "16650001"), these appear to be numeric probe IDs rather than standard human gene symbols. # Hence, 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) Decide which keys in the gene annotation dataframe match the probe IDs and the gene symbols. # From the previews, the 'ID' column matches the numeric probe IDs (e.g. '16657436'), # and 'GB_ACC' appears to contain some form of gene-related information (e.g. 'NR_046018'). # We will use 'ID' for probe identifiers and 'GB_ACC' for gene symbols. # 2) Get a gene mapping dataframe by extracting the relevant pair of columns. mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GB_ACC') # 3) Convert probe-level measurements in gene_data to gene expression values by applying the mapping. gene_data = apply_gene_mapping(gene_data, mapping_df) # STEP7 import pandas as pd # 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library. normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # Since we determined in a previous step that trait data is unavailable (trait_row = None), # we have no clinical dataframe (selected_clinical_df) to link with gene data. # Therefore, we skip linking clinical and genetic data and trait-based processing. # For final validation with is_final=True, we must provide a boolean 'is_biased'. # Because no trait data is available to assess bias, we set it to False by default. is_trait_biased = False # 5. Conduct final quality validation and save the cohort information. # Because trait data was deemed unavailable, is_trait_available=False. # The dataset is not usable for trait-based analysis, so the final data will not be saved. 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=is_trait_biased, df=normalized_gene_data, note="No trait data available; only gene expression data was processed." ) # 6. If the dataset were usable, we would save the final linked data. But since is_usable is expected to be False, we skip. if is_usable: # Normally we would save the final linked data, but we have no trait data. pass