Liu-Hy's picture
Add files using upload-large-folder tool
e6817b9 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Height"
cohort = "GSE101710"
# Input paths
in_trait_dir = "../DATA/GEO/Height"
in_cohort_dir = "../DATA/GEO/Height/GSE101710"
# Output paths
out_data_file = "./output/preprocess/3/Height/GSE101710.csv"
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE101710.csv"
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE101710.csv"
json_path = "./output/preprocess/3/Height/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: RNA samples were hybridized to Human HT12-V4.0 BeadChip
# This indicates gene expression data availability
is_gene_available = True
# 2. Variable Availability and Data Type
# Height was recorded in screening questionnaire but not in sample characteristics
trait_row = None
# Age can be inferred from age group in row 1
age_row = 1
def convert_age(value: str) -> float:
# Extract value after colon and strip whitespace
value = value.split(':')[1].strip()
# Convert age groups to representative values
if value == 'Young':
return 25.5 # midpoint of 21-30 range from background info
elif value == 'Older':
return 70.0 # approximate midpoint for >65
else:
return None
# No gender information available
gender_row = None
def convert_gender(value: str) -> int:
return None
def convert_trait(value: str) -> float:
return None
# 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
# Skip since trait_row is None
# Extract gene expression data from the matrix file
genetic_data = get_genetic_data(matrix_file_path)
# Print first 20 row IDs
print("First 20 row IDs:")
print(genetic_data.index[:20].tolist())
# These identifiers start with "ILMN_" which indicates they are Illumina probe IDs, not gene symbols
# They need to be mapped to standard human gene symbols for analysis
requires_gene_mapping = True
# Extract gene annotation data from SOFT file
gene_metadata = get_gene_annotation(soft_file_path)
# Display information about the annotation data
print("Column names:")
print(gene_metadata.columns.tolist())
print("\nPreview of first few rows:")
print(json.dumps(preview_df(gene_metadata), indent=2))
# 1. Looking at gene expression data and annotation data:
# The gene expression data uses IDs like 'ILMN_1343291'
# The 'ID' column in gene annotation matches this format
# The 'Symbol' column contains gene symbols
# 2. Get mapping between probe IDs and gene symbols
mapping_data = get_gene_mapping(gene_metadata, 'ID', 'Symbol')
# 3. Convert probe-level measurements to gene expression data
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# 1. Normalize gene symbols
gene_data = normalize_gene_symbols_in_index(gene_data)
gene_data.to_csv(out_gene_data_file)
# Create a minimal dataframe for validation
minimal_df = pd.DataFrame({'trait': [None]})
# Validate and save metadata about the unusable dataset
is_usable = validate_and_save_cohort_info(
is_final=True,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False,
is_biased=True, # Dataset without trait measurements is inherently biased
df=minimal_df,
note="Dataset contains gene expression data but no height measurements"
)