# Path Configuration from tools.preprocess import * # Processing context trait = "Sickle_Cell_Anemia" cohort = "GSE84633" # Input paths in_trait_dir = "../DATA/GEO/Sickle_Cell_Anemia" in_cohort_dir = "../DATA/GEO/Sickle_Cell_Anemia/GSE84633" # Output paths out_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/GSE84633.csv" out_gene_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/gene_data/GSE84633.csv" out_clinical_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/clinical_data/GSE84633.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 Series title "Gene expression of peripheral blood..." # 2. Identify available variables in the sample characteristics dictionary # The dictionary is: # 0: ['tissue: peripheral blood'] # 1: ['cell type: mononuclear cells'] # 2: ['disease: sickle cell disease'] # We see "sickle cell disease" is constant across samples (single unique value), hence not useful for association. trait_row = None age_row = None gender_row = None # 2.2 Write data type conversion functions. # Since no data is available, these functions will simply return None. def convert_trait(x: str): return None def convert_age(x: str): return None def convert_gender(x: str): return None # 3. Conduct initial filtering and save metadata is_trait_available = (trait_row is not None) 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 skip the clinical feature extraction 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]) # Based on the observed identifiers, they do not appear to be standard human gene symbols. # They are likely array probe IDs that require mapping to human 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. The "ID" column in the annotation dataframe matches the probe IDs in the gene expression dataframe. # The "gene_assignment" column contains gene symbol information. # 2. Get a gene mapping dataframe by extracting these two columns from gene_annotation. mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment') # 3. Convert probe-level measurements to gene expression data using the mapping. gene_data = apply_gene_mapping(gene_data, mapping_df) # (Optional) You can inspect the resulting gene_data shape or head for verification: print("Mapped gene_data shape:", gene_data.shape) print("Head of the mapped gene_data:") print(gene_data.head()) # STEP7 # Since we previously determined that 'trait_row' is None, we do NOT have trait data available. # We therefore skip the steps that require clinical data (linking, missing-value handling, bias checking). # However, we can still normalize gene symbols and save the resulting gene expression data. # 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) # 2. Because trait data is not available, skip linking clinical to genetic data and any related processing. # 3. Perform the initial filtering and record that the dataset is missing trait data (is_final=False). validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=True, is_trait_available=False, # No trait data note="This dataset lacks trait information, so it is not usable for association analysis." ) # 4. Since there is no trait data, the dataset cannot be used for association studies. # Hence, we do not proceed with final validation or produce a final linked data file.