# Path Configuration from tools.preprocess import * # Processing context trait = "Cervical_Cancer" cohort = "GSE163114" # Input paths in_trait_dir = "../DATA/GEO/Cervical_Cancer" in_cohort_dir = "../DATA/GEO/Cervical_Cancer/GSE163114" # Output paths out_data_file = "./output/preprocess/1/Cervical_Cancer/GSE163114.csv" out_gene_data_file = "./output/preprocess/1/Cervical_Cancer/gene_data/GSE163114.csv" out_clinical_data_file = "./output/preprocess/1/Cervical_Cancer/clinical_data/GSE163114.csv" json_path = "./output/preprocess/1/Cervical_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: Gene Expression Data Availability # Based on the background information ("Ki-67 promotes carcinogenesis by enabling global transcriptional programmes") # and the use of the HeLa cell line, it is likely that this dataset contains gene expression data. is_gene_available = True # Step 2: Variable Availability and Data Type Conversion # From the sample characteristics dictionary: # {0: ['cell line: HeLa'], 1: ['lentivirus: shRNA control', 'lentivirus: shRNA Ki-67']} # - All samples come from the HeLa cell line, which is derived from cervical cancer, but this is a constant feature (no variation). # - There's no row providing age or gender information. # Hence, no variable has meaningful variation. We set rows to None. trait_row = None # No row captures a varying cervical cancer trait age_row = None # No row for age gender_row = None # No row for gender # Even though these functions won't be used (since trait_row, age_row, gender_row = None), # we provide them per instructions. def convert_trait(value: str): """ Convert the trait to the chosen type. Not applicable here, but defined for completeness. """ if not value or ':' not in value: return None val = value.split(':', 1)[-1].strip() return val if val else None def convert_age(value: str): """ Convert age data to a continuous type. Not applicable here, but defined for completeness. """ if not value or ':' not in value: return None val = value.split(':', 1)[-1].strip() # We do not actually have numeric values, so just return None. return None def convert_gender(value: str): """ Convert gender data to binary. Not applicable here, but defined for completeness. """ if not value or ':' not in value: return None val = value.split(':', 1)[-1].strip().lower() if val in ['male', 'm']: return 1 elif val in ['female', 'f']: return 0 return None # Step 3: Save Metadata # If trait_row is None, trait data is considered unavailable. 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: Since trait_row is None, we skip geo_select_clinical_features. # No clinical data extraction is performed because the trait is not available. # 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]) # Based on the numeric IDs (1,2,3,...), they do not appear to be standard human gene symbols. # They seem like probe identifiers or some form of numeric reference that would require mapping. print("These numeric IDs likely need mapping to standard gene symbols.") 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)) # STEP: Gene Identifier Mapping # 1. Decide which key in the gene annotation dataframe stores the gene identifiers # matching the gene expression data. From the preview, the 'ID' column in gene_annotation # corresponds to the numeric probe IDs in gene_data. For gene symbols, we use 'GENE_SYMBOL'. # 2. Get a gene mapping dataframe mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL') # 3. Convert probe-level measurements to gene expression data gene_data = apply_gene_mapping(gene_data, mapping_df) # Print a quick check of the mapped dataframe print("Mapped gene_data shape:", gene_data.shape) print("Head of mapped gene_data:") print(gene_data.head()) # STEP 7 # 1. Normalize gene symbols in the gene_data, then save to CSV. normalized_gene_data = normalize_gene_symbols_in_index(gene_data) normalized_gene_data.to_csv(out_gene_data_file) # Since trait_row was None in earlier steps, there is no actual trait data available. # We cannot link clinical data or do trait-based QC. However, the library requires a final # validation with a DataFrame and a Boolean for is_biased. # Create an empty DataFrame as a placeholder, and declare is_biased=False by default. placeholder_df = pd.DataFrame() trait_biased = False # 2. Perform final validation, marking trait as unavailable but providing the required arguments. is_usable = validate_and_save_cohort_info( is_final=True, cohort=cohort, info_path=json_path, is_gene_available=True, # Gene data is present is_trait_available=False, # Trait is not available is_biased=trait_biased, df=placeholder_df, # Provide a placeholder DataFrame note="No trait data in this series. Final validation with placeholder DataFrame." ) # 3. If the dataset were usable (it won't be without trait), we would save final linked data. if is_usable: # Typically we would link data and save CSV, but trait is absent. Skipping. pass