|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "COVID-19" |
|
cohort = "GSE211378" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/COVID-19" |
|
in_cohort_dir = "../DATA/GEO/COVID-19/GSE211378" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/COVID-19/GSE211378.csv" |
|
out_gene_data_file = "./output/preprocess/3/COVID-19/gene_data/GSE211378.csv" |
|
out_clinical_data_file = "./output/preprocess/3/COVID-19/clinical_data/GSE211378.csv" |
|
json_path = "./output/preprocess/3/COVID-19/cohort_info.json" |
|
|
|
|
|
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path) |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("\nSample Characteristics:") |
|
print(json.dumps(unique_values_dict, indent=2)) |
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
trait_row = 12 |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(value): |
|
"""Convert COVID-19 status to binary (0: healthy, 1: COVID convalescent)""" |
|
if not value or ':' not in value: |
|
return None |
|
id_str = value.split(':')[1].strip() |
|
|
|
if '_' in id_str: |
|
return 1 |
|
else: |
|
return 0 |
|
|
|
def convert_age(value): |
|
"""Not needed as age data is not available""" |
|
return None |
|
|
|
def convert_gender(value): |
|
"""Not needed as gender data is not available""" |
|
return None |
|
|
|
|
|
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) |
|
|
|
|
|
if trait_row is not None: |
|
clinical_features = geo_select_clinical_features(clinical_data, trait, trait_row, convert_trait) |
|
print("Preview of extracted clinical features:") |
|
print(preview_df(clinical_features)) |
|
clinical_features.to_csv(out_clinical_data_file) |
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("First 20 gene/probe IDs:") |
|
print(list(genetic_data.index)[:20]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
requires_gene_mapping = False |
|
|
|
normalized_gene_data = normalize_gene_symbols_in_index(genetic_data) |
|
normalized_gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
clinical_data_loaded = pd.read_csv(out_clinical_data_file, index_col=0) |
|
linked_data = geo_link_clinical_genetic_data(clinical_data_loaded, normalized_gene_data) |
|
|
|
|
|
linked_data = handle_missing_values(linked_data, trait) |
|
|
|
|
|
trait_biased, filtered_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
|
|
|
note = "This dataset contains COVID-19 binary trait data (convalescent vs healthy) and gene expression data from whole blood samples. Age and gender data are not available." |
|
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=trait_biased, |
|
df=filtered_data, |
|
note=note |
|
) |
|
|
|
|
|
if is_usable: |
|
filtered_data.to_csv(out_data_file) |