# Path Configuration | |
from tools.preprocess import * | |
# Processing context | |
trait = "Anxiety_disorder" | |
cohort = "GSE119995" | |
# Input paths | |
in_trait_dir = "../DATA/GEO/Anxiety_disorder" | |
in_cohort_dir = "../DATA/GEO/Anxiety_disorder/GSE119995" | |
# Output paths | |
out_data_file = "./output/preprocess/1/Anxiety_disorder/GSE119995.csv" | |
out_gene_data_file = "./output/preprocess/1/Anxiety_disorder/gene_data/GSE119995.csv" | |
out_clinical_data_file = "./output/preprocess/1/Anxiety_disorder/clinical_data/GSE119995.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 # Based on the description: "Exposure-induced changes of plasma mRNA expression levels." | |
# 2. Variable Availability and Data Type Conversion | |
# The sample characteristics dictionary is: | |
# {0: ['disease: panic disorder'], | |
# 1: ['tissue: blood plasma'], | |
# 2: ['Sex: female', 'Sex: male', 'Sex: not determined'], | |
# 3: ['medication: 0', 'medication: 1'], | |
# 4: ['timepoint: b1', 'timepoint: p24_1', 'timepoint: pe1'], | |
# 5: [ ... 'individual: #' ... ]} | |
# | |
# We see no row for a varying 'trait' or 'age' field, but row 2 has 'Sex' with different values. | |
trait_row = None # No row with 'trait' variation (only "disease: panic disorder"). | |
age_row = None # No age data found in the dictionary. | |
gender_row = 2 # Row with varying "Sex" values. | |
def convert_trait(x: str): | |
return None # Trait is not available in this dataset for variation. | |
def convert_age(x: str): | |
return None # Age is not available. | |
def convert_gender(x: str): | |
# Example: "Sex: female" -> 'female' | |
val = x.split(':')[-1].strip().lower() | |
if val == 'female': | |
return 0 | |
elif val == 'male': | |
return 1 | |
else: | |
return None | |
# 3. Save Metadata (initial filtering) | |
is_trait_available = (trait_row is not None) | |
is_usable = 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 because trait_row is None. | |
# 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]) | |
# Since the identifiers follow the pattern "ILMN_<id>", they appear to be Illumina probe IDs rather than human gene symbols. | |
# Therefore, they require mapping to gene symbols. | |
print("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. Determine the appropriate columns for the probe IDs and gene symbols | |
prob_col = 'ID' # Matches the "ILMN_xxxxx" identifiers seen in the gene expression data | |
gene_col = 'Symbol' # Column containing gene symbols | |
# 2. Extract the gene mapping from the annotation dataframe | |
mapping_df = get_gene_mapping(gene_annotation, prob_col, gene_col) | |
# 3. Convert probe-level measurements to gene-level by applying the mapping | |
gene_data = apply_gene_mapping(gene_data, mapping_df) | |
# STEP 7: Data Normalization and Linking | |
import pandas as pd | |
# 1) Normalize the 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}") | |
# Because 'trait_row' was None in earlier steps, we have no varying trait data. Therefore, we cannot link | |
# clinical and genetic data in a meaningful way (no trait to analyze) nor perform trait-based processing. | |
# 2) As we are in the final step and must call 'validate_and_save_cohort_info' with is_final=True, we need | |
# to provide both 'df' and 'is_biased'. Since there's no trait data, we create an empty DataFrame and | |
# set is_biased=False (the trait is effectively unavailable, so "bias" is moot). | |
empty_df = pd.DataFrame() | |
is_usable = validate_and_save_cohort_info( | |
is_final=True, | |
cohort=cohort, | |
info_path=json_path, | |
is_gene_available=True, # We do have gene expression data | |
is_trait_available=False, # No valid trait data | |
is_biased=False, # Arbitrary boolean because we must supply one; trait isn't actually present | |
df=empty_df, | |
note="Trait data not available; skipping linking and final dataset output." | |
) | |
# 3) If the dataset were usable, we'd save a final linked dataset, but it's not usable without a trait. | |
if is_usable: | |
# This block won't run because is_trait_available=False => is_usable=False | |
pass | |
else: | |
print("No trait data found; the dataset is not usable for trait-based association. Skipping final output.") |