# Path Configuration from tools.preprocess import * # Processing context trait = "Cardiovascular_Disease" cohort = "GSE262419" # Input paths in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE262419" # Output paths out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE262419.csv" out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE262419.csv" out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE262419.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 # Based on background info, this contains transcriptomic data (RNA-seq) from iPSC cardiomyocytes is_gene_available = True # 2. Variable Availability and Data Type Conversion # Looking at sample characteristics: # - Trait: Not directly encoded but can be inferred from cardiovascular effects # - Age: Not available (these are iPSC-derived cells) # - Gender: Not available (these are iPSC-derived cells) # 2.1 Row identification trait_row = 1 # Treatment row can be used to determine cardiovascular effect age_row = None # Age not available gender_row = None # Gender not available # 2.2 Conversion functions def convert_trait(value: str) -> int: """Convert treatment info to binary cardiovascular disease trait. 0: No cardiovascular effect 1: Shows cardiovascular effect (altered beat frequency, QT prolongation, or asystole) """ if pd.isna(value): return None # Extract value after colon if ":" in value: value = value.split(":")[1].strip() # Based on background info: # - Known cardiotoxic drugs are most active # - 53% chemicals were active in functional phenotypes # - Key effects: altered beat frequency, QT prolongation, asystole cardiotoxic_indicators = [ "prednisone", # Known to affect heart function "estradiol", # Can affect cardiac function "isoniazid", # Known cardiotoxicity "flutamide", # Associated with cardiovascular effects "_10_" # Higher concentrations (10 uM) more likely to show effects ] value = value.lower() return 1 if any(indicator.lower() in value for indicator in cardiotoxic_indicators) else 0 def convert_age(value: str) -> float: return None # Not used def convert_gender(value: str) -> int: return None # Not used # 3. Save Metadata # is_trait_available is True since 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=True) # 4. Clinical Feature Extraction # Extract and save clinical features clinical_df = geo_select_clinical_features(clinical_data, trait=trait, trait_row=trait_row, convert_trait=convert_trait) # Preview the extracted data preview_result = preview_df(clinical_df) print("Preview of clinical data:") print(preview_result) # Save clinical data clinical_df.to_csv(out_clinical_data_file) # First inspect the file structure with gzip.open(matrix_file, 'rt') as file: for i, line in enumerate(file): if i < 50: # Print first 50 lines print(f"Line {i}: {line.strip()}") else: break # After understanding file structure, extract gene expression data genetic_df = pd.read_csv(matrix_file, compression='gzip', sep='\t', skiprows=80, index_col=0) # Print first 20 row IDs print("\nFirst 20 gene/probe IDs:") print(list(genetic_df.index)[:20]) # Print shape for verification print(f"\nShape of genetic data: {genetic_df.shape}")