Liu-Hy's picture
Add files using upload-large-folder tool
56598a1 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Bladder_Cancer"
cohort = "GSE203149"
# Input paths
in_trait_dir = "../DATA/GEO/Bladder_Cancer"
in_cohort_dir = "../DATA/GEO/Bladder_Cancer/GSE203149"
# Output paths
out_data_file = "./output/z1/preprocess/Bladder_Cancer/GSE203149.csv"
out_gene_data_file = "./output/z1/preprocess/Bladder_Cancer/gene_data/GSE203149.csv"
out_clinical_data_file = "./output/z1/preprocess/Bladder_Cancer/clinical_data/GSE203149.csv"
json_path = "./output/z1/preprocess/Bladder_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
import re
import pandas as pd
# 1) Gene Expression Data Availability
# Background clearly indicates full transcriptome microarray (Clariom S) => gene expression available.
is_gene_available = True
# 2) Variable Availability and Converters
# From the sample characteristics, only one field exists:
# {0: ['disease: Muscle-invasive bladder cancer']}
# This is constant across samples, so trait is not usable (treated as not available).
trait_row = None
# No age or gender information is present.
age_row = None
gender_row = None
def _after_colon(x):
if x is None or (isinstance(x, float) and pd.isna(x)):
return None
s = str(x)
parts = s.split(":", 1)
return parts[1].strip() if len(parts) == 2 else s.strip()
def convert_trait(x):
# Not used since trait_row is None.
v = _after_colon(x)
if v is None or v.lower() in {"", "na", "n/a", "none", "unknown"}:
return None
vl = v.lower()
# Heuristic mapping for case/control if ever needed
if "bladder" in vl:
return 1
if "control" in vl or "normal" in vl or "healthy" in vl:
return 0
return None
def convert_age(x):
# Not used since age_row is None.
v = _after_colon(x)
if v is None:
return None
# Extract first integer/float number (e.g., "65 years", "age: 58")
m = re.search(r"[-+]?\d*\.?\d+", v)
if m:
try:
return float(m.group(0))
except Exception:
return None
return None
def convert_gender(x):
# Not used since gender_row is None.
v = _after_colon(x)
if v is None:
return None
vl = v.lower()
if vl in {"male", "m"} or vl.startswith("male"):
return 1
if vl in {"female", "f"} or vl.startswith("female"):
return 0
return None
# 3) Save metadata (initial filtering)
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 clinical data were available, we would extract using geo_select_clinical_features and save.