Liu-Hy's picture
Add files using upload-large-folder tool
012bb62 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Sickle_Cell_Anemia"
cohort = "GSE46471"
# Input paths
in_trait_dir = "../DATA/GEO/Sickle_Cell_Anemia"
in_cohort_dir = "../DATA/GEO/Sickle_Cell_Anemia/GSE46471"
# Output paths
out_data_file = "./output/preprocess/3/Sickle_Cell_Anemia/GSE46471.csv"
out_gene_data_file = "./output/preprocess/3/Sickle_Cell_Anemia/gene_data/GSE46471.csv"
out_clinical_data_file = "./output/preprocess/3/Sickle_Cell_Anemia/clinical_data/GSE46471.csv"
json_path = "./output/preprocess/3/Sickle_Cell_Anemia/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)
print("Background Information:")
print(background_info)
print("\nSample Characteristics:")
# Get dictionary of unique values per row
unique_values_dict = get_unique_values_by_row(clinical_data)
for row, values in unique_values_dict.items():
print(f"\n{row}:")
print(values)
# 1. Gene Expression Data Availability
# Yes, this is a microarray gene expression dataset studying endothelial cells
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# 2.1 Data Availability
# For this specific dataset studying damage pathways in endothelial cells,
# all samples are control samples (no disease state), so trait data is not available
trait_row = None
# No age data available in sample characteristics
age_row = None
# No gender data available in sample characteristics
gender_row = None
# 2.2 Data Type Conversion
def convert_trait(x):
# Not needed since trait data is not available
return None
def convert_age(x):
# Not needed since age data is not available
return None
def convert_gender(x):
# Not needed since gender data is not available
return None
# 3. Save Metadata
# Initial filtering - since trait data is not available (trait_row is None),
# is_trait_available should be False
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. Clinical Feature Extraction
# Skip this step since trait_row is None, indicating clinical data is not available
# Get gene expression data from matrix file
genetic_data = get_genetic_data(matrix_file_path)
# Examine data structure
print("Data structure and head:")
print(genetic_data.head())
print("\nShape:", genetic_data.shape)
print("\nFirst 20 row IDs (gene/probe identifiers):")
print(list(genetic_data.index)[:20])
# Get a few column names to verify sample IDs
print("\nFirst 5 column names:")
print(list(genetic_data.columns)[:5])
# The gene identifiers in the data appear to be just numeric values (1,2,3...),
# which are not standard human gene symbols. We need to map these to proper gene symbols.
requires_gene_mapping = True
# Extract gene annotation data
gene_annotation = get_gene_annotation(soft_file_path)
# Preview column names and values from annotation dataframe
print("Gene annotation DataFrame preview:")
print(preview_df(gene_annotation))
# Extract gene identifiers and gene symbols from the annotation data
id_col = 'ID' # Gene identifiers in the data are numeric values (1,2,3...)
gene_col = 'GENE_SYMBOL' # Gene symbols are stored in GENE_SYMBOL column
# Get mapping between gene identifiers and gene symbols
mapping_data = get_gene_mapping(gene_annotation, id_col, gene_col)
# Convert probe-level measurements to gene expression data
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# Preview the gene data after mapping
print("\nGene expression data after mapping:")
print(gene_data.shape)
print("\nFirst few genes and their expression values:")
print(preview_df(gene_data))
# 1. Normalize gene symbols in gene expression data
gene_data = normalize_gene_symbols_in_index(gene_data)
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
gene_data.to_csv(out_gene_data_file)
print("\nGene data shape (normalized gene-level):", gene_data.shape)
# Save metadata indicating dataset is not usable due to lack of trait data
note = "Dataset contains normalized gene expression data but lacks trait information."
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, # Set to True since no trait data makes it unusable
df=gene_data, # Provide the gene expression data
note=note
)