From 234f110e1e492a2701a6cf8cd2b45aa2341c8041 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Tue, 17 Jan 2023 10:54:02 +0300 Subject: Update demo to dump entire dataset for BXDPublish * scripts/sampledata.py: Import os and sys. <__name__>: Add demo to dump "BXDPublish" dataset. --- scripts/sampledata.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/sampledata.py b/scripts/sampledata.py index 411ec2b4..4777b6f9 100644 --- a/scripts/sampledata.py +++ b/scripts/sampledata.py @@ -1,4 +1,6 @@ import json +import os +import sys # Required Evils! from flask import g @@ -61,12 +63,24 @@ def fetch_all_traits(species, group, type_, dataset): yield result.get('name') -# Dump all traits from a given dataset -for trait in fetch_all_traits( - species="mouse", - group="BXD", - type_="Phenotypes", - dataset="BXDPublish", -): - print(json.dumps(dump_sample_data("BXDPublish", trait))) - break # Just do this once! +if __name__ == "__main__": + DATASET_NAME = "BXDPublish" + + if not os.path.isdir( + BASE_DIR:=os.path.join(sys.argv[1],DATASET_NAME) + ): + os.makedirs(BASE_DIR) + + print("\n\n======================================\n\n") + print(f"Dumping Sampledata into {sys.argv[1]}:\n\n") + for trait in fetch_all_traits( + species="mouse", + group="BXD", + type_="Phenotypes", + dataset="BXDPublish", + ): + # Dump all sample data into a given directory: + print(f"\033[FDumping: {DATASET_NAME}/{trait}") + with open(os.path.join(BASE_DIR, f"{trait}.json"), "w") as f: + json.dump(dump_sample_data(DATASET_NAME, trait), f) + print("DONE DUMPING!") -- cgit v1.2.3