|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Height" |
|
cohort = "GSE101709" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Height" |
|
in_cohort_dir = "../DATA/GEO/Height/GSE101709" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Height/GSE101709.csv" |
|
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE101709.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE101709.csv" |
|
json_path = "./output/preprocess/3/Height/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 = None |
|
age_row = 1 |
|
gender_row = None |
|
|
|
|
|
def convert_age(x): |
|
if not isinstance(x, str): |
|
return None |
|
value = x.split(": ")[-1].strip() |
|
if value == "Young": |
|
return 25.5 |
|
elif value in ["Older", "Frail"]: |
|
return 70 |
|
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 |
|
) |
|
|
|
|
|
|
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("First 20 row IDs:") |
|
print(genetic_data.index[:20].tolist()) |
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file_path) |
|
|
|
|
|
print("Column names:") |
|
print(gene_metadata.columns.tolist()) |
|
print("\nPreview of first few rows:") |
|
print(json.dumps(preview_df(gene_metadata), indent=2)) |
|
|
|
prob_col = 'ID' |
|
gene_col = 'Symbol' |
|
|
|
|
|
mapping_data = get_gene_mapping(gene_metadata, prob_col, gene_col) |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_data, mapping_data) |
|
|
|
|
|
print("Preview of mapped gene expression data:") |
|
print(f"Number of genes: {len(gene_data)}") |
|
print("First few gene symbols:") |
|
print(gene_data.index[:10].tolist()) |
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
clinical_features = pd.DataFrame() |
|
|
|
|
|
linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data) |
|
|
|
|
|
linked_data = handle_missing_values(linked_data, trait) |
|
|
|
|
|
is_biased = True |
|
|
|
|
|
note = "Dataset lacks height measurements, though gene expression data is available" |
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False, |
|
is_biased=is_biased, |
|
df=linked_data, |
|
note=note |
|
) |
|
|
|
|
|
if is_usable: |
|
os.makedirs(os.path.dirname(out_data_file), exist_ok=True) |
|
linked_data.to_csv(out_data_file) |