# Path Configuration from tools.preprocess import * # Processing context trait = "Large_B-cell_Lymphoma" cohort = "GSE243973" # Input paths in_trait_dir = "../DATA/GEO/Large_B-cell_Lymphoma" in_cohort_dir = "../DATA/GEO/Large_B-cell_Lymphoma/GSE243973" # Output paths out_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/GSE243973.csv" out_gene_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/gene_data/GSE243973.csv" out_clinical_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/clinical_data/GSE243973.csv" json_path = "./output/preprocess/3/Large_B-cell_Lymphoma/cohort_info.json" # Get file paths for 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 clinical feature row clinical_features = get_unique_values_by_row(clinical_data) # Print background info print("Background Information:") print(background_info) print("\nClinical Features and Sample Values:") print(json.dumps(clinical_features, indent=2)) # 1. Gene Expression Data Availability # Yes - Series summary mentions transcriptomic profiling is_gene_available = True # 2.1 Feature Key Identification # Trait - Row 0 contains disease state info trait_row = 0 # Age - Not available in characteristics age_row = None # Gender - Not available in characteristics gender_row = None # 2.2 Data Type Conversion Functions def convert_trait(x: str) -> int: """Convert disease status to binary: 1 for LBCL, 0 for control""" if pd.isna(x): return None value = x.split(': ')[1].lower() if ': ' in x else x.lower() if 'large b-cell lymphoma' in value: return 1 elif 'healthy control' in value: return 0 return None def convert_age(x: str) -> float: """Not used but defined for completeness""" return None def convert_gender(x: str) -> int: """Not used but defined for completeness""" 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. Extract Clinical Features if trait_row is not None: clinical_features = geo_select_clinical_features( clinical_df=clinical_data, trait=trait, trait_row=trait_row, convert_trait=convert_trait, age_row=age_row, convert_age=convert_age, gender_row=gender_row, convert_gender=convert_gender ) # Preview the data preview = preview_df(clinical_features) print("Clinical features preview:", preview) # Save to CSV clinical_features.to_csv(out_clinical_data_file) # Extract gene expression data from matrix file genetic_data = get_genetic_data(matrix_file) # Print first 20 row IDs print("First 20 gene/probe IDs:") print(genetic_data.index[:20].tolist()) # These appear to be standard human gene symbols (HGNC format) # e.g. ABCF1, ACACA, ADAR are well-known human gene symbols # No mapping needed as they are already in the correct format requires_gene_mapping = False # 1. Normalize gene symbols genetic_data = normalize_gene_symbols_in_index(genetic_data) genetic_data.to_csv(out_gene_data_file) # 2. Link clinical and genetic data linked_data = geo_link_clinical_genetic_data(clinical_features, genetic_data) # 3. Handle missing values linked_data = handle_missing_values(df=linked_data, trait_col=trait) # 4. Check for biases and remove biased demographic features is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) # 5. Validate dataset quality and save metadata note = "" if is_biased: note = "The trait distribution is severely biased." is_usable = validate_and_save_cohort_info( is_final=True, cohort=cohort, info_path=json_path, is_gene_available=True, is_trait_available=True, is_biased=is_biased, df=linked_data, note=note ) # 6. Save linked data if usable if is_usable: linked_data.to_csv(out_data_file)