# Path Configuration | |
from tools.preprocess import * | |
# Processing context | |
trait = "Adrenocortical_Cancer" | |
cohort = "GSE68606" | |
# Input paths | |
in_trait_dir = "../DATA/GEO/Adrenocortical_Cancer" | |
in_cohort_dir = "../DATA/GEO/Adrenocortical_Cancer/GSE68606" | |
# Output paths | |
out_data_file = "./output/preprocess/1/Adrenocortical_Cancer/GSE68606.csv" | |
out_gene_data_file = "./output/preprocess/1/Adrenocortical_Cancer/gene_data/GSE68606.csv" | |
out_clinical_data_file = "./output/preprocess/1/Adrenocortical_Cancer/clinical_data/GSE68606.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 | |
# Based on the "Assay Type: Gene Expression" and "Affymetrix Human Genome U133A arrays" in the metadata, | |
# we conclude that this dataset likely contains gene expression data. | |
is_gene_available = True | |
# 2) Variable Availability and Data Type Conversion | |
# 2.1 Identify availability of 'trait', 'age', and 'gender' by looking at the Sample Characteristics Dictionary | |
# We did not find "Adrenocortical_Cancer" or an equivalent entry in any row, | |
# so trait data is considered not available. | |
trait_row = None | |
# Age data is present in row 6 with multiple unique numeric values. | |
age_row = 6 | |
# Gender data is present in row 5 (female/male). | |
gender_row = 5 | |
# 2.2 Define conversion functions for each variable | |
def convert_trait(x: str): | |
# Trait data is not available in this dataset, return None for all inputs. | |
return None | |
def convert_age(x: str): | |
# Extract the substring after the colon and strip whitespace | |
val = x.split(":", 1)[-1].strip() | |
# Convert to integer if possible, otherwise None | |
return int(val) if val.isdigit() else None | |
def convert_gender(x: str): | |
# Extract the substring after the colon and strip whitespace | |
val = x.split(":", 1)[-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) # False in this case | |
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 this step because trait_row is None (no trait data available). | |
# 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]) | |
# These identifiers (e.g., '1007_s_at', '1053_at') are Affymetrix probe set IDs, not 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) The key for the probe identifiers in the gene annotation is "ID", | |
# and the key for the gene symbols is "Gene Symbol". | |
# 2) Build a gene mapping dataframe using those two columns. | |
gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol') | |
# 3) Apply the mapping to convert probe-level measurements to gene expression data. | |
gene_data = apply_gene_mapping(gene_data, gene_mapping) | |
# STEP 7: Data Normalization and Linking | |
# Even though we lack trait data, it's still valuable to finalize gene-level data. | |
# 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 trait_row = None, there's no trait data to link or analyze. | |
# We cannot produce a linked dataset or evaluate trait bias in a meaningful way. | |
# However, the task instructions request a "final" validation. | |
import pandas as pd | |
# Provide a dummy DataFrame and set is_biased to False | |
# so that validate_and_save_cohort_info can finalize and mark this dataset as unusable for trait analysis. | |
empty_df = pd.DataFrame() | |
is_biased = False | |
is_usable = validate_and_save_cohort_info( | |
is_final=True, | |
cohort=cohort, | |
info_path=json_path, | |
is_gene_available=True, # We do have gene data | |
is_trait_available=False, # But no trait data | |
is_biased=is_biased, # Arbitrarily set to False since no trait is present | |
df=empty_df, # An empty DataFrame to satisfy the function's requirements | |
note="No trait data available, so no final linked dataset can be produced." | |
) | |
# 6. Because the dataset is not usable for trait-based analysis, we do not save a final linked dataset. |