Liu-Hy's picture
Add files using upload-large-folder tool
3088323 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Cardiovascular_Disease"
cohort = "GSE228783"
# Input paths
in_trait_dir = "../DATA/GEO/Cardiovascular_Disease"
in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE228783"
# Output paths
out_data_file = "./output/preprocess/1/Cardiovascular_Disease/GSE228783.csv"
out_gene_data_file = "./output/preprocess/1/Cardiovascular_Disease/gene_data/GSE228783.csv"
out_clinical_data_file = "./output/preprocess/1/Cardiovascular_Disease/clinical_data/GSE228783.csv"
json_path = "./output/preprocess/1/Cardiovascular_Disease/cohort_info.json"
# STEP1
from tools.preprocess import *
# 1. Attempt to identify the paths to the SOFT file and the matrix file
try:
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
except AssertionError:
print("[WARNING] Could not find the expected '.soft' or '.matrix' files in the directory.")
soft_file, matrix_file = None, None
if soft_file is None or matrix_file is None:
print("[ERROR] Required GEO files are missing. Please check file names in the cohort directory.")
else:
# 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("\nSample Characteristics Dictionary:")
print(sample_characteristics_dict)
# Step 1: Decide if the dataset likely contains gene expression data
is_gene_available = True # Based on the transcriptome context
# Step 2: Determine variable availability
trait_row = None # No cardiovascular disease info in sample characteristics
age_row = None # No age info found
gender_row = None # No gender info found
# Prepare conversion functions. Though not used when the rows are None, we must define them.
def convert_trait(x: str) -> Optional[float]:
# Not used in this dataset
return None
def convert_age(x: str) -> Optional[float]:
# Not used in this dataset
return None
def convert_gender(x: str) -> Optional[int]:
# Not used in this dataset
return None
# Step 3: Conduct initial filtering and save to metadata
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
)
# Step 4: Since trait_row is None, skip clinical feature extraction