From c63310dc23d763cdd4c6f9a1b31bda2da387d2c0 Mon Sep 17 00:00:00 2001
From: Harry Carey <harry.carey95@gmail.com>
Date: Tue, 23 May 2023 18:25:49 +0200
Subject: [PATCH] added testOOP as a temporary file while building the PyNutil
 class

---
 PyNutil/dream_workflow.py           |  6 +++---
 PyNutil/main.py                     | 14 ++++++++++----
 PyNutil/metadata/config.json        |  7 ++++---
 PyNutil/metadata/metadata_loader.py |  2 +-
 testOOP.py                          | 16 ++++++++++++++++
 5 files changed, 34 insertions(+), 11 deletions(-)
 create mode 100644 testOOP.py

diff --git a/PyNutil/dream_workflow.py b/PyNutil/dream_workflow.py
index 205896b..eedf748 100644
--- a/PyNutil/dream_workflow.py
+++ b/PyNutil/dream_workflow.py
@@ -22,12 +22,12 @@ quantifier.load_mask(mask_path=r"blablabla/")
 quantifier.load_custom_regions(custom_region_json=r"blablabla/")
 # run coordinate extraction
 # ideally extract coordinates per section and whole brain
-points = quantifier.get_coordinates()
+quantifier.get_coordinates()
 
 quantifier.save_coordinates()
 
-objects = quantifier.get_objects()
+quantifier.get_objects()
 
-loads = quantifier.get_loads()
+quantifier.get_loads()
 
 quantifier.save_segmentation_atlas_overlays()
diff --git a/PyNutil/main.py b/PyNutil/main.py
index 0626eeb..71fd2b3 100644
--- a/PyNutil/main.py
+++ b/PyNutil/main.py
@@ -1,5 +1,5 @@
 from .metadata import metadata_loader
-from read_and_write import readAtlasVolume
+from .read_and_write import readAtlasVolume
 
 
 class PyNutil:
@@ -13,7 +13,7 @@ class PyNutil:
         self.config, self.metadata_path = metadata_loader.load_config()
         if atlas not in self.config["annotation_volumes"]:
             raise ValueError(
-                f"Atlas {atlas} not found in config file\n valid atlases are {self.config['annotation_volumes'].keys()}"
+                f"Atlas {atlas} not found in config file, valid atlases are: \n{' , '.join(list(self.config['annotation_volumes'].keys()))}"
             )
         self.segmentation_folder = segmentation_folder
         self.json_file = json_file
@@ -23,5 +23,11 @@ class PyNutil:
 
     def build_quantifier(self):
         # do all the expensive computations
-        atlas_path = self.config["annotation_volumes"][self.atlas]["volume"]
-        self.atlas_volume = readAtlasVolume(self.atlas)
+        atlas_root_path = self.config["annotation_volume_directory"]
+        current_atlas_path = self.config["annotation_volumes"][self.atlas]["volume"]
+        print("loading atlas volume")
+        self.atlas_volume = readAtlasVolume(atlas_root_path + current_atlas_path)
+
+    def get_coordinates(self):
+        if not hasattr(self, "atlas_volume"):
+            raise ValueError("Please run build_quantifier before running get_coordinates")
diff --git a/PyNutil/metadata/config.json b/PyNutil/metadata/config.json
index 1ec2ba3..5cab460 100644
--- a/PyNutil/metadata/config.json
+++ b/PyNutil/metadata/config.json
@@ -22,6 +22,7 @@
     "WHS_Atlas_Rat_Brain_v4":{
         "labels":"WHS_v4_colours.csv",
         "volume":"None"
-    },
-    "annotation_volume_directory":"annotation_volumes/"
-}}
\ No newline at end of file
+    }
+},
+"annotation_volume_directory":"PyNutil/metadata/annotation_volumes/"
+}
\ No newline at end of file
diff --git a/PyNutil/metadata/metadata_loader.py b/PyNutil/metadata/metadata_loader.py
index ec27363..ae3361f 100644
--- a/PyNutil/metadata/metadata_loader.py
+++ b/PyNutil/metadata/metadata_loader.py
@@ -11,7 +11,7 @@ def load_config() -> dict:
     :rtype: dict
     """
     # returns a path to the config file assuming that it is in the same directory as this script
-    path = str(Path(__file__).parent.parent.absolute()) + "/config.json"
+    path = str(Path(__file__).parent.parent.absolute()) + "/metadata/config.json"
     # open the config file
     with open(path, "r") as f:
         # load the config file
diff --git a/testOOP.py b/testOOP.py
new file mode 100644
index 0000000..2c6c0e3
--- /dev/null
+++ b/testOOP.py
@@ -0,0 +1,16 @@
+from PyNutil import PyNutil
+
+
+
+
+
+pnt = PyNutil(
+    'test',
+    'test',
+    [0,0,0],
+    "allen2017")
+
+pnt.build_quantifier()
+
+pnt.get_coordinates()
+
-- 
GitLab