Liu-Hy's picture
Add files using upload-large-folder tool
54d4d57 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "High-Density_Lipoprotein_Deficiency"
cohort = "GSE34945"
# Input paths
in_trait_dir = "../DATA/GEO/High-Density_Lipoprotein_Deficiency"
in_cohort_dir = "../DATA/GEO/High-Density_Lipoprotein_Deficiency/GSE34945"
# Output paths
out_data_file = "./output/preprocess/3/High-Density_Lipoprotein_Deficiency/GSE34945.csv"
out_gene_data_file = "./output/preprocess/3/High-Density_Lipoprotein_Deficiency/gene_data/GSE34945.csv"
out_clinical_data_file = "./output/preprocess/3/High-Density_Lipoprotein_Deficiency/clinical_data/GSE34945.csv"
json_path = "./output/preprocess/3/High-Density_Lipoprotein_Deficiency/cohort_info.json"
# Get file paths
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
# Get background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
# Get unique values for each clinical feature
unique_values_dict = get_unique_values_by_row(clinical_data)
# Print background information
print("Background Information:")
print(background_info)
print("\nSample Characteristics:")
print(json.dumps(unique_values_dict, indent=2))
# 1. Gene Expression Data Availability
# Based on background info, this is a SNP genotyping study using GoldenGate bead array
# Not gene expression data
is_gene_available = False
# 2. Variable Availability and Data Type Conversion
# 2.1 Data Row Identification
# For trait:
# From field 2, HDL (trait of interest) status can be inferred from APOC3 levels
# Not constant since values vary widely
trait_row = 2
# For age: Not available in characteristics data
age_row = None
# For gender: Not available in characteristics data
gender_row = None
# 2.2 Conversion Functions
def convert_trait(value: str) -> Optional[int]:
# Extract APOC3 level change after ':'
if ":" not in value:
return None
try:
change = float(value.split(":")[1].strip())
# Negative change (reduction) in APOC3 indicates HDL deficiency
# Using threshold of -20% change
return 1 if change < -20 else 0
except:
return None
def convert_age(value: str) -> Optional[float]:
return None # Not used since age data unavailable
def convert_gender(value: str) -> Optional[int]:
return None # Not used since gender data unavailable
# 3. Save Metadata
is_trait_available = 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=is_trait_available
)
# 4. Clinical Feature Extraction
# Since trait_row is not None, extract clinical features
clinical_df = 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 processed clinical data
preview_df(clinical_df)
# Save to CSV
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
clinical_df.to_csv(out_clinical_data_file)