Liu-Hy's picture
Add files using upload-large-folder tool
a5a8278 verified
raw
history blame contribute delete
4.82 kB
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Bipolar_disorder"
cohort = "GSE93114"
# Input paths
in_trait_dir = "../DATA/GEO/Bipolar_disorder"
in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE93114"
# Output paths
out_data_file = "./output/preprocess/1/Bipolar_disorder/GSE93114.csv"
out_gene_data_file = "./output/preprocess/1/Bipolar_disorder/gene_data/GSE93114.csv"
out_clinical_data_file = "./output/preprocess/1/Bipolar_disorder/clinical_data/GSE93114.csv"
json_path = "./output/preprocess/1/Bipolar_disorder/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)
# 1) Determine gene expression data availability.
is_gene_available = True # Based on series title mentioning "Gene and MicroRNA expression", we assume gene data is present.
# 2) Variable availability and data type conversion.
# From inspection, all samples have the same 'disease state: bipolar disorder' (constant),
# and there's no mention of age or gender. So they are not available for analysis.
trait_row = None
age_row = None
gender_row = None
# Define conversion functions. Although data is not available, we provide stubs as required.
def convert_trait(value: str):
"""
Convert trait (bipolar_disorder) to binary (0 or 1).
Since no actual data is available (constant), return None.
"""
return None
def convert_age(value: str):
"""
Convert age data to continuous.
No data is available in this dataset, so return None.
"""
return None
def convert_gender(value: str):
"""
Convert gender to binary (female=0, male=1).
No data is available in this dataset, so return None.
"""
return None
# 3) Conduct initial filtering and save metadata.
# Trait data is not available (trait_row is 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=(trait_row is not None)
)
# 4) Since 'trait_row' is None, we skip clinical feature extraction.
# 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])
# Observing the gene identifiers, they appear to be numeric probe IDs rather than standard human gene symbols.
# Therefore, gene mapping is required.
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
# The numeric row indices in our gene expression DataFrame (e.g., "16650001")
# do not match any column in the annotation (which contains entries like "14q0_st").
# Therefore, we cannot perform a meaningful mapping here. We'll retain the data as is.
print("No matching annotation found; skipping gene mapping.")
# Keep gene_data unchanged.
# STEP 7: Data Normalization and Skipping Final Validation Due to No Trait Data
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
normalized_gene_data.to_csv(out_gene_data_file)
# Since no trait data is available (trait_row is None), we cannot link clinical data or finalize.
# We'll do a non-final validation just to record that gene data exists but trait data does not.
is_usable = validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False
)
# No final linked data is saved because there is no trait data to integrate.