# Path Configuration | |
from tools.preprocess import * | |
# Processing context | |
trait = "Creutzfeldt-Jakob_Disease" | |
cohort = "GSE62699" | |
# Input paths | |
in_trait_dir = "../DATA/GEO/Creutzfeldt-Jakob_Disease" | |
in_cohort_dir = "../DATA/GEO/Creutzfeldt-Jakob_Disease/GSE62699" | |
# Output paths | |
out_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/GSE62699.csv" | |
out_gene_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/gene_data/GSE62699.csv" | |
out_clinical_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/clinical_data/GSE62699.csv" | |
json_path = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/cohort_info.json" | |
# STEP1 | |
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("Sample Characteristics Dictionary:") | |
print(sample_characteristics_dict) | |
import pandas as pd | |
import os | |
import json | |
from typing import Optional, Callable | |
# 1. Gene Expression Data Availability | |
# Based on the background info, mRNA data (Affymetrix GeneChip HG-U133A 2.0) is indeed present. | |
is_gene_available = True | |
# 2. Variable Availability and Data Type Conversion | |
# 2.1 Data Availability | |
# The sample characteristics dictionary shows: | |
# {0: ['diagnosis: alcohol dependence (AD)', 'diagnosis: Control'], | |
# 1: ['tissue type: post mortem brain']} | |
# There's no mention of Creutzfeldt-Jakob_Disease, age, or gender. So all are set to None. | |
trait_row = None | |
age_row = None | |
gender_row = None | |
# 2.2 Data Type Conversion | |
# Functions to convert potential values (though not used due to unavailability). | |
def convert_trait(x: str) -> Optional[float]: | |
# Returns 1 or 0 for presence/absence of CJD, None if unknown; not used here | |
if not x or ":" not in x: | |
return None | |
# Extract the portion after ':' | |
val = x.split(":", 1)[1].strip().lower() | |
if "creutzfeldt-jakob" in val: | |
return 1.0 | |
elif "control" in val or "no" in val: | |
return 0.0 | |
return None | |
def convert_age(x: str) -> Optional[float]: | |
# Returns a float if age is found, None if unknown; not used here | |
if not x or ":" not in x: | |
return None | |
val = x.split(":", 1)[1].strip() | |
try: | |
return float(val) | |
except ValueError: | |
return None | |
def convert_gender(x: str) -> Optional[int]: | |
# Returns 0 for female, 1 for male, None if unknown; not used here | |
if not x or ":" not in x: | |
return None | |
val = x.split(":", 1)[1].strip().lower() | |
if "female" in val: | |
return 0 | |
elif "male" in val: | |
return 1 | |
return None | |
# 3. Save Metadata (initial filtering) | |
# Trait data availability depends on whether trait_row is None. | |
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 | |
# Because 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]) | |
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)) | |
# STEP6: Gene Identifier Mapping | |
# 1 & 2. Identify the columns in the annotation that correspond to probe ID and gene symbol | |
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Gene Symbol") | |
# 3. Apply the mapping to convert probe-level measurements to gene-level expression | |
gene_data = apply_gene_mapping(gene_data, mapping_df) | |
# STEP7 | |
# 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) | |
# Since trait_row was None, there is no clinical data to link or trait to analyze. | |
# Thus, we skip steps that depend on trait data or linking clinical and genetic data. | |
# 5. Final quality validation | |
# Even though we have no trait, the instructions ask for final validation. | |
# Because "is_trait_available=False", the dataset will be deemed un-usable for trait-based analysis. | |
is_usable = validate_and_save_cohort_info( | |
is_final=True, | |
cohort=cohort, | |
info_path=json_path, | |
is_gene_available=True, | |
is_trait_available=False, # No trait data | |
is_biased=False, # Required non-None value, but has no effect since is_trait_available=False | |
df=normalized_gene_data, # Required DataFrame for final validation | |
note="No trait data found; only gene data is present." | |
) | |
# 6. If the dataset were usable (it won't be, since trait data is unavailable), save the linked data. | |
if is_usable: | |
# No final data to save because trait is missing. | |
pass |