|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cardiovascular_Disease" |
|
cohort = "GSE190042" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" |
|
in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE190042" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE190042.csv" |
|
out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE190042.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE190042.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 = None |
|
|
|
|
|
age_row = 2 |
|
|
|
|
|
gender_row = 1 |
|
|
|
|
|
def convert_trait(x): |
|
return None |
|
|
|
def convert_age(x): |
|
try: |
|
|
|
age = float(x.split(': ')[1]) |
|
return age |
|
except: |
|
return None |
|
|
|
def convert_gender(x): |
|
try: |
|
gender = x.split(': ')[1].strip().upper() |
|
if gender == 'F': |
|
return 0 |
|
elif gender == 'M': |
|
return 1 |
|
return None |
|
except: |
|
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=False |
|
) |
|
|
|
|
|
|
|
genetic_df = get_genetic_data(matrix_file) |
|
|
|
|
|
print("DataFrame shape:", genetic_df.shape) |
|
print("\nFirst few rows and columns:") |
|
print(genetic_df.head().iloc[:, :5]) |
|
|
|
|
|
print("\nRaw file preview:") |
|
with gzip.open(matrix_file, 'rt') as f: |
|
for i, line in enumerate(f): |
|
if i > 30 and i < 35: |
|
print(line.strip()) |
|
|
|
|
|
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)) |
|
|
|
mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol') |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_df, mapping_df) |
|
|
|
|
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False |
|
) |