# Path Configuration from tools.preprocess import * # Processing context trait = "Colon_and_Rectal_Cancer" cohort = "GSE56699" # Input paths in_trait_dir = "../DATA/GEO/Colon_and_Rectal_Cancer" in_cohort_dir = "../DATA/GEO/Colon_and_Rectal_Cancer/GSE56699" # Output paths out_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/GSE56699.csv" out_gene_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/gene_data/GSE56699.csv" out_clinical_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/clinical_data/GSE56699.csv" json_path = "./output/preprocess/1/Colon_and_Rectal_Cancer/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 # Based on the series description, this is a microarray dataset. # Step 2: Identify row indices for trait/age/gender and define conversion functions # 2.1. Data Availability trait_row = None # All samples are rectal cancer; no variation across samples => not useful for association study age_row = None # No row found that clearly represents age gender_row = None # No row found that clearly represents gender # 2.2. Define data type conversion functions def convert_trait(value: str) -> Optional[int]: # This dataset does not provide a separate trait column, # but we still define a placeholder function. # If needed, parse the string after the colon: # For instance, if the dataset had a line like "Trait: case", we might do: # real_value = value.split(':')[-1].strip().lower() # return 1 if real_value == "case" else 0 if real_value == "control" else None return None def convert_age(value: str) -> Optional[float]: # Placeholder function, since age is not available. # If we had real data, we would parse after the colon, convert to float, handle unknown as None. return None def convert_gender(value: str) -> Optional[int]: # Placeholder function, since gender is not available. # Typically, we parse after the colon, convert female->0, male->1, else None return None # Step 3: Initial filtering and record saving 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: Extract and preview clinical features if trait data is available if trait_row is not None: selected_clinical_df = geo_select_clinical_features( clinical_data, # assuming 'clinical_data' is our DataFrame from the previous step trait=trait, trait_row=trait_row, convert_trait=convert_trait, age_row=age_row, convert_age=convert_age, gender_row=gender_row, convert_gender=convert_gender ) preview_result = preview_df(selected_clinical_df, n=5) print("Preview of selected clinical features:", preview_result) selected_clinical_df.to_csv(out_clinical_data_file, index=False) # 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. Decide which columns store the probe IDs and gene symbols, and create the mapping DataFrame gene_mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol") # 2. Convert probe-level measurements to gene-level data gene_data = apply_gene_mapping(gene_data, gene_mapping_df) # STEP 7 # Trait data is unavailable, so we cannot do a final validation or linking based on an absent trait. # However, we can still normalize and save the gene expression data, then record partial metadata indicating that # the dataset is not usable because it lacks trait information. # 1. Normalize the gene expression data normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # 2. Because trait data is unavailable, we skip linking, missing-value handling, and bias assessment. # 3. Perform partial (initial) validation to record that trait data is unavailable. validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=True, # We have gene data is_trait_available=False # Trait data is unavailable ) # 4. Since the dataset is missing trait data, it is not suitable for final analysis; do not save linked data.