# Path Configuration from tools.preprocess import * # Processing context trait = "Cystic_Fibrosis" cohort = "GSE60690" # Input paths in_trait_dir = "../DATA/GEO/Cystic_Fibrosis" in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE60690" # Output paths out_data_file = "./output/preprocess/1/Cystic_Fibrosis/GSE60690.csv" out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE60690.csv" out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE60690.csv" json_path = "./output/preprocess/1/Cystic_Fibrosis/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. Gene Expression Data Availability # From the background info ("global gene expression was measured in RNA from LCLs"), # it is clear that the dataset contains gene expression data. is_gene_available = True # 2. Variable Availability and Data Type Conversion # 2.1 Data Availability # - The "trait" here is "Cystic_Fibrosis", but the background indicates # this dataset is entirely CF patients (no variation). Hence treat as not available. trait_row = None # - Age is found in row 2 ("age of enrollment: ..."). age_row = 2 # - Gender is found in row 0 ("Sex: Male", "Sex: Female"). gender_row = 0 # 2.2 Data Type Conversion import re def convert_trait(value: str) -> int: """ Although trait_row is None (trait not available), define a function for completeness. Returns None if called, as there's no variation here. """ return None def convert_age(value: str) -> float: """ Convert 'age of enrollment: 38.2' -> 38.2 (float). If 'NA', return None. """ # Extract the portion after the colon parts = value.split(':') if len(parts) < 2: return None age_str = parts[1].strip() if age_str.upper() == 'NA': return None try: return float(age_str) except ValueError: return None def convert_gender(value: str) -> int: """ Convert 'Sex: Male' -> 1 'Sex: Female' -> 0 Otherwise return None. """ parts = value.split(':') if len(parts) < 2: return None gender_str = parts[1].strip().lower() if gender_str == 'male': return 1 elif gender_str == 'female': return 0 return None # 3. Save Metadata # trait data availability depends on trait_row. is_trait_available = trait_row is not None usable_status = 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 # Skip this step because trait_row is None (no trait variation). # Thus, we do not call geo_select_clinical_features. # 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]) 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)) # STEP6: Gene Identifier Mapping # 1. Identify the columns in 'gene_annotation' that match the probe IDs in 'gene_data' # and the column that stores gene symbols. Based on inspection, "ID" aligns with # the probe identifiers in the expression data, and "gene_assignment" stores gene symbols. probe_col = "ID" gene_symbol_col = "gene_assignment" # 2. Extract a mapping dataframe containing these two columns mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col) # 3. Apply the mapping to convert the probe-level expression data to gene-level data gene_data = apply_gene_mapping(gene_data, mapping_df) # STEP 7 # 1) Normalize the gene symbols in the obtained gene expression data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # The dataset lacks trait variation (only CF patients), so no clinical data can be used for association. # We skip linking to clinical data and skip further steps requiring trait info. # 2) Final validation and saving metadata # The library requires non-None boolean for 'is_biased' when is_final=True. # Since there's no trait variation, we consider it "biased" for association. is_biased = True _ = 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_biased, df=pd.DataFrame(), # Passing an empty DataFrame as the dataset for final validation note="All samples are CF patients; no variation in the trait." ) # 3) Because the trait is unavailable for association, the dataset is not usable. # We therefore do not create or save any linked data CSV file.