Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
139fde8
expanding lab tables \for other NWB fields
CBroz1 Nov 22, 2021
9c56224
Expand Lab for NWB export
CBroz1 Nov 29, 2021
112005e
Keyword, no default
CBroz1 Nov 30, 2021
b9804c3
Pub, no default
CBroz1 Nov 30, 2021
5987d93
revise assembly of info for nwb export
CBroz1 Dec 1, 2021
b600a4a
fix pop empty nwb entries
CBroz1 Dec 1, 2021
340458a
edit docker users for buildtest
CBroz1 Dec 2, 2021
1d41a74
Add docstrings
CBroz1 Dec 6, 2021
a3c0b75
quickfix: dependency import
CBroz1 Dec 6, 2021
63bd5f5
pynwb version issues w/h5py resolved recently
CBroz1 Dec 17, 2021
ea71fd5
Update author dj neuro -> dj
CBroz1 Dec 21, 2021
733d303
Update element_lab/__init__.py
CBroz1 Dec 23, 2021
ea67c24
Remove outdated `make_nwb` function
CBroz1 Dec 23, 2021
5c4ac32
PEP8 full word funcs. rm equip table
CBroz1 Dec 28, 2021
e16b95b
Deleting tempy.py notes file
CBroz1 Dec 28, 2021
e21b6c6
Sourcecode as master/part table 1
CBroz1 Jan 10, 2022
5c3a076
Sourcecode as master/part table 2
CBroz1 Jan 10, 2022
ab18244
Remove notes from nwb.py
CBroz1 Jan 10, 2022
4581206
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
00cf2a2
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
be59780
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
c6591ed
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
405f491
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
8f3e8fb
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
263448e
Update element_lab/export/nwb.py
CBroz1 Jan 11, 2022
955cef4
Remove lab.Project slices, virus, etc.; PEP8 linting
CBroz1 Jan 11, 2022
506c191
Apply Dimitri's suggestions, additional edit forthcoming
CBroz1 Jan 12, 2022
465084d
refactor nwb.py: only execute funcs if relevant input
CBroz1 Jan 12, 2022
a762b26
Apply Dimitri's suggestions, additional edit forthcoming
CBroz1 Jan 13, 2022
fc47e6c
Bump version, changelog notes. Add time_zone to export.
CBroz1 Jan 13, 2022
0d393cd
pass Nones intead of empty strings. These do not populate the NWBFile
bendichter Jan 26, 2022
33288d5
Pin pynwb to 1.4.0
CBroz1 Jan 27, 2022
8c0373c
Merge from bendichter: pass Nones instead of empty strings
CBroz1 Jan 28, 2022
debe13b
@Kabilar's code review: PEP8
CBroz1 Jan 28, 2022
2c2240f
dj.part->dj.manual: keyw, pubs, sourcecode
CBroz1 Jan 28, 2022
6ddd420
Update version history URL list
CBroz1 Jan 28, 2022
fe227e1
Prefix former part tables: add Project in name
CBroz1 Jan 28, 2022
2dccbdc
Apply suggestions from @kabilar's code review
CBroz1 Jan 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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.1.0b1] - 2022-01-28
### Added
+ Added functions to generate dictionaries for NWB export.


## [0.1.0b0] - 2021-05-07
### Added
+ First beta release
Expand All @@ -12,6 +17,6 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
+ Added GitHub Action release process
+ Added `lab` schema


[0.1.0b1]: https://github.com/datajoint/element-lab/compare/0.1.0b0...0.1.0b1
[0.1.0b0]: https://github.com/datajoint/element-lab/compare/0.1.0a1...0.1.0b0
[0.1.0a1]: https://github.com/datajoint/element-lab/releases/tag/0.1.0a1
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ ARG PKG_NAME
ARG PKG_VERSION

FROM datajoint/${IMAGE}:py${PY_VER}-${DISTRO}
COPY --chown=dja:anaconda ./requirements.txt ./setup.py \
COPY --chown=anaconda:anaconda ./requirements.txt ./setup.py \
/main/
COPY --chown=dja:anaconda ./${PKG_NAME} /main/${PKG_NAME}
COPY --chown=anaconda:anaconda ./${PKG_NAME} /main/${PKG_NAME}
RUN \
cd /main && \
pip install . && \
Expand Down
4 changes: 0 additions & 4 deletions element_lab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
__author__ = "DataJoint NEURO"
__date__ = "December 15, 2020"
__version__ = "0.0.1"
__all__ = ['__author__', '__version__', '__date__']
1 change: 1 addition & 0 deletions element_lab/export/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .nwb import elementlab_nwb_dict
84 changes: 84 additions & 0 deletions element_lab/export/nwb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from element_lab import lab


def lab_to_nwb_dict(lab_key):
"""
Generate a dictionary containing all relevant lab and institution info
:param lab_key: Key specifying one entry in element_lab.lab.Lab
:return: dictionary with NWB parameters
"""
lab_info = (lab.Lab & lab_key).fetch1()
return dict(
institution=lab_info.get('institution'),
lab=lab_info.get('lab_name'),
)


def project_to_nwb_dict(project_key):
"""
Generate a dictionary object containing relevant project information
(e.g., experimental description, related publications, etc.).
:param project_key: Key specifying one entry in element_lab.lab.Project
:return: dictionary with NWB parameters
"""
project_info = (lab.Project & project_key).fetch1()
return dict(
experiment_description=project_info.get('project_description'),
keywords=(lab.ProjectKeywords() & project_key
).fetch('keyword').tolist() or None,
related_publications=(lab.ProjectPublication() & project_key
).fetch('publication').tolist() or None
)


def protocol_to_nwb_dict(protocol_key):
"""
Generate a dictionary object containing all protocol title and notes.
:param protocol_key: Key specifying one entry in element_lab.lab.Protocol
:return: dictionary with NWB parameters
"""
protocol_info = (lab.Protocol & protocol_key).fetch1()
return dict(
protocol=protocol_info.get('protocol'),
notes=protocol_info.get('protocol_description')
)


def element_lab_to_nwb_dict(lab_key=None, project_key=None, protocol_key=None):
"""
Generate a dictionary object containing all relevant lab information used
when generating an NWB file at the session level.
All parameters optional, but should only specify one of respective type
Use: mynwbfile = pynwb.NWBFile(identifier="your identifier",
session_description="your description",
session_start_time=session_datetime,
**element_lab_to_nwb_dict(
lab_key=key1,
project_key=key2,
protocol_key=key3))

:param lab_key: Key specifying one entry in element_lab.lab.Lab
:param project_key: Key specifying one entry in element_lab.lab.Project
:param protocol_key: Key specifying one entry in element_lab.lab.Protocol
:return: dictionary with NWB parameters
"""
# Validate input
assert any([lab_key, project_key, protocol_key]), 'Must specify one key.'
assert lab_key is None or len(lab.Lab & lab_key) == 1, \
'Multiple labs error! The lab_key should specify only one lab.'
assert project_key is None or len(lab.Project & project_key) == 1, \
'Multiple projects error! The project_key should specify only one '\
'project.'
assert protocol_key is None or len(lab.Protocol & protocol_key) == 1, \
'Multiple protocols error! The protocol_key should specify only one '\
'protocol.'

element_info = dict()
if lab_key:
element_info.update(lab_to_nwb_dict(lab_key))
if project_key:
element_info.update(project_to_nwb_dict(project_key))
if protocol_key:
element_info.update(protocol_to_nwb_dict(protocol_key))

return element_info
54 changes: 42 additions & 12 deletions element_lab/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
def activate(schema_name, create_schema=True, create_tables=True):
"""
activate(schema_name, create_schema=True, create_tables=True)
:param schema_name: schema name on the database server to activate the `lab` element
:param create_schema: when True (default), create schema in the database if it does not yet exist.
:param create_tables: when True (default), create tables in the database if they do not yet exist.
:param schema_name: schema name on the database server to activate the
`lab` element
:param create_schema: when True (default), create schema in the
database if it does not yet exist.
:param create_tables: when True (default), create tables in the
database if they do not yet exist.
"""
schema.activate(schema_name, create_schema=create_schema, create_tables=create_tables)
schema.activate(schema_name, create_schema=create_schema,
create_tables=create_tables)


@schema
class Lab(dj.Lookup):
definition = """
lab : varchar(24) # Abbreviated lab name
lab : varchar(24) # Abbreviated lab name
---
lab_name : varchar(255) # full lab name
institution : varchar(255)
address : varchar(255)
time_zone : varchar(64)
time_zone : varchar(64) # 'UTC±X' format for NWB export
"""


Expand Down Expand Up @@ -77,7 +81,7 @@ class Protocol(dj.Lookup):
protocol : varchar(16)
---
-> ProtocolType
protocol_description='' : varchar(255)
protocol_description='' : varchar(255)
"""


Expand All @@ -86,7 +90,33 @@ class Project(dj.Lookup):
definition = """
project : varchar(32)
---
project_description='' : varchar(1024)
project_description='' : varchar(1024)
"""


class ProjectKeywords(dj.Manual):
definition = """
# Project keywords, exported dataset meta info
-> Project
keyword: varchar(32)
"""


class ProjectPublication(dj.Manual):
definition = """
# Project's resulting publications
-> Project
publication: varchar(256)
"""


class ProjectSourceCode(dj.Manual):
definition = """
# URL to source code for replication
-> Project
repository_url : varchar(256)
---
repository_name='' : varchar(32)
"""


Expand All @@ -102,9 +132,9 @@ class ProjectUser(dj.Manual):
class Source(dj.Lookup):
definition = """
# source or supplier of animals
source : varchar(32) # abbreviated source name
source : varchar(32) # abbreviated source name
---
source_name : varchar(255)
contact_details='' : varchar(255)
source_description='' : varchar(255)
source_name : varchar(255)
contact_details='' : varchar(255)
source_description='' : varchar(255)
"""
2 changes: 1 addition & 1 deletion element_lab/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Package metadata."""
__version__ = '0.1.0b0'
__version__ = '0.1.0b1'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
datajoint>=0.13.0
pynwb==1.4.0