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 = "GSE146114"
# Input paths
in_trait_dir = "../DATA/GEO/Cervical_Cancer"
in_cohort_dir = "../DATA/GEO/Cervical_Cancer/GSE146114"
# Output paths
out_data_file = "./output/z2/preprocess/Cervical_Cancer/GSE146114.csv"
out_gene_data_file = "./output/z2/preprocess/Cervical_Cancer/gene_data/GSE146114.csv"
out_clinical_data_file = "./output/z2/preprocess/Cervical_Cancer/clinical_data/GSE146114.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
import re
import pandas as pd
# 1) Gene Expression Data Availability
# Background indicates Illumina WG-6 v3 / HT-12 v4 mRNA expression arrays.
is_gene_available = True
# 2) Variable Availability and Data Type Conversion
# Based on the sample characteristics:
# - Trait (Cervical_Cancer): All samples are cervical tumor patients (case-only). No variability -> not available.
# - Age: Not present.
# - Gender: Cervical cancer patients are female; gender not explicitly listed and effectively constant -> not available.
trait_row = None
age_row = None
gender_row = None
# Conversion functions (defined for interface consistency; may not be used due to unavailability)
def convert_trait(x):
# Map to binary case/control if ever needed:
# 1 = Cervical cancer case; 0 = control/normal.
if x is None:
return None
try:
val = str(x)
# Extract value after colon if present
if ':' in val:
val = val.split(':', 1)[1].strip()
low = val.lower()
if any(k in low for k in ['cervical', 'cervix', 'tumor', 'carcinoma']):
return 1
if any(k in low for k in ['normal', 'healthy', 'control', 'adjacent normal']):
return 0
return None
except Exception:
return None
def convert_age(x):
# Return age in years as float if a number is present; otherwise None
if x is None:
return None
try:
val = str(x)
if ':' in val:
val = val.split(':', 1)[1].strip()
m = re.search(r'(\d+(?:\.\d+)?)', val)
return float(m.group(1)) if m else None
except Exception:
return None
def convert_gender(x):
# Female -> 0, Male -> 1
if x is None:
return None
try:
val = str(x)
if ':' in val:
val = val.split(':', 1)[1].strip()
low = val.lower()
if low in ['f', 'female', 'woman', 'women']:
return 0
if low in ['m', 'male', 'man', 'men']:
return 1
return None
except Exception:
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 trait_row is not None:
selected_clinical_df = 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
)
clinical_preview = preview_df(selected_clinical_df)
print("Clinical preview:", clinical_preview)
# Save clinical data
selected_clinical_df.to_csv(out_clinical_data_file, index=True)