Project flow¶
LaminDB allows tracking data lineage on the entire project level.
Here, we walk through exemplified app uploads, pipelines & notebooks following Schmidt et al., 2022.
A CRISPR screen reading out a phenotypic endpoint on T cells is paired with scRNA-seq to generate insights into IFN-γ production.
These insights get linked back to the original data through the steps taken in the project to provide context for interpretation & future decision making.
More specifically: Why should I care about data flow?
Data flow tracks data sources & transformations to trace biological insights, verify experimental outcomes, meet regulatory standards, increase the robustness of research and optimize the feedback loop of team-wide learning iterations.
While tracking data flow is easier when it’s governed by deterministic pipelines, it becomes hard when it’s governed by interactive human-driven analyses.
LaminDB interfaces workflow mangers for the former and embraces the latter.
# !pip install 'lamindb[jupyter,bionty,aws]'
!lamin init --storage ./mydata
Show code cell output
→ connected lamindb: testuser1/mydata
Import lamindb:
import lamindb as ln
from IPython.display import Image, display
→ connected lamindb: testuser1/mydata
Steps¶
In the following, we walk through exemplified steps covering different types of transforms (Transform
).
Note
The full notebooks are in this repository.
App upload of phenotypic data ¶
Register data through app upload from wetlab by testuser1
:
# This function mimics the upload of artifacts via the UI
# In reality, you simply drag and drop files into the UI
def mock_upload_crispra_result_app():
ln.setup.login("testuser1")
transform = ln.Transform(name="Upload GWS CRISPRa result", type="upload")
ln.track(transform=transform)
output_path = ln.core.datasets.schmidt22_crispra_gws_IFNG(ln.settings.storage.root)
output_file = ln.Artifact(
output_path, description="Raw data of schmidt22 crispra GWS"
)
output_file.save()
mock_upload_crispra_result_app()
Show code cell output
→ created Transform('rT1g4ctSZmCW0000') & created Run('2024-09-02 13:30:49.676860+00:00')
Hit identification in notebook ¶
Access, transform & register data in drylab by testuser2
in notebook hit-identification.
Show code cell content
# the following mimics the integrated analysis notebook
# In reality, you would execute inside the notebook
import nbproject_test
from pathlib import Path
cwd = Path.cwd()
nbproject_test.execute_notebooks(cwd / "project-flow-scripts/hit-identification.ipynb", write=True)
Executing notebooks in /home/runner/work/lamin-usecases/lamin-usecases/docs/project-flow-scripts/hit-identification.ipynb
Scheduled: ['hit-identification']
hit-identification
✓ (4.288s)
Total time: 4.290s
Inspect data flow:
artifact = ln.Artifact.get(description="hits from schmidt22 crispra GWS")
artifact.view_lineage()
Sequencer upload ¶
Upload files from sequencer via script chromium_10x_upload.py:
!python project-flow-scripts/chromium_10x_upload.py
Show code cell output
→ connected lamindb: testuser1/mydata
→ created Transform('qCJPkOuZAi9q0000') & created Run('2024-09-02 13:30:56.610773+00:00')
scRNA-seq bioinformatics pipeline ¶
Process uploaded files using a script or workflow manager: Pipelines – workflow managers and obtain 3 output files in a directory filtered_feature_bc_matrix/
:
!python project-flow-scripts/cellranger.py
Show code cell output
→ connected lamindb: testuser1/mydata
→ created Transform('PMCTweBFUhiW0000') & created Run('2024-09-02 13:30:59.254990+00:00')
! this creates one artifact per file in the directory - consider ln.Artifact(dir_path) to get one artifact for the entire directory
!python project-flow-scripts/postprocess_cellranger.py
Show code cell output
→ connected lamindb: testuser1/mydata
→ created Transform('YqmbO6oMXjRj0000') & created Run('2024-09-02 13:31:01.142866+00:00')
Inspect data flow:
output_file = ln.Artifact.get(description="perturbseq counts")
output_file.view_lineage()
Integrate scRNA-seq & phenotypic data ¶
Integrate data in notebook integrated-analysis.
Show code cell content
# the following mimics the integrated analysis notebook
# In reality, you would execute inside the notebook
nbproject_test.execute_notebooks(cwd / "project-flow-scripts/integrated-analysis.ipynb", write=True)
Executing notebooks in /home/runner/work/lamin-usecases/lamin-usecases/docs/project-flow-scripts/integrated-analysis.ipynb
Scheduled: ['integrated-analysis']
integrated-analysis
✓ (4.309s)
Total time: 4.310s
Review results¶
Let’s load one of the plots:
# track the current notebook as transform
ln.context.uid = "1LCd8kco9lZU0000"
ln.context.track()
→ notebook imports: ipython==8.27.0 lamindb==0.76.3 nbproject_test==0.5.1
→ created Transform('1LCd8kco9lZU0000') & created Run('2024-09-02 13:31:07.180076+00:00')
artifact = ln.Artifact.get(key__contains="figures/matrixplot")
artifact.cache()
Show code cell output
PosixUPath('/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/zJVMsDgbLivXlNdX0000.png')
display(Image(filename=artifact.path))
We see that the image artifact is tracked as an input of the current notebook. The input is highlighted, the notebook follows at the bottom:
artifact.view_lineage()
Alternatively, we can also look at the sequence of transforms:
transform = ln.Transform.search("Project flow").first()
transform.predecessors.df()
uid | version | is_latest | name | key | description | type | source_code | hash | reference | reference_type | _source_code_artifact_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||
6 | lB3IyPLQSmvt0000 | None | True | Perform single cell analysis, integrate with C... | integrated-analysis.ipynb | None | notebook | None | None | None | None | None | 2 | 2024-09-02 13:31:05.387850+00:00 |
transform.view_lineage()
Understand runs¶
We tracked pipeline and notebook runs through track()
, which stores a Transform
and a Run
record within a global context.
Artifact
objects are the inputs and outputs of runs.
What if I don’t want a global context?
Sometimes, we don’t want to create a global run context but manually pass a run when creating an artifact:
run = ln.Run(transform=transform)
ln.Artifact(filepath, run=run)
When does an artifact appear as a run input?
When accessing an artifact via cache()
, load()
or open()
, two things happen:
The current run gets added to
artifact.input_of
The transform of that artifact gets added as a parent of the current transform
You can then switch off auto-tracking of run inputs if you set ln.settings.track_run_inputs = False
: Can I disable tracking run inputs?
You can also track run inputs on a case by case basis via is_run_input=True
, e.g., here:
artifact.load(is_run_input=True)
Query by provenance¶
We can query or search for the notebook that created the artifact:
transform = ln.Transform.search("GWS CRIPSRa analysis").first()
And then find all the artifacts created by that notebook:
ln.Artifact.filter(transform=transform).df()
uid | version | is_latest | description | key | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||||
2 | KLC1QGomdjUPO0OF0000 | None | True | hits from schmidt22 crispra GWS | None | .parquet | dataset | 18368 | ky0pLx8o9oFJnn0niPUHog | None | None | md5 | DataFrame | 1 | True | 1 | 2 | 2 | 2 | 2024-09-02 13:30:54.266165+00:00 |
Which transform ingested a given artifact?
artifact = ln.Artifact.filter().first()
artifact.transform
Transform(uid='rT1g4ctSZmCW0000', is_latest=True, name='Upload GWS CRISPRa result', type='upload', created_by_id=1, updated_at='2024-09-02 13:30:49 UTC')
And which user?
artifact.created_by
User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at='2024-09-02 13:30:56 UTC')
Which transforms were created by a given user?
users = ln.User.lookup()
ln.Transform.filter(created_by=users.testuser1).df()
uid | version | is_latest | name | key | description | type | source_code | hash | reference | reference_type | _source_code_artifact_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||
1 | rT1g4ctSZmCW0000 | None | True | Upload GWS CRISPRa result | None | None | upload | None | None | None | None | NaN | 1 | 2024-09-02 13:30:49.675138+00:00 |
3 | qCJPkOuZAi9q0000 | None | True | chromium_10x_upload.py | chromium_10x_upload.py | None | script | None | None | None | None | 5.0 | 1 | 2024-09-02 13:30:56.989971+00:00 |
7 | 1LCd8kco9lZU0000 | None | True | Project flow | project-flow.ipynb | None | notebook | None | None | None | None | NaN | 1 | 2024-09-02 13:31:07.176044+00:00 |
Which notebooks were created by a given user?
ln.Transform.filter(created_by=users.testuser1, type="notebook").df()
uid | version | is_latest | name | key | description | type | source_code | hash | reference | reference_type | _source_code_artifact_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||
7 | 1LCd8kco9lZU0000 | None | True | Project flow | project-flow.ipynb | None | notebook | None | None | None | None | None | 1 | 2024-09-02 13:31:07.176044+00:00 |
We can also view all recent additions to the entire database:
ln.view()
Show code cell output
Artifact
uid | version | is_latest | description | key | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||||
12 | zJVMsDgbLivXlNdX0000 | None | True | None | figures/matrixplot_fig2_score-wgs-hits-per-clu... | .png | None | 28814 | Uqpe3rI2qCa6KHvUIxadLw | None | None | md5 | None | 1 | True | 1 | 6 | 6 | 2 | 2024-09-02 13:31:06.230905+00:00 |
11 | EIhO772HJsyEhVQP0000 | None | True | None | figures/umap_fig1_score-wgs-hits.png | .png | None | 118999 | JMFvnvCcQzIdtXM8Y12MKg | None | None | md5 | None | 1 | True | 1 | 6 | 6 | 2 | 2024-09-02 13:31:06.034159+00:00 |
10 | RjNugqu7oygxzwNf0000 | None | True | perturbseq counts | schmidt22_perturbseq.h5ad | .h5ad | None | 20659936 | la7EvqEUMDlug9-rpw-udA | None | None | md5 | AnnData | 1 | False | 1 | 5 | 5 | 2 | 2024-09-02 13:31:02.153176+00:00 |
9 | acEHGliob5AXl4Te0000 | None | True | None | perturbseq/filtered_feature_bc_matrix/barcodes... | .tsv.gz | None | 6 | 7jd2n1fZjH_SeKW4qE9aeQ | None | None | md5 | None | 1 | False | 1 | 4 | 4 | 2 | 2024-09-02 13:30:59.636009+00:00 |
8 | cVIMUaslw0lGhGvz0000 | None | True | None | perturbseq/filtered_feature_bc_matrix/matrix.m... | .mtx.gz | None | 6 | yX6YsbnnkEeG5cegAd1ijA | None | None | md5 | None | 1 | False | 1 | 4 | 4 | 2 | 2024-09-02 13:30:59.635522+00:00 |
7 | tY7uEQyZuU2rKEOd0000 | None | True | None | perturbseq/filtered_feature_bc_matrix/features... | .tsv.gz | None | 6 | GIG05_Mx5G4IItT6p4YHew | None | None | md5 | None | 1 | False | 1 | 4 | 4 | 2 | 2024-09-02 13:30:59.634741+00:00 |
4 | 6zgAAH9QKhPVMLNh0000 | None | True | None | fastq/perturbseq_R2_001.fastq.gz | .fastq.gz | None | 6 | 0uhCMHJOZjViCEA2TStNRQ | None | None | md5 | None | 1 | False | 1 | 3 | 3 | 1 | 2024-09-02 13:30:56.972676+00:00 |
Run
uid | started_at | finished_at | is_consecutive | reference | reference_type | transform_id | report_id | environment_id | parent_id | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||
1 | 14qjMHAJpXkhALcQu7vv | 2024-09-02 13:30:49.677007+00:00 | NaT | True | None | None | 1 | None | NaN | None | 1 |
2 | 9cNuURBW4to5fVhcKfnt | 2024-09-02 13:30:53.854043+00:00 | NaT | True | None | None | 2 | None | NaN | None | 2 |
3 | kpNfoR5BDLigO4oN0BF5 | 2024-09-02 13:30:56.610916+00:00 | 2024-09-02 13:30:56.988376+00:00 | True | None | None | 3 | None | 6.0 | None | 1 |
4 | oxZkif2W2sGGzMs6u314 | 2024-09-02 13:30:59.255132+00:00 | NaT | None | None | None | 4 | None | NaN | None | 2 |
5 | nSHEDm2cdsWGy73rVexm | 2024-09-02 13:31:01.143015+00:00 | NaT | None | None | None | 5 | None | NaN | None | 2 |
6 | Z6jQblJgYMYTk1L3oBDO | 2024-09-02 13:31:05.391323+00:00 | NaT | True | None | None | 6 | None | NaN | None | 2 |
7 | vLCwJRFpYOjDQoCUyDeE | 2024-09-02 13:31:07.180211+00:00 | NaT | True | None | None | 7 | None | NaN | None | 1 |
Storage
uid | root | description | type | region | instance_uid | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|
id | |||||||||
1 | M7rbrks4JcWZ | /home/runner/work/lamin-usecases/lamin-usecase... | None | local | None | 54ZGqgkROOFf | None | 1 | 2024-09-02 13:30:47.693719+00:00 |
Transform
uid | version | is_latest | name | key | description | type | source_code | hash | reference | reference_type | _source_code_artifact_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||
7 | 1LCd8kco9lZU0000 | None | True | Project flow | project-flow.ipynb | None | notebook | None | None | None | None | NaN | 1 | 2024-09-02 13:31:07.176044+00:00 |
6 | lB3IyPLQSmvt0000 | None | True | Perform single cell analysis, integrate with C... | integrated-analysis.ipynb | None | notebook | None | None | None | None | NaN | 2 | 2024-09-02 13:31:05.387850+00:00 |
5 | YqmbO6oMXjRj0000 | None | True | postprocess_cellranger.py | postprocess_cellranger.py | None | script | None | None | None | None | NaN | 2 | 2024-09-02 13:31:01.140876+00:00 |
4 | PMCTweBFUhiW0000 | 7.2.0 | True | Cell Ranger | None | None | pipeline | None | None | https://www.10xgenomics.com/support/software/c... | None | NaN | 2 | 2024-09-02 13:30:59.253121+00:00 |
3 | qCJPkOuZAi9q0000 | None | True | chromium_10x_upload.py | chromium_10x_upload.py | None | script | None | None | None | None | 5.0 | 1 | 2024-09-02 13:30:56.989971+00:00 |
2 | T0T28btuB0PG0000 | None | True | GWS CRIPSRa analysis | hit-identification.ipynb | None | notebook | None | None | None | None | NaN | 2 | 2024-09-02 13:30:53.850728+00:00 |
1 | rT1g4ctSZmCW0000 | None | True | Upload GWS CRISPRa result | None | None | upload | None | None | None | None | NaN | 1 | 2024-09-02 13:30:49.675138+00:00 |
User
uid | handle | name | updated_at | |
---|---|---|---|---|
id | ||||
2 | bKeW4T6E | testuser2 | Test User2 | 2024-09-02 13:30:59.246701+00:00 |
1 | DzTjkKse | testuser1 | Test User1 | 2024-09-02 13:30:56.501880+00:00 |
Show code cell content
!lamin login testuser1
!lamin delete --force mydata
!rm -r ./mydata
✓ logged in with email testuser1@lamin.ai (uid: DzTjkKse)
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.10.14/x64/bin/lamin", line 8, in <module>
sys.exit(main())
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/rich_click/rich_command.py", line 367, in __call__
return super().__call__(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/rich_click/rich_command.py", line 152, in main
rv = self.invoke(ctx)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamin_cli/__main__.py", line 179, in delete
return delete(instance, force=force)
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamindb_setup/_delete.py", line 98, in delete
n_objects = check_storage_is_empty(
File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamindb_setup/core/upath.py", line 776, in check_storage_is_empty
raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage /home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb contains 5 objects ('_is_initialized' ignored) - delete them prior to deleting the instance