# Path Configuration from tools.preprocess import * # Processing context trait = "Celiac_Disease" cohort = "GSE106260" # Input paths in_trait_dir = "../DATA/GEO/Celiac_Disease" in_cohort_dir = "../DATA/GEO/Celiac_Disease/GSE106260" # Output paths out_data_file = "./output/preprocess/3/Celiac_Disease/GSE106260.csv" out_gene_data_file = "./output/preprocess/3/Celiac_Disease/gene_data/GSE106260.csv" out_clinical_data_file = "./output/preprocess/3/Celiac_Disease/clinical_data/GSE106260.csv" json_path = "./output/preprocess/3/Celiac_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 the SOFT file background_info, clinical_data = get_background_and_clinical_data(soft_file) # Get unique values for each feature type in clinical data unique_values = {} for _, row in clinical_data.iterrows(): for cell in row: if isinstance(cell, str) and ': ' in cell: feature_type = cell.split(': ')[0] feature_value = cell.split(': ')[1] if feature_type not in unique_values: unique_values[feature_type] = set() unique_values[feature_type].add(feature_value) # Convert sets to lists for JSON serialization unique_values = {k: list(v) for k, v in unique_values.items()} # Print background info print("=== Dataset Background Information ===") print(background_info) print("\n=== Sample Characteristics ===") print(json.dumps(unique_values, indent=2)) # 1. Gene Expression Data Availability # Based on series title and summary, this appears to be a study of immune cell samples # involving RNA gene expression analysis, not just miRNA or methylation is_gene_available = True # 2. Variable Availability and Data Type Conversion # Looking at sample characteristics, trait (celiac disease) status isn't explicitly # recorded in sample characteristics. Inferring from the treatment status would not # be reliable. No age or gender info is available either. trait_row = None age_row = None gender_row = None # Define conversion functions even though they won't be used for this dataset def convert_trait(x): """Convert trait value to binary""" if not isinstance(x, str): return None val = x.split(':')[-1].strip().lower() if 'celiac' in val or 'cd' in val: return 1 elif 'control' in val or 'healthy' in val: return 0 return None def convert_age(x): """Convert age value to float""" if not isinstance(x, str): return None val = x.split(':')[-1].strip() try: return float(val) except: return None def convert_gender(x): """Convert gender to binary""" if not isinstance(x, str): return None val = x.split(':')[-1].strip().lower() if 'f' in val or 'female' in val: return 0 elif 'm' in val or 'male' in val: return 1 return None # 3. Save metadata # Initial filtering - trait data not available validate_and_save_cohort_info(is_final=False, cohort=cohort, info_path=json_path, is_gene_available=is_gene_available, is_trait_available=False) # 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 DataFrame shape and first 20 row IDs print("DataFrame shape:", genetic_df.shape) print("\nFirst 20 row IDs:") print(genetic_df.index[:20]) print("\nPreview of first few rows and columns:") print(genetic_df.head().iloc[:, :5]) # Looking at the identifiers, they start with "ILMN_" which indicates these are Illumina probe IDs, # not standard gene symbols. Therefore these need to be mapped to human gene symbols. requires_gene_mapping = True # Extract gene annotation data, excluding control probe lines gene_metadata = get_gene_annotation(soft_file) # Preview filtered annotation data print("Column names:") print(gene_metadata.columns) print("\nPreview of gene annotation data:") print(preview_df(gene_metadata)) # 1. Observe ID mappings: 'ID' column in annotation matches ILMN IDs in expression data, 'Symbol' contains gene symbols prob_col = 'ID' gene_col = 'Symbol' # 2. Get mapping between probe IDs and gene symbols mapping_data = get_gene_mapping(gene_metadata, prob_col, gene_col) # 3. Apply gene mapping to probe-level measurements to get gene expression data gene_data = apply_gene_mapping(genetic_df, mapping_data) # Preview results print("Gene expression data shape:", gene_data.shape) print("\nPreview of gene expression data:") print(gene_data.head().iloc[:, :5]) # 1. Normalize gene symbols and save 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) # Save metadata indicating dataset is not usable due to missing trait data validate_and_save_cohort_info( is_final=False, cohort=cohort, info_path=json_path, is_gene_available=is_gene_available, is_trait_available=False )