# Path Configuration from tools.preprocess import * # Processing context trait = "Sickle_Cell_Anemia" cohort = "GSE46471" # Input paths in_trait_dir = "../DATA/GEO/Sickle_Cell_Anemia" in_cohort_dir = "../DATA/GEO/Sickle_Cell_Anemia/GSE46471" # Output paths out_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/GSE46471.csv" out_gene_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/gene_data/GSE46471.csv" out_clinical_data_file = "./output/preprocess/1/Sickle_Cell_Anemia/clinical_data/GSE46471.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) import pandas as pd import os import json # 1. Determine if gene expression data is available is_gene_available = True # This appears to be a microarray-based gene expression dataset # 2. Determine data availability # Based on the sample characteristics, no keys provide trait/age/gender info. trait_row = None age_row = None gender_row = None # 2.2 Define dummy conversion functions def convert_trait(x: str): # No trait data is actually available; return None return None def convert_age(x: str): # No age data is actually available; return None return None def convert_gender(x: str): # No gender data is actually available; return None 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 is skipped because trait_row is None # 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 format of the identifiers (e.g., '1', '2', '3', etc.), # these are not standard human gene symbols and thus require mapping. 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 in the gene annotation correspond to the expression data ID and the gene symbols. # From our observations: "ID" in the annotation matches the probe IDs in gene_data, # and "GENE_SYMBOL" stores the gene symbols (even though initial rows are NAs, real mapping info might appear further down). # 2. Generate the gene mapping dataframe from the annotation. mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL') # 3. Convert probe-level measurements into gene-level expression data. gene_data = apply_gene_mapping(gene_data, mapping_df) # (Optional) Quickly show the shape of the resulting gene_data for reference. print("Mapped gene expression data shape:", gene_data.shape) # STEP7 # 1. Normalize the obtained gene data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # Since the previous steps indicated 'trait_row = None', there is no clinical data # for linking or analysis. We therefore skip linking, missing-value handling, and bias checks. # Instead, finalize the dataset availability information to mark the dataset as not usable. import pandas as pd # Create a dummy DataFrame for final validation dummy_df = pd.DataFrame() # 5. Final quality validation # Mark is_trait_available=False. For is_biased, we can set True to fully exclude it from usage. # The library function requires both 'df' and 'is_biased' when is_final=True. 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=True, # Marks dataset as not usable df=dummy_df, note="No trait data was found, so the dataset is not usable." ) # 6. If the dataset is usable, save it (but here is_usable will be False, so no saving) if is_usable: # If trait were available and everything passed, we'd link & save the final CSV here. pass