# Path Configuration from tools.preprocess import * # Processing context trait = "Cardiovascular_Disease" cohort = "GSE228783" # Input paths in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE228783" # Output paths out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE228783.csv" out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE228783.csv" out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE228783.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 # Dataset likely contains gene expression data based on experimental design is_gene_available = True # 2. Variable Availability and Data Type Conversion # 2.1 Data Availability # For trait (Cardiovascular Disease): Not directly measured in this liver disease study trait_row = None # For age: Not available in characteristics age_row = None # For gender: Not available in characteristics gender_row = None # 2.2 Data Type Conversion Functions def convert_trait(x): return None # No trait data def convert_age(x): return None # No age data def convert_gender(x): return None # No gender data # 3. Save Metadata - Initial Filtering 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_df = get_genetic_data(matrix_file) # Preview the DataFrame structure print("DataFrame shape:", genetic_df.shape) print("\nFirst few rows and columns:") print(genetic_df.head().iloc[:, :5]) # Print first few lines from the matrix file to inspect format print("\nRaw file preview:") with gzip.open(matrix_file, 'rt') as f: for i, line in enumerate(f): if i > 30 and i < 35: # Print a few lines around where data starts print(line.strip()) # Looking at the gene identifiers in the first few rows (e.g., 11715100_at, 11715101_s_at), # these appear to be Affymetrix probe IDs, not gene symbols. # They need to be mapped to official human gene symbols for analysis. 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)) # Get probe-to-gene mapping dataframe mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol') # Convert probe-level measurements to gene expression data gene_data = apply_gene_mapping(genetic_df, mapping_df) # Preview output print("Gene expression data shape after mapping:", gene_data.shape) print("\nFirst few rows of gene expression data:") print(gene_data.head().iloc[:, :5]) # 1. Normalize gene symbols and save gene data genetic_df = normalize_gene_symbols_in_index(gene_data) os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) genetic_df.to_csv(out_gene_data_file) # 2. Since clinical data is not available, create a placeholder dataframe for validation placeholder_df = pd.DataFrame(index=genetic_df.columns, columns=['trait']) # 3. Final validation and save cohort info note = "Dataset contains gene expression data from liver tissue samples but lacks required trait information for cardiovascular disease 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, # Set to True since lacking trait data df=placeholder_df, note=note )