Liu-Hy's picture
Add files using upload-large-folder tool
ee94703 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Adrenocortical_Cancer"
cohort = "GSE76019"
# Input paths
in_trait_dir = "../DATA/GEO/Adrenocortical_Cancer"
in_cohort_dir = "../DATA/GEO/Adrenocortical_Cancer/GSE76019"
# Output paths
out_data_file = "./output/preprocess/1/Adrenocortical_Cancer/GSE76019.csv"
out_gene_data_file = "./output/preprocess/1/Adrenocortical_Cancer/gene_data/GSE76019.csv"
out_clinical_data_file = "./output/preprocess/1/Adrenocortical_Cancer/clinical_data/GSE76019.csv"
json_path = "./output/preprocess/1/Adrenocortical_Cancer/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. Gene expression data availability
is_gene_available = True # Based on "gene expression profiling" statement
# 2. Variable availability
# The trait is constant ("ACC") across all samples --> not useful for association study
trait_row = None
age_row = None
gender_row = None
# 2.2 Define data conversion functions (they won't be used because rows are None, but we must still define them)
def convert_trait(value: str):
# No actual functionality here because trait_row is None
return None
def convert_age(value: str):
# No actual functionality here because age_row is None
return None
def convert_gender(value: str):
# No actual functionality here because gender_row is None
return None
# 3. Initial Filtering (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
)
# 4. Clinical Feature Extraction is skipped since 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])
# The gene expression data uses probe-based identifiers (e.g., Affymetrix probe IDs) rather than standard human gene symbols.
# Therefore, a mapping step is needed.
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) The key in 'gene_annotation' that matches the probe identifiers in 'gene_data' is "ID".
# The key that stores the gene symbols is "Gene Symbol".
# 2) Extract a gene mapping dataframe from 'gene_annotation' with these columns.
mapping_df = get_gene_mapping(
annotation=gene_annotation,
prob_col="ID",
gene_col="Gene Symbol"
)
# 3) Convert probe-level measurements to gene-level expression data.
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
# STEP 7: Data Normalization and Linking
import pandas as pd
# 1. Normalize gene symbols and save the normalized gene data
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
normalized_gene_data.to_csv(out_gene_data_file, index=True)
# Since the trait was determined unavailable (trait_row is None), there is no clinical data to link.
# We therefore skip linking, missing value handling, and bias checks.
# 5. Final quality validation (the dataset is not suitable for trait-based association studies).
# We must provide a DataFrame and a boolean for is_biased to avoid errors, even though trait data is missing.
is_usable = validate_and_save_cohort_info(
is_final=True,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False,
is_biased=False, # Arbitrary value, as the dataset is already not usable due to missing trait
df=pd.DataFrame(), # Empty DataFrame to satisfy validation requirements
note="No trait data, so dataset is not suitable for association studies."
)
# 6. Since the dataset is not usable for trait-based analyses, we do NOT save a final linked data file.