# Path Configuration from tools.preprocess import * # Processing context trait = "Cardiovascular_Disease" cohort = "GSE276839" # Input paths in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE276839" # Output paths out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE276839.csv" out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE276839.csv" out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE276839.csv" json_path = "./output/preprocess/3/Cardiovascular_Disease/cohort_info.json" # Get paths to the SOFT and matrix files soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) # Get background info and clinical data from matrix file background_info, clinical_data = get_background_and_clinical_data(matrix_file) # Get unique values for each feature (row) in clinical data unique_values_dict = get_unique_values_by_row(clinical_data) # Print background info print("=== Dataset Background Information ===") print(background_info) print("\n=== Sample Characteristics ===") print(json.dumps(unique_values_dict, indent=2)) # 1. Gene Expression Data Availability # From the series title and summary, this is a transcriptomics study measuring gene expression # in cardiac tissue samples, so gene expression data should be available is_gene_available = True # 2.1 Data Row Identification # Age groups are in row 0, indicating age data availability age_row = 0 # No gender data available in sample characteristics gender_row = None # Trait cannot be determined from sample characteristics since all samples are cardiac tissues # from patients with congenital heart disease trait_row = None # 2.2 Data Type Conversion Functions def convert_age(value: str) -> Optional[float]: """Convert age group to numeric values representing approximate age in years""" if not isinstance(value, str): return None value = value.lower().split(': ')[-1] if 'neonate' in value: return 0.0 elif 'infant' in value: return 0.5 # ~6 months elif 'toddler' in value or 'pre school' in value: return 2.5 # ~2-3 years elif 'school age' in value: return 8.0 # ~6-10 years elif 'adolescent' in value or 'young adult' in value: return 16.0 # ~14-18 years return None # Empty function definitions for trait and gender since data not available def convert_trait(value: str) -> Optional[int]: return None def convert_gender(value: str) -> Optional[int]: 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=(trait_row is not None) ) # 4. Skip clinical feature extraction since trait_row is None # Extract gene expression data from matrix file genetic_df = get_genetic_data(matrix_file) # Print first 20 row IDs print("First 20 gene/probe IDs:") print(list(genetic_df.index)[:20]) # These IDs are from Affymetrix's ClariomD arrays and need to be mapped to standard gene symbols requires_gene_mapping = True # Extract gene annotation data gene_metadata = get_gene_annotation(soft_file) # Preview column names and first few values print("Column names and preview of gene annotation data:") print(preview_df(gene_metadata)) # Extract gene symbols from the full text descriptions gene_metadata['Gene'] = gene_metadata['SPOT_ID.1'].apply(extract_human_gene_symbols) # Get mapping between probe IDs and gene symbols mapping_df = get_gene_mapping(gene_metadata, 'ID', 'Gene') # Apply mapping to convert probe measurements to gene expression values gene_data = apply_gene_mapping(genetic_df, mapping_df) # Normalize gene symbols to standard format gene_data = normalize_gene_symbols_in_index(gene_data) # 1. Save normalized gene data if not os.path.exists(os.path.dirname(out_gene_data_file)): os.makedirs(os.path.dirname(out_gene_data_file)) gene_data.to_csv(out_gene_data_file) # Record that this dataset can't be used due to missing clinical data is_usable = validate_and_save_cohort_info( is_final=False, # Initial filtering since clinical data unavailable cohort=cohort, info_path=json_path, is_gene_available=True, is_trait_available=False # From Step 2, trait_row was None )