# Path Configuration from tools.preprocess import * # Processing context trait = "Vitamin_D_Levels" cohort = "GSE35925" # Input paths in_trait_dir = "../DATA/GEO/Vitamin_D_Levels" in_cohort_dir = "../DATA/GEO/Vitamin_D_Levels/GSE35925" # Output paths out_data_file = "./output/preprocess/3/Vitamin_D_Levels/GSE35925.csv" out_gene_data_file = "./output/preprocess/3/Vitamin_D_Levels/gene_data/GSE35925.csv" out_clinical_data_file = "./output/preprocess/3/Vitamin_D_Levels/clinical_data/GSE35925.csv" json_path = "./output/preprocess/3/Vitamin_D_Levels/cohort_info.json" # Get file paths soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir) # Get background info and clinical data background_info, clinical_data = get_background_and_clinical_data(matrix_file_path) # Print shape and first few rows to verify data print("Background Information:") print(background_info) print("\nClinical Data Shape:", clinical_data.shape) print("\nFirst few rows of Clinical Data:") print(clinical_data.head()) print("\nSample Characteristics:") # Get dictionary of unique values per row unique_values_dict = get_unique_values_by_row(clinical_data) for row, values in unique_values_dict.items(): print(f"\n{row}:") print(values) # 1. Gene Expression Data Availability # From background info, this is a gene expression study using U133 Plus 2.0 GeneChip (Affymetrix) is_gene_available = True # 2. Clinical Features # 2.1 Data Availability # All samples are breast cancer patients, so looking at rows 0-3 for clinical data trait_row = None # No vitamin D level data age_row = 1 # Age data in row 1 gender_row = None # Gender data unusable since all samples are female (constant feature) # 2.2 Data Type Conversion Functions def convert_trait(x): # Not used since trait data not available return None def convert_age(x): try: return float(x.split(': ')[1]) except: return None def convert_gender(x): # Not used since gender data marked as unavailable return None # 3. Save metadata validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=is_gene_available, is_trait_available=False # trait_row is None ) # 4. Skip clinical feature extraction since trait_row is None # Extract gene expression data from matrix file genetic_data = get_genetic_data(matrix_file_path) # Print first 20 row IDs print("First 20 gene/probe IDs:") print(list(genetic_data.index[:20])) # The identifiers shown are from Affymetrix Human Genome U133 Plus 2.0 Array probe IDs # These are probe IDs and need to be mapped to gene symbols requires_gene_mapping = True # Extract gene annotation from SOFT file gene_annotation = get_gene_annotation(soft_file_path) # Preview annotation structure preview = preview_df(gene_annotation) print("Gene annotation preview:") print(preview) # Get gene mapping from annotation mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol') # Apply the mapping to convert probe-level measurements to gene expression data gene_data = apply_gene_mapping(genetic_data, mapping_data) # Preview first few rows of gene data print("\nFirst few rows of gene expression data:") print(preview_df(gene_data)) # 1. Normalize gene symbols in gene expression data gene_data = normalize_gene_symbols_in_index(gene_data) os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) gene_data.to_csv(out_gene_data_file) print("\nGene data shape (normalized gene-level):", gene_data.shape) # Since trait data is not available (trait_row was None in Step 2), # set the trait bias to True since dataset lacks required trait data note = "Dataset contains gene expression data but lacks vitamin D level measurements needed for trait analysis." 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 missing trait data df=gene_data, # Provide the gene expression data note=note )