Skip to content

Commit

Permalink
Merge pull request #43 from kushalbakshi/main
Browse files Browse the repository at this point in the history
Add injection schema
  • Loading branch information
Thinh Nguyen authored Oct 3, 2023
2 parents fe24d09 + 400c93a commit a609e49
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docs/src/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
15 changes: 8 additions & 7 deletions element_animal/genotyping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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__,
)


Expand Down
153 changes: 153 additions & 0 deletions element_animal/injection.py
Original file line number Diff line number Diff line change
@@ -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)
"""
10 changes: 5 additions & 5 deletions element_animal/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def activate(
*,
create_schema: bool = True,
create_tables: bool = True,
linking_module: bool = True,
linking_module=None,
):
"""Activate this schema.
Expand All @@ -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:
Expand All @@ -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__,
)


Expand Down Expand Up @@ -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.
Expand Down
48 changes: 29 additions & 19 deletions element_animal/surgery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def activate(
*,
create_schema: bool = True,
create_tables: bool = True,
linking_module: bool = True,
linking_module=None,
):
"""Activate this schema.
Expand All @@ -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:
Expand All @@ -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__,
)


Expand Down Expand Up @@ -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 = """
Expand All @@ -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
---
Expand Down
2 changes: 1 addition & 1 deletion element_animal/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Package metadata."""
__version__ = "0.1.8"
__version__ = "0.2.0"
Loading

0 comments on commit a609e49

Please sign in to comment.