Liu-Hy's picture
Add files using upload-large-folder tool
a0b62f5 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Aniridia"
cohort = "GSE137997"
# Input paths
in_trait_dir = "../DATA/GEO/Aniridia"
in_cohort_dir = "../DATA/GEO/Aniridia/GSE137997"
# Output paths
out_data_file = "./output/preprocess/3/Aniridia/GSE137997.csv"
out_gene_data_file = "./output/preprocess/3/Aniridia/gene_data/GSE137997.csv"
out_clinical_data_file = "./output/preprocess/3/Aniridia/clinical_data/GSE137997.csv"
json_path = "./output/preprocess/3/Aniridia/cohort_info.json"
# Get file paths
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
# Extract background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_file)
# Get unique values per clinical feature
sample_characteristics = get_unique_values_by_row(clinical_data)
# Print background info
print("Dataset Background Information:")
print(f"{background_info}\n")
# Print sample characteristics
print("Sample Characteristics:")
for feature, values in sample_characteristics.items():
print(f"Feature: {feature}")
print(f"Values: {values}\n")
# 1. Gene Expression Data Availability
# Based on the background info, this is an mRNA study, so gene expression data should be available
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# Trait (Aniridia) can be inferred from disease status (AAK vs control) in Feature 2
trait_row = 2
def convert_trait(value):
if not isinstance(value, str):
return None
value = value.split(': ')[-1].strip().lower()
# AAK (aniridia-associated keratopathy) indicates aniridia
if value == 'aak':
return 1
elif value == 'healthy control':
return 0
return None
# Age is available in Feature 0
age_row = 0
def convert_age(value):
if not isinstance(value, str):
return None
try:
age = int(value.split(': ')[-1])
return age
except:
return None
# Gender is available in Feature 1
gender_row = 1
def convert_gender(value):
if not isinstance(value, str):
return None
value = value.split(': ')[-1].strip().lower()
if value in ['f', 'w']: # 'w' likely means woman/weiblich(German)
return 0
elif value == 'm':
return 1
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. Clinical Feature Extraction
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 extracted features
preview = preview_df(clinical_features)
print("Preview of clinical features:")
print(preview)
# Save to CSV
clinical_features.to_csv(out_clinical_data_file)
# Extract gene expression data from matrix file
gene_data = get_genetic_data(matrix_file)
# Print first 20 row IDs and shape of data to help debug
print("Shape of gene expression data:", gene_data.shape)
print("\nFirst few rows of data:")
print(gene_data.head())
print("\nFirst 20 gene/probe identifiers:")
print(gene_data.index[:20])
# Based on the identifiers having the format "hsa-miR-*" and "hsa-let-*", these are microRNA identifiers,
# not standard human gene symbols. They need to be mapped to their target genes.
requires_gene_mapping = True
# Extract gene annotation from SOFT file
gene_annotation = get_gene_annotation(soft_file)
# Print findings about dataset nature
print("Dataset Analysis:")
print("-" * 50)
print("This dataset contains miRNA expression data (hsa-miR-* identifiers)")
print("Standard gene mapping is not applicable for miRNA data")
print("The dataset cannot be used for gene-level analysis without miRNA target information")
print("-" * 50)
# Set requires_gene_mapping to False since we cannot map miRNAs to genes
requires_gene_mapping = False
# Set is_gene_available to False since we don't have gene expression data
is_gene_available = False
# Save updated metadata about dataset usability
validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=is_gene_available,
is_trait_available=True,
note="Dataset contains miRNA expression data instead of gene expression data"
)