# Path Configuration from tools.preprocess import * # Processing context trait = "Sickle_Cell_Anemia" cohort = "GSE84634" # Input paths in_trait_dir = "../DATA/GEO/Sickle_Cell_Anemia" in_cohort_dir = "../DATA/GEO/Sickle_Cell_Anemia/GSE84634" # Output paths out_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/GSE84634.csv" out_gene_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/gene_data/GSE84634.csv" out_clinical_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/clinical_data/GSE84634.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. Decide if this dataset contains gene expression data is_gene_available = True # Based on the background info stating "Gene expression ... were analyzed" # 2. Determine variable availability and build conversion functions # From the sample characteristics {0: [...], 1: [...], 2: ['disease: sickle cell disease']}, # we see only one unique "disease" value. Per instructions, constant features are not available. trait_row = None age_row = None gender_row = None # Define data type conversion functions even if no corresponding row is found (for consistency). def convert_trait(value: str): parts = value.split(':', 1) if len(parts) < 2: return None v = parts[1].strip().lower() if "sickle cell" in v: return 1 return 0 def convert_age(value: str): parts = value.split(':', 1) if len(parts) < 2: return None try: return float(parts[1].strip()) except ValueError: return None def convert_gender(value: str): parts = value.split(':', 1) if len(parts) < 2: return None v = parts[1].strip().lower() if v in ["male", "m"]: return 1 elif v in ["female", "f"]: return 0 return None # Since trait is constant in this dataset, treat it as unavailable is_trait_available = False # 3. Conduct the initial filtering and save metadata 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 skip clinical feature extraction. # (No further action taken here.) # 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 numeric probe-like identifiers, these are not standard gene symbols. # Therefore, they likely need to be mapped to known 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 6: Gene Identifier Mapping # 1. Identify the columns in the annotation corresponding to the probe identifiers (ID), # using "mrna_assignment" for the gene symbols as decided. mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="mrna_assignment") # 2. Convert probe-level measurements to gene-level measurements using the mapping dataframe. gene_data = apply_gene_mapping(gene_data, mapping_df) # (Optional debugging output) print("Gene expression data mapped to symbols. Data shape:", gene_data.shape) print("First 10 gene symbols:", gene_data.index[:10].tolist()) # 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) # 2. Since no trait data is available (trait_row=None), we cannot link it to clinical data nor perform a proper final analysis. # We'll finalize the metadata indicating that the dataset is not usable for trait-based analysis. empty_df = pd.DataFrame() # Empty placeholder since we must pass a non-None df for final validation is_trait_available = False is_biased = True # Arbitrarily set True to signal that it's not suitable for final use # 3. Perform final validation with an empty df; this will mark the dataset as not usable. is_usable = validate_and_save_cohort_info( is_final=True, cohort=cohort, info_path=json_path, is_gene_available=True, is_trait_available=is_trait_available, is_biased=is_biased, df=empty_df, note="No trait data provided in this cohort" ) # 4. We do not save any final linked data because it is not usable. if is_usable: pass