|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cardiovascular_Disease" |
|
cohort = "GSE262419" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" |
|
in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE262419" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE262419.csv" |
|
out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE262419.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE262419.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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trait_row = 1 |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(value: str) -> int: |
|
"""Convert treatment info to binary cardiovascular disease trait. |
|
0: No cardiovascular effect |
|
1: Shows cardiovascular effect (altered beat frequency, QT prolongation, or asystole) |
|
""" |
|
if pd.isna(value): |
|
return None |
|
|
|
|
|
if ":" in value: |
|
value = value.split(":")[1].strip() |
|
|
|
|
|
|
|
|
|
|
|
cardiotoxic_indicators = [ |
|
"prednisone", |
|
"estradiol", |
|
"isoniazid", |
|
"flutamide", |
|
"_10_" |
|
] |
|
|
|
value = value.lower() |
|
return 1 if any(indicator.lower() in value for indicator in cardiotoxic_indicators) else 0 |
|
|
|
def convert_age(value: str) -> float: |
|
return None |
|
|
|
def convert_gender(value: str) -> 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=True) |
|
|
|
|
|
|
|
clinical_df = geo_select_clinical_features(clinical_data, |
|
trait=trait, |
|
trait_row=trait_row, |
|
convert_trait=convert_trait) |
|
|
|
|
|
preview_result = preview_df(clinical_df) |
|
print("Preview of clinical data:") |
|
print(preview_result) |
|
|
|
|
|
clinical_df.to_csv(out_clinical_data_file) |
|
|
|
with gzip.open(matrix_file, 'rt') as file: |
|
for i, line in enumerate(file): |
|
if i < 50: |
|
print(f"Line {i}: {line.strip()}") |
|
else: |
|
break |
|
|
|
|
|
genetic_df = pd.read_csv(matrix_file, compression='gzip', sep='\t', skiprows=80, index_col=0) |
|
|
|
|
|
print("\nFirst 20 gene/probe IDs:") |
|
print(list(genetic_df.index)[:20]) |
|
|
|
|
|
print(f"\nShape of genetic data: {genetic_df.shape}") |