|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Breast_Cancer" |
|
cohort = "GSE283522" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Breast_Cancer" |
|
in_cohort_dir = "../DATA/GEO/Breast_Cancer/GSE283522" |
|
|
|
|
|
out_data_file = "./output/preprocess/1/Breast_Cancer/GSE283522.csv" |
|
out_gene_data_file = "./output/preprocess/1/Breast_Cancer/gene_data/GSE283522.csv" |
|
out_clinical_data_file = "./output/preprocess/1/Breast_Cancer/clinical_data/GSE283522.csv" |
|
json_path = "./output/preprocess/1/Breast_Cancer/cohort_info.json" |
|
|
|
|
|
from tools.preprocess import * |
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
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) |
|
|
|
|
|
sample_characteristics_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("Sample Characteristics Dictionary:") |
|
print(sample_characteristics_dict) |
|
import re |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
|
|
trait_row = 1 |
|
|
|
|
|
age_row = 2 |
|
|
|
|
|
gender_row = 5 |
|
|
|
|
|
def convert_trait(value: str): |
|
""" |
|
Convert the value in row 1 into a binary indicator for breast cancer. |
|
'isolate: breast cancer patient' -> 1 |
|
'isolate: healthy individual' -> 0 |
|
otherwise -> None |
|
""" |
|
parts = value.split(':', 1) |
|
if len(parts) < 2: |
|
return None |
|
v = parts[1].strip().lower() |
|
if 'breast cancer patient' in v: |
|
return 1 |
|
elif 'healthy individual' in v: |
|
return 0 |
|
else: |
|
return None |
|
|
|
def convert_age(value: str): |
|
""" |
|
Convert the value in row 2 into a continuous numeric age. |
|
Example: 'age: 55 - 59' -> 57 (midpoint), 'age: not applicable' -> None |
|
""" |
|
parts = value.split(':', 1) |
|
if len(parts) < 2: |
|
return None |
|
range_str = parts[1].strip().lower() |
|
if 'not applicable' in range_str: |
|
return None |
|
|
|
digits = re.findall(r'\d+', range_str) |
|
if len(digits) == 2: |
|
low, high = map(int, digits) |
|
return (low + high) / 2 |
|
elif len(digits) == 1: |
|
return int(digits[0]) |
|
else: |
|
return None |
|
|
|
def convert_gender(value: str): |
|
""" |
|
Convert the value in row 5 into a binary indicator for gender. |
|
'Sex: female' -> 0 |
|
'Sex: male' -> 1 |
|
otherwise -> None |
|
""" |
|
parts = value.split(':', 1) |
|
if len(parts) < 2: |
|
return None |
|
v = parts[1].strip().lower() |
|
if v == 'female': |
|
return 0 |
|
elif v == 'male': |
|
return 1 |
|
else: |
|
return None |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
if trait_row is not None: |
|
selected_clinical = geo_select_clinical_features( |
|
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 = preview_df(selected_clinical) |
|
print("Preview of selected clinical features:", preview) |
|
|
|
|
|
selected_clinical.to_csv(out_clinical_data_file, index=False) |
|
|
|
|
|
gene_data = get_genetic_data(matrix_file) |
|
|
|
|
|
print(gene_data.index[:20]) |