# Path Configuration from tools.preprocess import * # Processing context trait = "Endometrioid_Cancer" cohort = "GSE94524" # Input paths in_trait_dir = "../DATA/GEO/Endometrioid_Cancer" in_cohort_dir = "../DATA/GEO/Endometrioid_Cancer/GSE94524" # Output paths out_data_file = "./output/z2/preprocess/Endometrioid_Cancer/GSE94524.csv" out_gene_data_file = "./output/z2/preprocess/Endometrioid_Cancer/gene_data/GSE94524.csv" out_clinical_data_file = "./output/z2/preprocess/Endometrioid_Cancer/clinical_data/GSE94524.csv" json_path = "./output/z2/preprocess/Endometrioid_Cancer/cohort_info.json" # Step 1: Initial Data Loading 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 2: Dataset Analysis and Clinical Feature Extraction # 1. Gene Expression Data Availability is_gene_available = True # The study focuses on differential enhancer activity, suggesting gene expression data # 2. Variable Availability and Data Type Conversion # 2.1 Data Availability # trait: Only one unique value 'tissue: endometrioid adenocarcinoma' - constant feature, not useful trait_row = None age_row = None # No age information available gender_row = None # No gender information available # 2.2 Data Type Conversion def convert_trait(value): """Convert trait values to binary""" if value is None: return None return None # Not used since trait_row is None def convert_age(value): """Convert age values to continuous""" if value is None: return None return None # Not used since age_row is None def convert_gender(value): """Convert gender values to binary (0=female, 1=male)""" if value is None: return None return None # Not used since gender_row is None # 3. 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. Clinical Feature Extraction # Skip this step since trait_row is None (no clinical data available) # Step 3: Gene Data Extraction # 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]) # Step 4: Gene Identifier Review print("Examining gene identifiers...") print("Sample identifiers:", gene_data.index[:10].tolist()) # These are numeric identifiers (1, 2, 3, etc.), not human gene symbols # Human gene symbols are typically alphanumeric strings like BRCA1, TP53, GAPDH, etc. # These numeric IDs likely represent probe IDs or other database identifiers that need mapping requires_gene_mapping = True # Step 5: Gene Annotation # 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 mapping columns # 'ID' column matches the gene expression data identifiers (numeric IDs) # 'HUGO' column contains gene symbols, though it has some NaN values prob_col = 'ID' gene_col = 'HUGO' # 2. Get gene mapping dataframe gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col) # 3. Apply gene mapping to convert probe-level data to gene expression data gene_data = apply_gene_mapping(gene_data, gene_mapping) # Normalize gene symbols to ensure consistency gene_data = normalize_gene_symbols_in_index(gene_data) print(f"Gene expression data shape after mapping: {gene_data.shape}") print(f"Sample gene names: {gene_data.index[:10].tolist()}") # Step 7: Data Normalization and Linking # 1. Normalize the obtained gene data and save it normalized_gene_data = normalize_gene_symbols_in_index(gene_data) os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) normalized_gene_data.to_csv(out_gene_data_file) # Since no clinical data with variable traits is available (trait_row was None in Step 2), # this dataset is not suitable for association studies print("No variable clinical trait data available - dataset not suitable for association studies") # Create empty dataframe to represent unavailable linked data linked_data = pd.DataFrame() # 5. Conduct final quality validation 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, # Dataset is biased/unusable due to constant trait values df=linked_data, note="INFO: Dataset contains only constant trait values (all endometrioid adenocarcinoma), no variable clinical features for association analysis" ) # 6. Since the dataset is not usable for association studies, do not save linked data file print(f"Dataset usability: {is_usable}")