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.
Setup¶
Init a test instance:
!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)
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
💡 saved: Transform(uid='jXwLQU398hmS', name='Upload GWS CRISPRa result', type='upload', updated_at=2024-05-20 08:36:41 UTC, created_by_id=1)
💡 saved: Run(uid='HwuqAjkLmgQXFsC6YOn7', transform_id=1, created_by_id=1)
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
✓ (3.672s)
Total time: 3.673s
Inspect data flow:
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
💡 saved: Transform(version='1', uid='qCJPkOuZAi9q5zKv', name='chromium_10x_upload.py', key='chromium_10x_upload.py', type='script', updated_at=2024-05-20 08:36:48 UTC, created_by_id=1)
💡 saved: Run(uid='RtUwu8FCDnX15iJ90I6c', transform_id=3, created_by_id=1)
✅ saved transform.source_code: Artifact(version='1', updated_at=2024-05-20 08:36:48 UTC, uid='L1MDIGzjftThAyjCUZCe', suffix='.py', description='Source of transform qCJPkOuZAi9q5zKv', size=474, hash='o-QoKgEZGxbk5oBtcAKoWw', hash_type='md5', visibility=0, key_is_virtual=True, created_by_id=1, storage_id=1)
✅ saved run.environment: Artifact(updated_at=2024-05-20 08:36:48 UTC, uid='NCske8n2bSHYfGBaJhoE', suffix='.txt', description='requirements.txt', size=3344, hash='DX4AZkvBPK-hfIpUcdAU0Q', hash_type='md5', visibility=0, key_is_virtual=True, created_by_id=1, storage_id=1)
scRNA-seq bioinformatics pipeline ¶
Process uploaded files using a script or workflow manager: Pipelines 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
💡 saved: Transform(version='7.2.0', uid='qY9aAILlTJMW', name='Cell Ranger', type='pipeline', reference='https://www.10xgenomics.com/support/software/cell-ranger/7.2', updated_at=2024-05-20 08:36:50 UTC, created_by_id=2)
💡 saved: Run(uid='0mNsLnH49vTmK6fGdRf4', transform_id=4, created_by_id=2)
❗ this creates one artifact per file in the directory - you might simply call ln.Artifact(dir) to get one artifact for the entire directory
!python project-flow-scripts/postprocess_cellranger.py
Show code cell output
💡 connected lamindb: testuser1/mydata
💡 saved: Transform(version='2', uid='YqmbO6oMXjRj65cN', name='postprocess_cellranger.py', key='postprocess_cellranger.py', type='script', updated_at=2024-05-20 08:36:52 UTC, created_by_id=2)
💡 saved: Run(uid='b1hI5zi5ruzslTY2KAyg', transform_id=5, created_by_id=2)
Inspect data flow:
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
✓ (3.916s)
Total time: 3.918s
Review results¶
Let’s load one of the plots:
# track the current notebook as transform
ln.settings.transform.stem_uid = "1LCd8kco9lZU"
ln.settings.transform.version = "0"
ln.track()
💡 notebook imports: ipython==8.24.0 lamindb==0.72.0 nbproject_test==0.5.1
💡 saved: Transform(version='0', uid='1LCd8kco9lZU6K79', name='Project flow', key='project-flow', type='notebook', updated_at=2024-05-20 08:36:58 UTC, created_by_id=1)
💡 saved: Run(uid='FfG3hq1dy7uUQTSOOrSl', transform_id=7, created_by_id=1)
artifact = ln.Artifact.filter(key__contains="figures/matrixplot").one()
artifact.cache()
Show code cell output
PosixUPath('/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/Z2QduR5ZYRMQ29Ub8bQn.png')
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:
Alternatively, we can also look at the sequence of transforms:
transform = ln.Transform.search("Project flow").first()
transform.parents.df()
version | uid | name | key | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
6 | 1 | lB3IyPLQSmvt5zKv | Perform single cell analysis, integrate with C... | integrated-analysis | None | notebook | None | None | None | None | 2024-05-20 08:36:56.432751+00:00 | 2024-05-20 08:36:56.432774+00:00 | 2 |
Understand runs¶
We tracked pipeline and notebook runs through run_context
, which stores a Transform
and a Run
record as 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 backed()
, 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()
version | created_at | created_by_id | updated_at | uid | storage_id | key | suffix | accessor | description | size | hash | hash_type | n_objects | n_observations | transform_id | run_id | visibility | key_is_virtual | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||
2 | None | 2024-05-20 08:36:45.931718+00:00 | 2 | 2024-05-20 08:36:45.931758+00:00 | hwq7G2i19lQMSbxpRRyM | 1 | None | .parquet | DataFrame | hits from schmidt22 crispra GWS | 18368 | 5GtKh_v__shMvLryIdXkKA | md5 | None | None | 2 | 2 | 1 | True |
Which transform ingested a given artifact?
artifact = ln.Artifact.filter().first()
artifact.transform
Transform(uid='jXwLQU398hmS', name='Upload GWS CRISPRa result', type='upload', updated_at=2024-05-20 08:36:41 UTC, created_by_id=1)
And which user?
artifact.created_by
User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2024-05-20 08:36:47 UTC)
Which transforms were created by a given user?
users = ln.User.lookup()
ln.Transform.filter(created_by=users.testuser1).df()
version | uid | name | key | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
1 | None | jXwLQU398hmS | Upload GWS CRISPRa result | None | None | upload | None | NaN | None | None | 2024-05-20 08:36:41.714806+00:00 | 2024-05-20 08:36:41.714825+00:00 | 1 |
3 | 1 | qCJPkOuZAi9q5zKv | chromium_10x_upload.py | chromium_10x_upload.py | None | script | None | 5.0 | None | None | 2024-05-20 08:36:48.123815+00:00 | 2024-05-20 08:36:48.574620+00:00 | 1 |
7 | 0 | 1LCd8kco9lZU6K79 | Project flow | project-flow | None | notebook | None | NaN | None | None | 2024-05-20 08:36:58.157787+00:00 | 2024-05-20 08:36:58.157816+00:00 | 1 |
Which notebooks were created by a given user?
ln.Transform.filter(created_by=users.testuser1, type="notebook").df()
version | uid | name | key | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
7 | 0 | 1LCd8kco9lZU6K79 | Project flow | project-flow | None | notebook | None | None | None | None | 2024-05-20 08:36:58.157787+00:00 | 2024-05-20 08:36:58.157816+00:00 | 1 |
We can also view all recent additions to the entire database:
ln.view()
Show code cell output
Artifact
version | created_at | created_by_id | updated_at | uid | storage_id | key | suffix | accessor | description | size | hash | hash_type | n_objects | n_observations | transform_id | run_id | visibility | key_is_virtual | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||
12 | None | 2024-05-20 08:36:57.420041+00:00 | 2 | 2024-05-20 08:36:57.420084+00:00 | Z2QduR5ZYRMQ29Ub8bQn | 1 | figures/matrixplot_fig2_score-wgs-hits-per-clu... | .png | None | None | 28814 | vKSAeP8dZnBAPkdOYa_kRQ | md5 | None | None | 6 | 6 | 1 | True |
11 | None | 2024-05-20 08:36:57.150922+00:00 | 2 | 2024-05-20 08:36:57.150964+00:00 | gj57CfpBzGDNio8T3IKQ | 1 | figures/umap_fig1_score-wgs-hits.png | .png | None | None | 118999 | IlWQvuhi-VqBf1nCqWnYXQ | md5 | None | None | 6 | 6 | 1 | True |
10 | None | 2024-05-20 08:36:53.657677+00:00 | 2 | 2024-05-20 08:36:53.657726+00:00 | IMtJc6arsTqeDd0MDSai | 1 | schmidt22_perturbseq.h5ad | .h5ad | AnnData | perturbseq counts | 20659936 | la7EvqEUMDlug9-rpw-udA | md5 | None | None | 5 | 5 | 1 | False |
9 | None | 2024-05-20 08:36:51.135111+00:00 | 2 | 2024-05-20 08:36:51.135141+00:00 | NoQrIQFkoIMMPBmy6ZgO | 1 | perturbseq/filtered_feature_bc_matrix/features... | .tsv.gz | None | None | 6 | pPccvAS5I3oYSDR3rGZmtg | md5 | None | None | 4 | 4 | 1 | False |
8 | None | 2024-05-20 08:36:51.134534+00:00 | 2 | 2024-05-20 08:36:51.134567+00:00 | gMj1FfSv602Urw4MYR7g | 1 | perturbseq/filtered_feature_bc_matrix/barcodes... | .tsv.gz | None | None | 6 | PvFlKxy7ijPTEYJ4OFEQUQ | md5 | None | None | 4 | 4 | 1 | False |
7 | None | 2024-05-20 08:36:51.133738+00:00 | 2 | 2024-05-20 08:36:51.133772+00:00 | IUTyo8nDwBLjsVjIAXQQ | 1 | perturbseq/filtered_feature_bc_matrix/matrix.m... | .mtx.gz | None | None | 6 | eHp6FUPKQtXb4G5VSeNZQA | md5 | None | None | 4 | 4 | 1 | False |
4 | None | 2024-05-20 08:36:48.560037+00:00 | 1 | 2024-05-20 08:36:48.560069+00:00 | iPYm8jORKhj26TOWoAQ5 | 1 | fastq/perturbseq_R2_001.fastq.gz | .fastq.gz | None | None | 6 | oNwvuFaV4lsyEC9j86c6eg | md5 | None | None | 3 | 3 | 1 | False |
Run
uid | transform_id | started_at | finished_at | created_by_id | report_id | environment_id | is_consecutive | reference | reference_type | created_at | |
---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||
1 | HwuqAjkLmgQXFsC6YOn7 | 1 | 2024-05-20 08:36:41.718202+00:00 | NaT | 1 | None | NaN | True | None | None | 2024-05-20 08:36:41.718302+00:00 |
2 | NtUtLE0hUWBeoxuoomOQ | 2 | 2024-05-20 08:36:45.449954+00:00 | NaT | 2 | None | NaN | True | None | None | 2024-05-20 08:36:45.450043+00:00 |
3 | RtUwu8FCDnX15iJ90I6c | 3 | 2024-05-20 08:36:48.126513+00:00 | 2024-05-20 08:36:48.572968+00:00 | 1 | None | 6.0 | True | None | None | 2024-05-20 08:36:48.126598+00:00 |
4 | 0mNsLnH49vTmK6fGdRf4 | 4 | 2024-05-20 08:36:50.686130+00:00 | NaT | 2 | None | NaN | None | None | None | 2024-05-20 08:36:50.686250+00:00 |
5 | b1hI5zi5ruzslTY2KAyg | 5 | 2024-05-20 08:36:52.612694+00:00 | NaT | 2 | None | NaN | None | None | None | 2024-05-20 08:36:52.612820+00:00 |
6 | c677GexLTl0XYRxyFKHQ | 6 | 2024-05-20 08:36:56.437982+00:00 | NaT | 2 | None | NaN | True | None | None | 2024-05-20 08:36:56.438072+00:00 |
7 | FfG3hq1dy7uUQTSOOrSl | 7 | 2024-05-20 08:36:58.162767+00:00 | NaT | 1 | None | NaN | True | None | None | 2024-05-20 08:36:58.162855+00:00 |
Storage
created_at | created_by_id | run_id | updated_at | uid | root | description | type | region | instance_uid | |
---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||
1 | 2024-05-20 08:36:40.095581+00:00 | 1 | None | 2024-05-20 08:36:40.095628+00:00 | cDhO8Nfywykk | /home/runner/work/lamin-usecases/lamin-usecase... | None | local | None | 54ZGqgkROOFf |
Transform
version | uid | name | key | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
7 | 0 | 1LCd8kco9lZU6K79 | Project flow | project-flow | None | notebook | None | NaN | None | None | 2024-05-20 08:36:58.157787+00:00 | 2024-05-20 08:36:58.157816+00:00 | 1 |
6 | 1 | lB3IyPLQSmvt5zKv | Perform single cell analysis, integrate with C... | integrated-analysis | None | notebook | None | NaN | None | None | 2024-05-20 08:36:56.432751+00:00 | 2024-05-20 08:36:56.432774+00:00 | 2 |
5 | 2 | YqmbO6oMXjRj65cN | postprocess_cellranger.py | postprocess_cellranger.py | None | script | None | NaN | None | None | 2024-05-20 08:36:52.610237+00:00 | 2024-05-20 08:36:52.610265+00:00 | 2 |
4 | 7.2.0 | qY9aAILlTJMW | Cell Ranger | None | None | pipeline | None | NaN | https://www.10xgenomics.com/support/software/c... | None | 2024-05-20 08:36:50.683662+00:00 | 2024-05-20 08:36:50.683682+00:00 | 2 |
3 | 1 | qCJPkOuZAi9q5zKv | chromium_10x_upload.py | chromium_10x_upload.py | None | script | None | 5.0 | None | None | 2024-05-20 08:36:48.123815+00:00 | 2024-05-20 08:36:48.574620+00:00 | 1 |
2 | 1 | T0T28btuB0PG5zKv | GWS CRIPSRa analysis | hit-identification | None | notebook | None | NaN | None | None | 2024-05-20 08:36:45.445012+00:00 | 2024-05-20 08:36:45.445031+00:00 | 2 |
1 | None | jXwLQU398hmS | Upload GWS CRISPRa result | None | None | upload | None | NaN | None | None | 2024-05-20 08:36:41.714806+00:00 | 2024-05-20 08:36:41.714825+00:00 | 1 |
User
uid | handle | name | created_at | updated_at | |
---|---|---|---|---|---|
id | |||||
2 | bKeW4T6E | testuser2 | Test User2 | 2024-05-20 08:36:45.442375+00:00 | 2024-05-20 08:36:50.677902+00:00 |
1 | DzTjkKse | testuser1 | Test User1 | 2024-05-20 08:36:40.092147+00:00 | 2024-05-20 08:36:47.996968+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 103, 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 760, 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
['/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/L1MDIGzjftThAyjCUZCe.py', '/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/NCske8n2bSHYfGBaJhoE.txt', '/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/Z2QduR5ZYRMQ29Ub8bQn.png', '/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/_is_initialized', '/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/gj57CfpBzGDNio8T3IKQ.png', '/home/runner/work/lamin-usecases/lamin-usecases/docs/mydata/.lamindb/hwq7G2i19lQMSbxpRRyM.parquet']