# Path Configuration | |
from tools.preprocess import * | |
# Processing context | |
trait = "Cervical_Cancer" | |
cohort = "GSE146114" | |
# Input paths | |
in_trait_dir = "../DATA/GEO/Cervical_Cancer" | |
in_cohort_dir = "../DATA/GEO/Cervical_Cancer/GSE146114" | |
# Output paths | |
out_data_file = "./output/preprocess/1/Cervical_Cancer/GSE146114.csv" | |
out_gene_data_file = "./output/preprocess/1/Cervical_Cancer/gene_data/GSE146114.csv" | |
out_clinical_data_file = "./output/preprocess/1/Cervical_Cancer/clinical_data/GSE146114.csv" | |
json_path = "./output/preprocess/1/Cervical_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 # The dataset uses Illumina gene expression arrays. | |
# 2. Variable Availability | |
trait_row = None # Dataset includes only cervical cancer patients, so "Cervical_Cancer" is constant or not recorded. | |
age_row = None # No age-related information found. | |
gender_row = None # Likely all female patients, thus constant or not recorded. | |
# 2.2 Data Type Conversion Functions | |
def convert_trait(value: str): | |
# No trait data is actually available (or it's constant). | |
return None | |
def convert_age(value: str): | |
# No age data is available. | |
return None | |
def convert_gender(value: str): | |
# No gender data is available (or is constant). | |
return None | |
# 3. Save Metadata with initial filtering | |
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 | |
# Skipped because trait_row is None, so no clinical data extraction is performed. | |
# 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 identifiers (e.g., "ILMN_1343291") are Illumina probe IDs, not standard 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. Decide which columns to use for mapping: | |
# - The gene expression data uses "ILMN_####" style IDs, which match the "ID" column in 'gene_annotation'. | |
# - The "Symbol" column in 'gene_annotation' appears to store the actual gene symbols. | |
# 2. Get a gene mapping dataframe using the library function, choosing 'ID' for probe IDs and 'Symbol' for the symbols. | |
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol') | |
# 3. Convert probe-level measurements to gene-level expression by applying the mapping. Reuse the variable 'gene_data'. | |
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df) | |
# Just print a short preview to confirm the transformation | |
print("Mapped gene_data preview:") | |
print(gene_data.head()) | |
# STEP 7 | |
import pandas as pd | |
# 1. Normalize gene symbols in the gene_data, then save to CSV. | |
normalized_gene_data = normalize_gene_symbols_in_index(gene_data) | |
normalized_gene_data.to_csv(out_gene_data_file) | |
# Since 'trait_row' is None, no clinical trait data is available. | |
# We cannot perform linking or trait-based QC. The dataset is effectively unusable for trait analysis. | |
# 2 & 3 are skipped because we have no clinical data to link or trait to process. | |
# Prepare an empty DataFrame and a dummy bias indicator to pass final validation without error. | |
df_dummy = pd.DataFrame() | |
trait_biased_dummy = False # This dummy value is required by the library. | |
# 5. Conduct final validation. We must supply a DataFrame and is_biased value if is_final=True. | |
# Since there's no trait data, set is_trait_available=False and the dataset is not 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, | |
is_biased=trait_biased_dummy, | |
df=df_dummy, | |
note="No trait data available; only gene data present." | |
) | |
# 6. The dataset won't be usable when trait data is missing. Do not save a final linked data CSV. | |
if is_usable: | |
# If it were marked usable (unlikely), we would save the linked data here. | |
pass |