Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 88aeb23

Browse files
authored
Merge pull request #106 from kabilar/main
Update demo notebooks
2 parents 4d38edd + 3d0b582 commit 88aeb23

File tree

8 files changed

+386
-521
lines changed

8 files changed

+386
-521
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ ENV DJ_HOST fakeservices.datajoint.io
2424
ENV DJ_USER root
2525
ENV DJ_PASS simple
2626

27-
ENV DJ_PUBLIC_S3_MOUNT_PATH /workspaces/workflow-calcium-imaging/example_data
27+
ENV DJ_PUBLIC_S3_MOUNT_PATH /workspaces/workflow-calcium-imaging/example_data
28+
ENV IMAGING_ROOT_DATA_DIR /workspaces/workflow-calcium-imaging/example_data
29+
ENV DATABASE_PREFIX neuro_

notebooks/demo_prepare.ipynb

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"### Demo Preparation Notebook\n",
9+
"\n",
10+
"**Please Note**: This notebook and demo are NOT intended to be used as learning materials. To gain\n",
11+
"a thorough understanding of the DataJoint workflow for calcium imaging, please\n",
12+
"see the [`tutorial`](./tutorial.ipynb) notebook."
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"import datajoint as dj\n",
22+
"import datetime\n",
23+
"import numpy as np\n",
24+
"from workflow_calcium_imaging.pipeline import subject, session, scan, imaging, Equipment\n",
25+
"from element_calcium_imaging import imaging_report\n",
26+
"import suite2p"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"metadata": {},
33+
"outputs": [],
34+
"source": [
35+
"subject.Subject.insert1(\n",
36+
" dict(\n",
37+
" subject='subject1',\n",
38+
" subject_birth_date='2023-01-01',\n",
39+
" sex='U',\n",
40+
" )\n",
41+
")"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"Equipment.insert1(dict(scanner=\"Mesoscope\"))"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"session_key = dict(subject='subject1', \n",
60+
" session_datetime=datetime.datetime.now())\n",
61+
"\n",
62+
"session.Session.insert1(session_key)\n",
63+
"\n",
64+
"session.SessionDirectory.insert1(\n",
65+
" dict(\n",
66+
" session_key, \n",
67+
" session_dir='subject1/session1'\n",
68+
" )\n",
69+
")"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"scan.Scan.insert1(\n",
79+
" dict(\n",
80+
" session_key,\n",
81+
" scan_id=0,\n",
82+
" scanner=\"Mesoscope\",\n",
83+
" acq_software='ScanImage',\n",
84+
" )\n",
85+
")"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"populate_settings = {\"display_progress\": True}\n",
95+
"\n",
96+
"scan.ScanInfo.populate(**populate_settings)"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"metadata": {},
103+
"outputs": [],
104+
"source": [
105+
"suite2p_params = suite2p.default_ops()\n",
106+
"suite2p_params['nonrigid']=False\n",
107+
"\n",
108+
"imaging.ProcessingParamSet.insert_new_params(\n",
109+
" processing_method=\"suite2p\",\n",
110+
" paramset_idx=0,\n",
111+
" params=suite2p_params,\n",
112+
" paramset_desc='Default parameter set for suite2p'\n",
113+
")"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"imaging.ProcessingTask.insert1(\n",
123+
" dict(\n",
124+
" session_key,\n",
125+
" scan_id=0,\n",
126+
" paramset_idx=0,\n",
127+
" task_mode='load', # load or trigger\n",
128+
" processing_output_dir='subject1/session1/suite2p',\n",
129+
" )\n",
130+
")\n",
131+
"\n",
132+
"imaging.Processing.populate(**populate_settings)"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {},
139+
"outputs": [],
140+
"source": [
141+
"imaging.Curation.insert1(\n",
142+
" dict(\n",
143+
" session_key,\n",
144+
" scan_id=0,\n",
145+
" paramset_idx=0,\n",
146+
" curation_id=0,\n",
147+
" curation_time=datetime.datetime.now(),\n",
148+
" curation_output_dir='subject1/session1/suite2p',\n",
149+
" manual_curation=False,\n",
150+
" )\n",
151+
")\n",
152+
"\n",
153+
"imaging.MotionCorrection.populate(**populate_settings)\n",
154+
"imaging.Segmentation.populate(**populate_settings)\n",
155+
"imaging.Fluorescence.populate(**populate_settings)\n",
156+
"imaging.Activity.populate(**populate_settings)\n",
157+
"imaging_report.ScanLevelReport.populate(**populate_settings)\n",
158+
"imaging_report.TraceReport.populate(**populate_settings)"
159+
]
160+
}
161+
],
162+
"metadata": {
163+
"kernelspec": {
164+
"display_name": "Python 3",
165+
"language": "python",
166+
"name": "python3"
167+
},
168+
"language_info": {
169+
"codemirror_mode": {
170+
"name": "ipython",
171+
"version": 3
172+
},
173+
"file_extension": ".py",
174+
"mimetype": "text/x-python",
175+
"name": "python",
176+
"nbconvert_exporter": "python",
177+
"pygments_lexer": "ipython3",
178+
"version": "3.7.16"
179+
},
180+
"orig_nbformat": 4
181+
},
182+
"nbformat": 4,
183+
"nbformat_minor": 2
184+
}

notebooks/demo_run.ipynb

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"# DataJoint Workflow for Calcium Imaging\n",
9+
"\n",
10+
"+ This notebook demonstrates using the open-source DataJoint Element to build a workflow for\n",
11+
"calcium imaging.\n",
12+
"+ For a detailed tutorial, please see the [tutorial notebook](./tutorial.ipynb)."
13+
]
14+
},
15+
{
16+
"attachments": {},
17+
"cell_type": "markdown",
18+
"metadata": {},
19+
"source": [
20+
"<img src =../images/rawscans.gif title=\"value\" width=\"200\" height=\"200\"/>\n",
21+
"<img src =../images/motioncorrectedscans.gif width=\"200\" height=\"200\"/>\n",
22+
"<img src =../images/cellsegmentation.png width=\"200\" height=\"200\"/>\n",
23+
"<img src =../images/calciumtraces.png width=\"200\" height=\"200\"/> \n",
24+
"\n",
25+
"Left to right: Raw scans, Motion corrected scans, Cell segmentations, Calcium events"
26+
]
27+
},
28+
{
29+
"attachments": {},
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"### Import dependencies"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"metadata": {
40+
"tags": [
41+
"hide-input"
42+
]
43+
},
44+
"outputs": [],
45+
"source": [
46+
"import datajoint as dj\n",
47+
"from workflow_calcium_imaging.pipeline import subject, session, scan, imaging\n",
48+
"from element_calcium_imaging.plotting.widget import main"
49+
]
50+
},
51+
{
52+
"attachments": {},
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"### View workflow"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"dj.Diagram(subject.Subject) + dj.Diagram(session.Session) + dj.Diagram(scan) + dj.Diagram(imaging)"
66+
]
67+
},
68+
{
69+
"attachments": {},
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": [
73+
"### Insert an entry in a manual table by calling the `insert()` method\n",
74+
"\n",
75+
"```python\n",
76+
"subject.Subject.insert1(\n",
77+
" dict(subject='subject1',\n",
78+
" subject_birth_date='2023-01-01',\n",
79+
" sex='U'\n",
80+
" )\n",
81+
")\n",
82+
"```"
83+
]
84+
},
85+
{
86+
"attachments": {},
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"### Automatically process data with the `populate()` method\n",
91+
"\n",
92+
"+ Once data is inserted into manual tables, the `populate()` function automatically runs the ingestion and processing routines. \n",
93+
"\n",
94+
"+ For example, to run Suite2p processing in the `Processing` table:\n",
95+
"\n",
96+
" ```python\n",
97+
" imaging.Processing.populate()\n",
98+
" ```"
99+
]
100+
},
101+
{
102+
"attachments": {},
103+
"cell_type": "markdown",
104+
"metadata": {},
105+
"source": [
106+
"### Visualize processed data"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"main(imaging)"
116+
]
117+
},
118+
{
119+
"attachments": {},
120+
"cell_type": "markdown",
121+
"metadata": {},
122+
"source": [
123+
"For an in-depth tutorial please see the [tutorial notebook](./tutorial.ipynb)."
124+
]
125+
}
126+
],
127+
"metadata": {
128+
"kernelspec": {
129+
"display_name": "Python 3",
130+
"language": "python",
131+
"name": "python3"
132+
},
133+
"language_info": {
134+
"codemirror_mode": {
135+
"name": "ipython",
136+
"version": 3
137+
},
138+
"file_extension": ".py",
139+
"mimetype": "text/x-python",
140+
"name": "python",
141+
"nbconvert_exporter": "python",
142+
"pygments_lexer": "ipython3",
143+
"version": "3.9.12"
144+
},
145+
"orig_nbformat": 4,
146+
"vscode": {
147+
"interpreter": {
148+
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
149+
}
150+
}
151+
},
152+
"nbformat": 4,
153+
"nbformat_minor": 2
154+
}

0 commit comments

Comments
 (0)