|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Large_B-cell_Lymphoma" |
|
cohort = "GSE243973" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Large_B-cell_Lymphoma" |
|
in_cohort_dir = "../DATA/GEO/Large_B-cell_Lymphoma/GSE243973" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/GSE243973.csv" |
|
out_gene_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/gene_data/GSE243973.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Large_B-cell_Lymphoma/clinical_data/GSE243973.csv" |
|
json_path = "./output/preprocess/3/Large_B-cell_Lymphoma/cohort_info.json" |
|
|
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file) |
|
|
|
|
|
clinical_features = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("\nClinical Features and Sample Values:") |
|
print(json.dumps(clinical_features, indent=2)) |
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
trait_row = 0 |
|
|
|
age_row = None |
|
|
|
gender_row = None |
|
|
|
|
|
def convert_trait(x: str) -> int: |
|
"""Convert disease status to binary: 1 for LBCL, 0 for control""" |
|
if pd.isna(x): |
|
return None |
|
value = x.split(': ')[1].lower() if ': ' in x else x.lower() |
|
if 'large b-cell lymphoma' in value: |
|
return 1 |
|
elif 'healthy control' in value: |
|
return 0 |
|
return None |
|
|
|
def convert_age(x: str) -> float: |
|
"""Not used but defined for completeness""" |
|
return None |
|
|
|
def convert_gender(x: str) -> int: |
|
"""Not used but defined for completeness""" |
|
return None |
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=(trait_row is not None) |
|
) |
|
|
|
|
|
if trait_row is not None: |
|
clinical_features = 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 |
|
) |
|
|
|
|
|
preview = preview_df(clinical_features) |
|
print("Clinical features preview:", preview) |
|
|
|
|
|
clinical_features.to_csv(out_clinical_data_file) |
|
|
|
genetic_data = get_genetic_data(matrix_file) |
|
|
|
|
|
print("First 20 gene/probe IDs:") |
|
print(genetic_data.index[:20].tolist()) |
|
|
|
|
|
|
|
requires_gene_mapping = False |
|
|
|
genetic_data = normalize_gene_symbols_in_index(genetic_data) |
|
genetic_data.to_csv(out_gene_data_file) |
|
|
|
|
|
linked_data = geo_link_clinical_genetic_data(clinical_features, genetic_data) |
|
|
|
|
|
linked_data = handle_missing_values(df=linked_data, trait_col=trait) |
|
|
|
|
|
is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
|
|
|
note = "" |
|
if is_biased: |
|
note = "The trait distribution is severely biased." |
|
|
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=True, |
|
is_biased=is_biased, |
|
df=linked_data, |
|
note=note |
|
) |
|
|
|
|
|
if is_usable: |
|
linked_data.to_csv(out_data_file) |