From 4e5e3d3c01974a196bc56a97cd9326dd64385ce0 Mon Sep 17 00:00:00 2001 From: Kabilar Gunalan Date: Tue, 8 Aug 2023 14:54:44 -0500 Subject: [PATCH] Revert "Remove pipeline script" This reverts commit bada53eaf47cd8c2250d764f1638921a349f9f2c. --- notebooks/tutorial_pipeline.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 notebooks/tutorial_pipeline.py diff --git a/notebooks/tutorial_pipeline.py b/notebooks/tutorial_pipeline.py new file mode 100644 index 00000000..a31c076b --- /dev/null +++ b/notebooks/tutorial_pipeline.py @@ -0,0 +1,48 @@ +import datajoint as dj +from element_animal import subject +from element_animal.subject import Subject +from element_calcium_imaging import imaging, scan, imaging_report, db_prefix, plotting +from element_lab import lab +from element_lab.lab import Lab, Location, Project, Protocol, Source, User +from element_lab.lab import Device as Equipment +from element_lab.lab import User as Experimenter +from element_session import session_with_datetime as session +from element_session.session_with_datetime import Session +import element_interface +import pathlib + + +# Declare functions for retrieving data +def get_imaging_root_data_dir(): + """Retrieve imaging root data directory.""" + imaging_root_dirs = dj.config.get("custom", {}).get("imaging_root_data_dir", None) + if not imaging_root_dirs: + return None + elif isinstance(imaging_root_dirs, (str, pathlib.Path)): + return [imaging_root_dirs] + elif isinstance(imaging_root_dirs, list): + return imaging_root_dirs + else: + raise TypeError("`imaging_root_data_dir` must be a string, pathlib, or list") + + +def get_image_files(scan_key, file_type: str): + """Retrieve the list of absolute paths associated with a given Scan.""" + # Folder structure: root / subject / session / .tif or .sbx or .nd2 + session_dir = element_interface.utils.find_full_path( + get_imaging_root_data_dir(), + (session.SessionDirectory & scan_key).fetch1("session_dir"), + ) + + filepaths = [fp.as_posix() for fp in session_dir.glob(file_type)] + + if not filepaths: + raise FileNotFoundError(f"No {file_type} file found in {session_dir}") + return filepaths + + +# Activate schemas +lab.activate(db_prefix + "lab") +subject.activate(db_prefix + "subject", linking_module=__name__) +session.activate(db_prefix + "session", linking_module=__name__) +imaging.activate(db_prefix + "imaging", db_prefix + "scan", linking_module=__name__)