Liu-Hy's picture
Add files using upload-large-folder tool
7623c74 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "LDL_Cholesterol_Levels"
cohort = "GSE28893"
# Input paths
in_trait_dir = "../DATA/GEO/LDL_Cholesterol_Levels"
in_cohort_dir = "../DATA/GEO/LDL_Cholesterol_Levels/GSE28893"
# Output paths
out_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/GSE28893.csv"
out_gene_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/gene_data/GSE28893.csv"
out_clinical_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/clinical_data/GSE28893.csv"
json_path = "./output/preprocess/3/LDL_Cholesterol_Levels/cohort_info.json"
# Get paths for relevant files
soft_path, matrix_path = geo_get_relevant_filepaths(in_cohort_dir)
# Extract background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_path)
# Get unique values for each clinical feature
sample_chars = get_unique_values_by_row(clinical_data)
# Print dataset background information
print("Background Information:")
print(background_info)
print("\nClinical Features Overview:")
print(json.dumps(sample_chars, indent=2))
# 1. Gene Expression Data Availability
# The dataset is from Illumina Expression Array and is about gene expression in liver tissue
is_gene_available = True
# 2.1 Data Availability
# From background info, this study includes eQTLs related to LDL cholesterol levels
# But trait values are not directly available in sample characteristics
trait_row = None
# Age data is available in row 1
age_row = 1
# Gender data is available in row 2
gender_row = 2
# 2.2 Data Type Conversion Functions
def convert_trait(x):
# Not needed since trait data is not available
return None
def convert_age(x):
try:
# Extract number after colon
age = int(x.split(': ')[1])
return age
except:
return None
def convert_gender(x):
try:
# Extract value after colon and convert to binary
gender = x.split(': ')[1]
if gender == 'F':
return 0
elif gender == 'M':
return 1
return None
except:
return None
# 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
)
# 4. Skip clinical feature extraction since trait_row is None
# Get gene expression data
genetic_data = get_genetic_data(matrix_path)
# Preview raw data structure
print("First few rows of the raw data:")
print(genetic_data.head())
print("\nShape of the data:")
print(genetic_data.shape)
# Print first 20 row IDs to verify data structure
print("\nFirst 20 probe/gene identifiers:")
print(list(genetic_data.index)[:20])
# These IDs start with "ILMN_" which indicates they are Illumina probe IDs, not gene symbols
requires_gene_mapping = True
# Extract gene annotation data from SOFT file
gene_metadata = get_gene_annotation(soft_path)
# Preview annotation data structure
print("Gene annotation data preview:")
print(preview_df(gene_metadata))
# 1. 'ID' column in metadata matches ILMN probe IDs in expression data
# 'Symbol' column contains the gene symbols
# 2. Get gene mapping data
mapping_data = get_gene_mapping(gene_metadata, "ID", "Symbol")
# 3. Convert probe-level measurements to gene-level expression
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# Preview result
print("Gene expression data preview:")
print(gene_data.head())
print("\nShape after mapping:", gene_data.shape)
# 1. Normalize gene symbols
gene_data = normalize_gene_symbols_in_index(gene_data)
gene_data.to_csv(out_gene_data_file)
# Since we previously determined trait data is not available (trait_row = None),
# we cannot proceed with data linking and quality assessment
# We need to validate this cohort as not usable
note = "The dataset contains gene expression data but lacks LDL cholesterol level measurements"
is_usable = validate_and_save_cohort_info(
is_final=False, # Use initial filtering since we can't do final validation
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False
)