Liu-Hy's picture
Add files using upload-large-folder tool
24fe0da verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Endometriosis"
cohort = "GSE138297"
# Input paths
in_trait_dir = "../DATA/GEO/Endometriosis"
in_cohort_dir = "../DATA/GEO/Endometriosis/GSE138297"
# Output paths
out_data_file = "./output/preprocess/1/Endometriosis/GSE138297.csv"
out_gene_data_file = "./output/preprocess/1/Endometriosis/gene_data/GSE138297.csv"
out_clinical_data_file = "./output/preprocess/1/Endometriosis/clinical_data/GSE138297.csv"
json_path = "./output/preprocess/1/Endometriosis/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. Determine if gene expression data is available
# From the background info, it's a microarray dataset for gene expression.
is_gene_available = True
# 2. Determine the availability and the corresponding row indices for trait, age, and gender
# The trait is "Endometriosis", but the dictionary does not contain any row with that info.
# => trait_row is None
trait_row = None
# The 'age' data is found in row 3 with multiple distinct values.
age_row = 3
# The 'gender' data is found in row 1 with values "sex (female=1, male=0): 1" and "sex (female=1, male=0): 0".
gender_row = 1
# 2.2 Define the data type conversion functions
def convert_trait(value: str) -> Optional[int]:
# Since trait data is not actually available in this dataset, we return None
return None
def convert_age(value: str) -> Optional[float]:
# Example of input: "age (yrs): 49"
# We'll parse out the part after the colon and convert to float
try:
val = value.split(":", 1)[1].strip()
return float(val)
except:
return None
def convert_gender(value: str) -> Optional[int]:
# Example of input: "sex (female=1, male=0): 1"
# The part after the colon is '1' (meaning female in the original dataset),
# but per instructions we want female -> 0, male -> 1.
try:
val = value.split(":", 1)[1].strip()
if val == "1":
return 0 # female
elif val == "0":
return 1 # male
else:
return None
except:
return None
# 3. Save metadata with initial filtering
# Trait data is not available, so we expect the dataset to be filtered out.
is_trait_available = (trait_row is not None)
is_dataset_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. If trait_row is not None, extract and preview clinical features.
# Since trait_row is None, we SKIP this step.