|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cardiovascular_Disease" |
|
cohort = "GSE276839" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" |
|
in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE276839" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE276839.csv" |
|
out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE276839.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE276839.csv" |
|
json_path = "./output/preprocess/3/Cardiovascular_Disease/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) |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("=== Dataset Background Information ===") |
|
print(background_info) |
|
print("\n=== Sample Characteristics ===") |
|
print(json.dumps(unique_values_dict, indent=2)) |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
age_row = 0 |
|
|
|
gender_row = None |
|
|
|
|
|
trait_row = None |
|
|
|
|
|
def convert_age(value: str) -> Optional[float]: |
|
"""Convert age group to numeric values representing approximate age in years""" |
|
if not isinstance(value, str): |
|
return None |
|
value = value.lower().split(': ')[-1] |
|
if 'neonate' in value: |
|
return 0.0 |
|
elif 'infant' in value: |
|
return 0.5 |
|
elif 'toddler' in value or 'pre school' in value: |
|
return 2.5 |
|
elif 'school age' in value: |
|
return 8.0 |
|
elif 'adolescent' in value or 'young adult' in value: |
|
return 16.0 |
|
return None |
|
|
|
|
|
def convert_trait(value: str) -> Optional[int]: |
|
return None |
|
|
|
def convert_gender(value: str) -> Optional[int]: |
|
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) |
|
) |
|
|
|
|
|
|
|
genetic_df = get_genetic_data(matrix_file) |
|
|
|
|
|
print("First 20 gene/probe IDs:") |
|
print(list(genetic_df.index)[:20]) |
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Column names and preview of gene annotation data:") |
|
print(preview_df(gene_metadata)) |
|
|
|
gene_metadata['Gene'] = gene_metadata['SPOT_ID.1'].apply(extract_human_gene_symbols) |
|
|
|
|
|
mapping_df = get_gene_mapping(gene_metadata, 'ID', 'Gene') |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_df, mapping_df) |
|
|
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
|
|
if not os.path.exists(os.path.dirname(out_gene_data_file)): |
|
os.makedirs(os.path.dirname(out_gene_data_file)) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
is_usable = validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False |
|
) |