# Path Configuration from tools.preprocess import * # Processing context trait = "Eczema" cohort = "GSE61225" # Input paths in_trait_dir = "../DATA/GEO/Eczema" in_cohort_dir = "../DATA/GEO/Eczema/GSE61225" # Output paths out_data_file = "./output/preprocess/1/Eczema/GSE61225.csv" out_gene_data_file = "./output/preprocess/1/Eczema/gene_data/GSE61225.csv" out_clinical_data_file = "./output/preprocess/1/Eczema/clinical_data/GSE61225.csv" json_path = "./output/preprocess/1/Eczema/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) # Step 1: Determine gene expression data availability is_gene_available = True # According to the background info, it's an expression microarray. # Step 2: Variable availability and data type conversion # 2.1 Data availability trait_row = None # Eczema information is not found in the sample characteristics. age_row = 6 # "age: ..." is found at key 6 with multiple unique values. gender_row = 5 # "gender: female/male" is found at key 5 with multiple unique values. # 2.2 Data type conversion def convert_trait(value: str): # Trait not available, this function won't be used. return None def convert_age(value: str): # Parse the substring after the first colon 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): # Parse the substring after the first colon parts = value.split(':', 1) if len(parts) < 2: return None gender_val = parts[1].strip().lower() if gender_val == 'female': return 0 elif gender_val == 'male': return 1 else: return None # Step 3: Save metadata (initial filtering) 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 ) # Step 4: Since trait_row is None, we skip the 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]) # Gene Identifier Review # Observing the index values (ILMN_xxx) reveals they are Illumina probe identifiers rather than standard gene symbols. # Therefore we conclude: 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 columns store the probe identifiers and gene symbols: # From the annotation preview, 'ID' appears to contain the same probe identifiers (e.g., ILMN_1343295) # as in our gene expression data index, and 'ILMN_Gene' seems to hold the gene symbol. # 2. Get a gene mapping dataframe by extracting 'ID' and 'ILMN_Gene' columns. mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="ILMN_Gene") # 3. Convert probe-level measurements to gene-level expression data. gene_data = apply_gene_mapping(gene_data, mapping_df) import pandas as pd # STEP7 # 1) Normalize gene symbols and save normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # Define a placeholder clinical dataframe (since trait data is not actually available) selected_clinical_df = pd.DataFrame() # 2) Link the (empty) clinical dataframe with the normalized gene expression data linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data) # Ensure the trait column exists, even though it's unavailable if trait not in linked_data.columns: linked_data[trait] = None # 3) Handle missing values using the trait column final_data = handle_missing_values(linked_data, trait_col=trait) # 4) Evaluate bias in the (non-existent) trait trait_biased, final_data = judge_and_remove_biased_features(final_data, trait) # 5) Final validation. The dataset has no trait data, so is_trait_available=False 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=trait_biased, df=final_data, note="No trait data could be extracted for this dataset." ) # 6) If the dataset is deemed usable (unlikely given no trait), save final data if is_usable: final_data.to_csv(out_data_file)