# Path Configuration from tools.preprocess import * # Processing context trait = "Colon_and_Rectal_Cancer" cohort = "GSE46862" # Input paths in_trait_dir = "../DATA/GEO/Colon_and_Rectal_Cancer" in_cohort_dir = "../DATA/GEO/Colon_and_Rectal_Cancer/GSE46862" # Output paths out_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/GSE46862.csv" out_gene_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/gene_data/GSE46862.csv" out_clinical_data_file = "./output/preprocess/1/Colon_and_Rectal_Cancer/clinical_data/GSE46862.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) # 1. Gene Expression Data Availability is_gene_available = True # The dataset uses Affymetrix GeneChip arrays, indicating gene expression data. # 2. Variable Availability and Data Type Conversion # Based on the sample characteristics dictionary, the human trait "Colon_and_Rectal_Cancer" is not explicitly # listed. All samples are rectal cancer, so there's no meaningful variation for our trait. trait_row = None # Not available # 'Age' data appears in row 1, with multiple distinct values. age_row = 1 # 'Gender' data appears in row 2, with values "male" and "female". gender_row = 2 # Define conversion functions: def convert_trait(x: str) -> int: # Since trait data is not available (trait_row is None), # this function will never be called, but we define it for completeness. return None def convert_age(x: str) -> float: # Typical format: "age: 68" # Extract the substring after the first colon and convert to float. try: value_str = x.split(':', 1)[1].strip() return float(value_str) except: return None def convert_gender(x: str) -> int: # Typical format: "Sex: male" or "Sex: female" # Extract the substring after the colon and convert to binary (male=1, female=0). try: value_str = x.split(':', 1)[1].strip().lower() if value_str == 'male': return 1 elif value_str == 'female': return 0 else: return None except: return None # 3. Save Metadata # Trait data is not available because trait_row is None. is_trait_available = (trait_row is not None) is_usable = 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 # Since trait_row is None, we skip this step. # 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]) # The numeric IDs appear to be probe identifiers rather than standard human gene symbols. 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 & 2. Identify the columns "ID" and "gene_assignment" as the probe IDs and gene symbol fields, respectively, # then extract them to form the mapping dataframe. mapping_df = get_gene_mapping(gene_annotation, "ID", "gene_assignment") # 3. Convert probe-level data into gene-level data by applying this mapping to our gene_data. gene_data = apply_gene_mapping(gene_data, mapping_df) # STEP7 # Since trait_row was determined to be None, there is no available trait data to link with. # We only proceed with normalizing and saving the gene expression data, then record partial metadata. # 1. Normalize the obtained gene data with synonyms from the NCBI Gene database. normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # 2 - 4. Skip any clinical linking or missing value handling since no trait data is available. # 5. Perform partial validation (not final) 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, is_trait_available=False, note="No trait data available; skipping final validation and combined dataset." ) # 6. Since the dataset is not usable for trait-based analysis, we do not save any linked data.