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 = "GSE111567"
# Input paths
in_trait_dir = "../DATA/GEO/LDL_Cholesterol_Levels"
in_cohort_dir = "../DATA/GEO/LDL_Cholesterol_Levels/GSE111567"
# Output paths
out_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/GSE111567.csv"
out_gene_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/gene_data/GSE111567.csv"
out_clinical_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/clinical_data/GSE111567.csv"
json_path = "./output/preprocess/3/LDL_Cholesterol_Levels/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
# Based on the background info mentioning HumanHT-12 v4 microarray and gene expression analysis,
# this dataset contains gene expression data
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# Trait (LDL cholesterol) is not directly available in clinical features
trait_row = None
# Age is not available in clinical features
age_row = None
# Gender is available at index 0
gender_row = 0
def convert_gender(x):
if x is None:
return None
value = x.split(': ')[1].strip()
if value.upper() == 'F':
return 0
elif value.upper() == 'M':
return 1
return None
# Convert functions for completeness though trait and age not available
def convert_trait(x):
return None
def convert_age(x):
return None
# 3. Save Metadata
# Perform initial filtering and save cohort info
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. Clinical Feature Extraction
# Skip since trait_row is None, indicating clinical data is not usable for our purpose
# 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 are Illumina probe IDs, not standard human gene symbols
# They need to be mapped to official HGNC gene symbols for analysis
requires_gene_mapping = True
# Extract gene annotation from SOFT file
gene_annotation = get_gene_annotation(soft_file)
# Preview column names and first few values
print("Gene Annotation Preview:")
print(preview_df(gene_annotation))
# 1. Observe gene identifiers:
# Gene expression data uses 'ILMN_' probe IDs, which match the 'ID' column in annotation
# Gene symbols are in the 'Symbol' column of annotation
# 2. Extract mapping between probe IDs and gene symbols
mapping_data = get_gene_mapping(gene_annotation, 'ID', 'Symbol')
# 3. Apply gene mapping to convert probe-level data to gene expression data
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# 1. Normalize gene symbols and save gene data
gene_data = normalize_gene_symbols_in_index(gene_data)
gene_data.to_csv(out_gene_data_file)
# Create a minimal dataframe for validation purposes
df_for_validation = pd.DataFrame(index=gene_data.index)
df_for_validation[trait] = None # Add trait column with all missing values
note = "The dataset contains gene expression data from peripheral blood mononuclear cells measured with HumanHT-12 v4 microarray but lacks LDL cholesterol level measurements."
is_usable = validate_and_save_cohort_info(
is_final=True,
cohort=cohort,
info_path=json_path,
is_gene_available=is_gene_available,
is_trait_available=False,
is_biased=True, # Missing trait data is considered extreme bias
df=df_for_validation,
note=note
)