Liu-Hy's picture
Add files using upload-large-folder tool
b5650f0 verified
raw
history blame
5.24 kB
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Creutzfeldt-Jakob_Disease"
cohort = "GSE87629"
# Input paths
in_trait_dir = "../DATA/GEO/Creutzfeldt-Jakob_Disease"
in_cohort_dir = "../DATA/GEO/Creutzfeldt-Jakob_Disease/GSE87629"
# Output paths
out_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/GSE87629.csv"
out_gene_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/gene_data/GSE87629.csv"
out_clinical_data_file = "./output/preprocess/1/Creutzfeldt-Jakob_Disease/clinical_data/GSE87629.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)
# Step 1: Determine if gene expression data is available
# Based on the background info (DNA microarray, purified B/T cells), we set:
is_gene_available = True
# Step 2: Identify data availability for trait, age, and gender.
# None of the sample characteristics keys mention Creutzfeldt-Jakob disease, age, or gender.
trait_row = None
age_row = None
gender_row = None
# Step 2.2: Define conversion functions, although no data is available.
def convert_trait(value: str) -> int:
# Not applicable; return None
return None
def convert_age(value: str) -> float:
# Not applicable; return None
return None
def convert_gender(value: str) -> int:
# Not applicable; return None
return None
# Step 3: Initial filtering and save metadata
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
)
# Step 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])
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. Identify the columns for probe ID and gene symbol based on the annotation data preview.
# We see that the 'ID' column matches the probe identifiers ('ILMN_...'),
# and the 'Symbol' column holds the gene symbols.
prob_col = 'ID'
gene_col = 'Symbol'
# 2. Extract the columns from gene_annotation and construct the mapping dataframe.
mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
# 3. Convert probe-level data to gene-level data by applying the mapping.
gene_data = apply_gene_mapping(gene_data, mapping_df)
# Print basic overview to confirm the gene_data structure.
print("Shape of gene_data after mapping:", gene_data.shape)
print("First 20 gene symbols in the mapped data:")
print(list(gene_data.index[:20]))
# STEP7
# Since in STEP 2 we determined that there is no available trait data (trait_row is None),
# we cannot link clinical data or perform trait-based analyses. We'll therefore skip
# linking, missing value handling based on the trait, and bias checks.
# However, we can still normalize the gene expression data and save it.
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
normalized_gene_data.to_csv(out_gene_data_file)
# 2. Because trait data is not available, we skip steps involving clinical data, linking, and trait-based checks.
# 3. Perform a final-like validation but use is_final=False to avoid errors, indicating that the dataset
# lacks trait data. This will update the cohort_info.json with the fact that there is no trait data.
is_usable = validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False
)
# 4. Because is_trait_available=False, the dataset is not usable for trait-based analysis.
# No further steps are needed.