# Path Configuration | |
from tools.preprocess import * | |
# Processing context | |
trait = "Anxiety_disorder" | |
cohort = "GSE60491" | |
# Input paths | |
in_trait_dir = "../DATA/GEO/Anxiety_disorder" | |
in_cohort_dir = "../DATA/GEO/Anxiety_disorder/GSE60491" | |
# Output paths | |
out_data_file = "./output/preprocess/1/Anxiety_disorder/GSE60491.csv" | |
out_gene_data_file = "./output/preprocess/1/Anxiety_disorder/gene_data/GSE60491.csv" | |
out_clinical_data_file = "./output/preprocess/1/Anxiety_disorder/clinical_data/GSE60491.csv" | |
json_path = "./output/preprocess/1/Anxiety_disorder/cohort_info.json" | |
# STEP 1 | |
from tools.preprocess import * | |
# 1. Identify the paths to the SOFT file and the matrix file | |
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) | |
# 2. Read the matrix file to obtain background information and sample characteristics data | |
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design'] | |
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1'] | |
background_info, clinical_data = get_background_and_clinical_data( | |
matrix_file, | |
background_prefixes, | |
clinical_prefixes | |
) | |
# 3. Obtain the sample characteristics dictionary from the clinical dataframe | |
sample_characteristics_dict = get_unique_values_by_row(clinical_data) | |
# 4. Explicitly print out all the background information and the sample characteristics dictionary | |
print("Background Information:") | |
print(background_info) | |
print("\nSample Characteristics Dictionary:") | |
print(sample_characteristics_dict) | |
# 1. Gene Expression Data Availability | |
is_gene_available = True # The series explicitly mentions "gene expression profiling", so we consider it available. | |
# 2. Variable Availability and Data Type Conversion | |
# After examining the sample characteristics, | |
# we do not see any key referencing "anxiety" or "anxiety_disorder." | |
# Therefore, we conclude that the trait data is not available in this dataset. | |
trait_row = None | |
# The 'age' information appears in row 0. | |
age_row = 0 | |
# The 'gender' information appears in row 1 (it's labeled 'male: 0' or 'male: 1'). | |
gender_row = 1 | |
# Define data-type conversion functions. | |
def convert_trait(value: str): | |
# Trait data is unavailable, so this function won't be used. | |
# We'll just return None as a placeholder. | |
return None | |
def convert_age(value: str): | |
# Extract the numeric part after the colon. Convert to float if possible, else None. | |
try: | |
val = value.split(':', 1)[1].strip() | |
return float(val) | |
except: | |
return None | |
def convert_gender(value: str): | |
# The field is "male: 0" for female, "male: 1" for male. | |
# We'll parse it and convert to 0 (female) or 1 (male). | |
try: | |
val = value.split(':', 1)[1].strip() | |
return 1 if val == '1' else 0 | |
except: | |
return None | |
# Determine whether trait data is available | |
is_trait_available = trait_row is not 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=is_trait_available | |
) | |
# 4. Clinical Feature Extraction | |
# Since trait_row is None, we skip this step. | |
# STEP3 | |
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined. | |
gene_data = get_genetic_data(matrix_file) | |
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation. | |
print(gene_data.index[:20]) | |
# Based on the identifiers such as "7A5" (likely SLC7A5) and "A2BP1" (also known as RBFOX1), | |
# it appears that these gene symbols are not standardized. Therefore, mapping is required. | |
requires_gene_mapping = True | |
# STEP5 | |
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file. | |
gene_annotation = get_gene_annotation(soft_file) | |
# 2. Use the 'preview_df' function from the library to preview the data and print out the results. | |
print("Gene annotation preview:") | |
print(preview_df(gene_annotation)) | |
# STEP: Gene Identifier Mapping | |
# 1. Identify which columns match the gene expression data | |
# Based on the previous previews, 'ID' matches the expression data identifiers, | |
# and 'ORF' contains the gene symbols. | |
mapping_df = get_gene_mapping(annotation=gene_annotation, prob_col='ID', gene_col='ORF') | |
# 2. Convert probe-level measurements to gene expression data by applying the gene mapping | |
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df) | |
# Print a small preview of the resulting mapped gene data | |
print("Mapped gene data shape:", gene_data.shape) | |
print("First 5 mapped gene symbols:", gene_data.index[:5]) | |
# STEP 7: Data Normalization and Linking | |
# 1. Normalize gene symbols in the obtained gene expression data | |
normalized_gene_data = normalize_gene_symbols_in_index(gene_data) | |
normalized_gene_data.to_csv(out_gene_data_file) | |
print(f"Saved normalized gene data to {out_gene_data_file}") | |
# 2. Link the clinical and genetic data on sample IDs | |
linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data) | |
# Since trait_row is None, trait data is unavailable, we cannot perform final trait-based validation. | |
# 3. We skip any trait-based missing value handling and bias checking because there's no trait. | |
# 4. Perform only partial metadata validation (is_final=False) since no trait data is available. | |
is_usable = validate_and_save_cohort_info( | |
is_final=False, | |
cohort=cohort, | |
info_path=json_path, | |
is_gene_available=True, | |
is_trait_available=False | |
) | |
# 5. We do not save a final linked data file because trait-based analysis is not possible. | |
print("Dataset does not have the specified trait data; no final data output generated.") |