# Path Configuration from tools.preprocess import * # Processing context trait = "Endometrioid_Cancer" cohort = "GSE73614" # Input paths in_trait_dir = "../DATA/GEO/Endometrioid_Cancer" in_cohort_dir = "../DATA/GEO/Endometrioid_Cancer/GSE73614" # Output paths out_data_file = "./output/z2/preprocess/Endometrioid_Cancer/GSE73614.csv" out_gene_data_file = "./output/z2/preprocess/Endometrioid_Cancer/gene_data/GSE73614.csv" out_clinical_data_file = "./output/z2/preprocess/Endometrioid_Cancer/clinical_data/GSE73614.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 # 2. Variable Availability and Data Type Conversion # 2.1 Data Availability trait_row = None # No trait information available in sample characteristics age_row = None # No age information available in sample characteristics gender_row = None # No gender information available in sample characteristics # 2.2 Data Type Conversion def convert_trait(value): """Convert trait values to binary (0 for non-endometrioid, 1 for endometrioid)""" if value is None: return None value_str = str(value).lower() if 'endometrioid' in value_str: return 1 else: return 0 def convert_age(value): """Convert age to continuous values""" if value is None: return None try: if ':' in str(value): age_str = str(value).split(':')[1].strip() else: age_str = str(value).strip() return float(age_str) except (ValueError, IndexError): return None def convert_gender(value): """Convert gender to binary (0 for female, 1 for male)""" if value is None: return None value_str = str(value).lower() if ':' in value_str: value_str = value_str.split(':')[1].strip() if 'female' in value_str or 'f' == value_str: return 0 elif 'male' in value_str or 'm' == value_str: return 1 else: return None # 3. Save Metadata is_trait_available = trait_row is not None save_cohort_info = 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 (clinical data not 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 # Examine the gene identifiers from the previous step gene_identifiers_sample = ['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056', 'A_23_P100074', 'A_23_P100092', 'A_23_P100103', 'A_23_P100111', 'A_23_P100127', 'A_23_P100133', 'A_23_P100141', 'A_23_P100156', 'A_23_P100177', 'A_23_P100189', 'A_23_P100196', 'A_23_P100203', 'A_23_P100220', 'A_23_P100240', 'A_23_P10025', 'A_23_P100263'] print("Sample gene identifiers:") for i, identifier in enumerate(gene_identifiers_sample[:5]): print(f" {identifier}") # Analysis: These identifiers follow the pattern "A_23_P" + numbers # This is the standard format for Agilent microarray probe IDs # The "A_23_P" prefix indicates Agilent platform probe identifiers # These are not human gene symbols (which would be like BRCA1, TP53, etc.) # Therefore, they need to be mapped to gene symbols for meaningful analysis print("\nAnalysis: These are Agilent microarray probe IDs (A_23_P prefix)") print("They are not human gene symbols and require mapping to gene symbols.") 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 # Gene identifiers in expression data match 'ID' column in annotation # Gene symbols are in 'GENE_SYMBOL' column prob_col = 'ID' gene_col = 'GENE_SYMBOL' # 2. Get gene mapping dataframe gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col) # 3. Apply gene mapping to convert probe-level to gene expression data gene_data = apply_gene_mapping(gene_data, gene_mapping) print(f"Gene expression data shape after mapping: {gene_data.shape}") print(f"First 5 gene symbols: {list(gene_data.index[:5])}") # Step 7: Data Normalization and Linking import os # 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) os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) normalized_gene_data.to_csv(out_gene_data_file) # 2. Since no clinical data is available (trait_row was None), create empty clinical dataframe empty_clinical_data = pd.DataFrame() linked_data = geo_link_clinical_genetic_data(empty_clinical_data, normalized_gene_data) # 5. Conduct quality check and save the cohort information os.makedirs(os.path.dirname(json_path), exist_ok=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=False, # Placeholder value since no trait data available df=linked_data, note="INFO: Dataset contains gene expression data but no trait information available for analysis" ) # 6. Since no trait data is available, the dataset is not usable - do not save linked data print("Dataset not saved - no trait information available for associational study")