diff --git a/CHANGELOG.md b/CHANGELOG.md index 893dab6..9a2e994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention. +## [0.2.0] - 2023-08-23 + ++ Add - `injection` schema ++ Update - docstrings, `linking_module` within each `activate` function + ## [0.1.8] - 2023-06-20 + Update - GitHub Actions workflows @@ -58,6 +63,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and + Add - `subject` schema + Add - `genotyping` schema +[0.2.0]: https://github.com/datajoint/element-animal/releases/tag/0.2.0 [0.1.8]: https://github.com/datajoint/element-animal/releases/tag/0.1.8 [0.1.7]: https://github.com/datajoint/element-animal/releases/tag/0.1.7 [0.1.6]: https://github.com/datajoint/element-animal/releases/tag/0.1.6 diff --git a/docs/src/concepts.md b/docs/src/concepts.md index 52f772e..38e00c9 100644 --- a/docs/src/concepts.md +++ b/docs/src/concepts.md @@ -56,6 +56,10 @@ There are three modules in `element-animal`: ![Surgery schema diagram](https://raw.githubusercontent.com/datajoint/element-animal/main/images/surgery_diagram.svg) +### Injection Diagram + +![Injection schema diagram](https://raw.githubusercontent.com/datajoint/element-animal/main/images/injection_diagram.svg) + ## `subject` schema ([API docs](https://datajoint.com/docs/elements/element-animal/api/element_animal/subject)) - Although not required, most choose to connect the `Session` table to a `Subject` table. @@ -93,3 +97,12 @@ There are three modules in `element-animal`: | Hemisphere | Brain region hemisphere | | ImplantationType | Type of implantation | | Implantation | Implantation of a device | + +### `injection` schema ([API docs](https://datajoint.com/docs/elements/element-animal/api/element_animal/injection)) + +| Table | Description | +| ------------------- | -------------------------------------------------------------- | +| VirusSerotype | Virus serotype | +| InjectionProtocol | Injection device protocol | +| VirusName | Full virus name | +| Injection | Information about the virus injection | diff --git a/element_animal/genotyping.py b/element_animal/genotyping.py index 1bb0820..45fabce 100644 --- a/element_animal/genotyping.py +++ b/element_animal/genotyping.py @@ -6,13 +6,14 @@ from . import subject schema = dj.schema() +_linking_module = None def activate( - genotyping_schema_name, - subject_schema_name=None, - create_schema=True, - create_tables=True, + genotyping_schema_name: str, + subject_schema_name: str = None, + create_schema: bool = True, + create_tables: bool = True, linking_module=None, ): """Activate this schema. @@ -26,8 +27,8 @@ def activate( database if it does not yet exist. create_tables (bool, optional): when True (default), create tables in the database if they do not yet exist. - linking_module (bool, optional): a module name or a module containing the - required dependencies to activate the `subject` element: + linking_module (str): A module name or a module containing the required + dependencies to activate the `genotyping` module. Dependencies: Upstream tables: @@ -56,7 +57,7 @@ def activate( genotyping_schema_name, create_schema=create_schema, create_tables=create_tables, - add_objects=linking_module.__dict__, + add_objects=_linking_module.__dict__, ) diff --git a/element_animal/injection.py b/element_animal/injection.py new file mode 100644 index 0000000..af9ab0f --- /dev/null +++ b/element_animal/injection.py @@ -0,0 +1,153 @@ +import importlib +import inspect + +import datajoint as dj + +from . import surgery + +schema = dj.Schema() +_linking_module = None + + +def activate( + injection_schema_name: str, + surgery_schema_name: str = None, + lab_schema_name: str = None, + *, + create_schema: bool = True, + create_tables: bool = True, + linking_module=None, +): + """Activate this schema. + + Args: + schema_name (str): schema name on the database server to activate the + `subject` element + create_schema (bool): when True (default), create schema in the + database if it does not yet exist. + create_tables (bool): when True (default), create tables in the + database if they do not yet exist. + linking_module (str): A module name or a module containing the required + dependencies to activate the `injection` module. + + Dependencies: + Upstream tables: + Device: table from `element-lab`. + """ + + if isinstance(linking_module, str): + linking_module = importlib.import_module(linking_module) + assert inspect.ismodule( + linking_module + ), "The argument 'linking_module' must be a module's name or a module" + + global _linking_module + _linking_module = linking_module + + surgery.activate( + surgery_schema_name, + create_schema=create_schema, + create_tables=create_tables, + linking_module=_linking_module, + ) + schema.activate( + injection_schema_name, + create_schema=create_schema, + create_tables=create_tables, + add_objects=_linking_module.__dict__, + ) + + +@schema +class VirusSerotype(dj.Lookup): + """Virus serotype. + + Attributes: + virus_serotype (str): Virus serotype. + """ + + definition = """ + virus_serotype: varchar(10) + """ + contents = zip( + [ + "AAV1", + "AAV2", + "AAV4", + "AAV5", + "AAV6", + "AAV7", + "AAV8", + "AAV9", + "AAV2/1", + "AAV2/5", + "AAV2/9", + "AAVrg", + "AAV/DJ", + "pAAV", + ] + ) + + +@schema +class InjectionProtocol(dj.Manual): + """Injection device protocol. + + Attributes: + protocol_id (int): Unique protocol ID. + lab.Device (foreign key): Primary key from lab.Device. + volume_per_pulse (float): Volume dispensed per microinjector pulse. + injection_rate (float): Rate at which injectate is dispensed. + interpulse_delay (float): Delay between injection pulses. Set to 0 if + injection is a single pulse. + """ + + definition = """ + protocol_id : int + --- + -> Device + volume_per_pulse : float + injection_rate : float + interpulse_delay : float + """ + + +@schema +class VirusName(dj.Manual): + """Full virus name. + + Attributes: + virus_name (str): Full virus name. Ex: AAV1.CAG.Flex.ArchT.GFP. + VirusSerotype (foreign key, nullable): Primary key from VirusSerotype. + """ + + definition = """ + virus_name: varchar(64) # Full virus name. Ex: AAV1.CAG.Flex.ArchT.GFP. + --- + -> [nullable] VirusSerotype + """ + + +@schema +class Injection(dj.Manual): + """Information about the virus injection. + + Attributes: + surgery.Implantation (foreign key): Primary key from + surgery.Implantation. + VirusName (foreign key): Primary key from VirusName. + InjectionProtocol (foreign key): Primary key from InjectionProtocol. + titer (str): Titer of injectate at the current injection site. + total_volume (float): Total volume injected at the current injection site. + injection_comment (str): Comments about the virus injection. + """ + + definition = """ + -> surgery.Implantation + -> VirusName + -> InjectionProtocol + --- + titer : varchar(16) + total_volume : float + injection_comment='' : varchar(1024) + """ diff --git a/element_animal/subject.py b/element_animal/subject.py index f706105..35034ee 100644 --- a/element_animal/subject.py +++ b/element_animal/subject.py @@ -11,7 +11,7 @@ def activate( *, create_schema: bool = True, create_tables: bool = True, - linking_module: bool = True, + linking_module=None, ): """Activate this schema. @@ -22,8 +22,8 @@ def activate( database if it does not yet exist. create_tables (bool): when True (default), create tables in the database if they do not yet exist. - linking_module (bool): a module name or a module containing the - required dependencies to activate the `subject` element: + linking_module (str): A module name or a module containing the required + dependencies to activate the `subject` module. Dependencies: Upstream tables: @@ -49,7 +49,7 @@ def activate( schema_name, create_schema=create_schema, create_tables=create_tables, - add_objects=linking_module.__dict__, + add_objects=_linking_module.__dict__, ) @@ -147,7 +147,7 @@ class Subject(dj.Manual): Attributes: subject ( varchar(8) ): Subject ID. - subject_nickname ( varchar(8) ): Subject nickname. + subject_nickname ( varchar(64) ): Subject nickname. sex (enum): 'M', 'F', or 'U'; Male, Female, or Unknown. subject_birth_date (date): Birth date of the subject. subject_description ( varchar(1024) ): Description of the subject. diff --git a/element_animal/surgery.py b/element_animal/surgery.py index d3e8ae2..27ad3d3 100644 --- a/element_animal/surgery.py +++ b/element_animal/surgery.py @@ -16,7 +16,7 @@ def activate( *, create_schema: bool = True, create_tables: bool = True, - linking_module: bool = True, + linking_module=None, ): """Activate this schema. @@ -27,8 +27,8 @@ def activate( database if it does not yet exist. create_tables (bool): when True (default), create tables in the database if they do not yet exist. - linking_module (bool): a module name or a module containing the - required dependencies to activate the `subject` element: + linking_module (str): A module name or a module containing the required + dependencies to activate the `surgery` module. Dependencies: Upstream tables: @@ -54,7 +54,7 @@ def activate( surgery_schema_name, create_schema=create_schema, create_tables=create_tables, - add_objects=linking_module.__dict__, + add_objects=_linking_module.__dict__, ) @@ -132,21 +132,15 @@ class Implantation(dj.Manual): """Implantation of a device Attributes: - Session (foreign key): Session primary key - location_id (int): ID of of brain location - ap ( float ): In mm, Anterior/posterior; Anterior Positive - ap_reference (projected attribute): Coordinate reference - ml ( float ): In mm, medial axis; Right Positive - ml_reference (projected attribute): Coordinate reference - dv ( float ): In mm, dorso-ventral axis. Ventral negative - dv_reference (projected attribute): Coordinate reference - theta ( float, nullable ): Elevation in degrees. - Rotation about ml-axis [0, 180] relative to z-axis - phi ( float, nullable ): Azimuth in degrees. - Rotations about dv-axis [0, 360] relative to x-axis - beta ( float, nullable ): Rotation about shank in degrees. - Rotation about the shank [-180, 180]. Clockwise is increasing. - 0 is the probe-front facing anterior + Subject (foreign key): Subject primary key. + implant_date (datetime): Date and time of implantation surgery. + ImplantationType (foreign key): ImplantationType primary key. + region_acronym ( projected attribute, varchar(32) ): Brain region + shorthand from BrainRegion. + hemisphere ( projected attribute, varchar(8) ): Brain region hemisphere + from Hemisphere. + user ( projected attribute, varchar(32) ): User who performed the surgery. + implant_comment ( varchar(1024), optional ): Comments about the implant. """ definition = """ @@ -161,6 +155,22 @@ class Implantation(dj.Manual): """ class Coordinate(dj.Part): + """Coordinates of the Implantation Device. + + Attributes: + Implantation (foreign key): Primary keys from Implantation. + ap ( float ): In mm, Anterior/posterior; Anterior Positive. + ap_reference (projected attribute): Coordinate reference. + ml ( float ): In mm, medial axis; Right Positive. + ml_reference (projected attribute): Coordinate reference. + dv ( float ): In mm, dorso-ventral axis. Ventral negative. + dv_reference (projected attribute): Coordinate reference. + theta ( float, nullable ): Elevation in degrees. Rotation about ml-axis [0, 180] relative to z-axis. + phi ( float, nullable ): Azimuth in degrees. Rotations about dv-axis [0, 360] relative to x-axis. + beta ( float, nullable ): Rotation about shank in degrees. Rotation + about the shank [-180, 180]. Clockwise is increasing. 0 is the probe-front facing anterior. + """ + definition = """ -> master --- diff --git a/element_animal/version.py b/element_animal/version.py index 10bc5c5..8667345 100644 --- a/element_animal/version.py +++ b/element_animal/version.py @@ -1,2 +1,2 @@ """Package metadata.""" -__version__ = "0.1.8" +__version__ = "0.2.0" diff --git a/images/injection_diagram.svg b/images/injection_diagram.svg new file mode 100644 index 0000000..2ea9c25 --- /dev/null +++ b/images/injection_diagram.svg @@ -0,0 +1,187 @@ + + +%3 + + +19 + +19 + + +surgery.Implantation + + +surgery.Implantation + + + + +19->surgery.Implantation + + + +23 + +23 + + +surgery.Implantation.Coordinate + + +surgery.Implantation.Coordinate + + + + +23->surgery.Implantation.Coordinate + + + +18 + +18 + + +18->surgery.Implantation + + + +21 + +21 + + +21->surgery.Implantation.Coordinate + + + +22 + +22 + + +22->surgery.Implantation.Coordinate + + + +lab.Device + + +lab.Device + + + + +injection.InjectionProtocol + + +injection.InjectionProtocol + + + + +lab.Device->injection.InjectionProtocol + + + +injection.VirusName + + +injection.VirusName + + + + +injection.Injection + + +injection.Injection + + + + +injection.VirusName->injection.Injection + + + +surgery.Implantation->surgery.Implantation.Coordinate + + + +surgery.Implantation->injection.Injection + + + +surgery.Hemisphere + + +surgery.Hemisphere + + + + +surgery.Hemisphere->19 + + + +surgery.BrainRegion + + +surgery.BrainRegion + + + + +surgery.BrainRegion->18 + + + +injection.VirusSerotype + + +injection.VirusSerotype + + + + +injection.VirusSerotype->injection.VirusName + + + +injection.InjectionProtocol->injection.Injection + + + +surgery.ImplantationType + + +surgery.ImplantationType + + + + +surgery.ImplantationType->surgery.Implantation + + + +surgery.CoordinateReference + + +surgery.CoordinateReference + + + + +surgery.CoordinateReference->23 + + + +surgery.CoordinateReference->21 + + + +surgery.CoordinateReference->22 + + + + \ No newline at end of file