aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-01-17 10:54:02 +0300
committerBonfaceKilz2023-01-20 15:02:46 +0300
commit234f110e1e492a2701a6cf8cd2b45aa2341c8041 (patch)
tree1ef4d6aa3b465f20991bb13b1c548b1dff958b5e
parentad84b1a142d928b3457f36c9eae3c087f13f067d (diff)
downloadgenenetwork2-234f110e1e492a2701a6cf8cd2b45aa2341c8041.tar.gz
Update demo to dump entire dataset for BXDPublish
* scripts/sampledata.py: Import os and sys. <__name__>: Add demo to dump "BXDPublish" dataset.
-rw-r--r--scripts/sampledata.py32
1 files changed, 23 insertions, 9 deletions
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!")