Liu-Hy's picture
Add files using upload-large-folder tool
7c88557 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Cervical_Cancer"
cohort = "GSE137034"
# Input paths
in_trait_dir = "../DATA/GEO/Cervical_Cancer"
in_cohort_dir = "../DATA/GEO/Cervical_Cancer/GSE137034"
# Output paths
out_data_file = "./output/z2/preprocess/Cervical_Cancer/GSE137034.csv"
out_gene_data_file = "./output/z2/preprocess/Cervical_Cancer/gene_data/GSE137034.csv"
out_clinical_data_file = "./output/z2/preprocess/Cervical_Cancer/clinical_data/GSE137034.csv"
json_path = "./output/z2/preprocess/Cervical_Cancer/cohort_info.json"
# Step 1: Initial Data Loading
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 2: Dataset Analysis and Clinical Feature Extraction
# Step: Dataset Analysis and Clinical Feature Extraction for GSE137034
# 1) Gene expression data availability
# Background indicates chromatin accessibility (ATAC-seq) in a SuperSeries; not gene expression suitable for our analysis.
is_gene_available = False
# 2) Variable availability and converters
# From the sample characteristics:
# {0: ['tissue: THP1 cells', 'tissue: Stimulated human CD4 T-cells'],
# 1: ['treatment: Cells cultured in full RPMI', 'treatment: Cells cultured in RPMI without arginine']}
# No trait (Cervical Cancer), age, or gender information available.
trait_row = None
age_row = None
gender_row = None
def _after_colon(value):
if value is None:
return None
s = str(value)
if ':' in s:
s = s.split(':', 1)[1]
s = s.strip()
return s if s else None
def convert_trait(value):
# Binary: 1 = cervical cancer case, 0 = non-cancer/controls.
v = _after_colon(value)
if v is None:
return None
vlow = v.lower()
# Heuristics for cervical cancer labels
if any(k in vlow for k in ['cervical', 'cervix']) and any(k in vlow for k in ['cancer', 'carcinoma', 'scc', 'adenocarcinoma', 'tumor', 'tumour']):
return 1
if any(k in vlow for k in ['normal', 'healthy', 'control', 'benign', 'non-cancer', 'noncancer']):
return 0
# Explicit case/control labels
if vlow in {'case', 'patient', 'tumor', 'tumour'}:
return 1
if vlow in {'control', 'healthy', 'normal'}:
return 0
return None
def convert_age(value):
# Continuous: extract a numeric age if present
v = _after_colon(value)
if v is None:
return None
import re
matches = re.findall(r'\d+\.?\d*', v)
if not matches:
return None
try:
age_val = float(matches[0])
# Filter unreasonable ages
if 0 < age_val < 120:
return age_val
except Exception:
pass
return None
def convert_gender(value):
# Binary: female=0, male=1
v = _after_colon(value)
if v is None:
return None
vlow = v.lower()
if vlow in {'female', 'f', 'woman', 'women', 'girl'}:
return 0
if vlow in {'male', 'm', 'man', 'men', 'boy'}:
return 1
return None
# 3) Initial filtering and save metadata
is_trait_available = trait_row is not None
_ = 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 because trait_row is None)
# If at some point trait_row becomes available, the following scaffold shows how to proceed:
if trait_row is not None:
selected = geo_select_clinical_features(
clinical_df=clinical_data,
trait=trait,
trait_row=trait_row,
convert_trait=convert_trait,
age_row=age_row,
convert_age=convert_age,
gender_row=gender_row,
convert_gender=convert_gender
)
_ = preview_df(selected)
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
selected.to_csv(out_clinical_data_file, index=True)