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='IklsxKrGLRImLZh0', name='Upload GWS CRISPRa result', type='upload', updated_at=2024-04-22 10:27:14 UTC, created_by_id=1)
π‘ saved: Run(uid='EWfQAIrW3wbA1uOGeERV', transform_id=1, created_by_id=1)
Hit identification in notebook #
Access, transform & register data in drylab by testuser2
:
# This function mimics the hit identification notebook
# In reality, you would run this in a notebook titled "GWS CRIPSRa analysis"
def mock_hit_identification_notebook():
# log in as another user
ln.setup.login("testuser2")
# create a new transform to mimic a new notebook
# (in reality you just run ln.track() in a notebook and you don't have to manage runs)
transform = ln.Transform(name="GWS CRIPSRa analysis", type="notebook")
transform.save()
run = ln.Run(transform=transform)
run.save()
# access the upload artifact
input_file = ln.Artifact.filter(key="schmidt22-crispra-gws-IFNG.csv").one()
# identify hits
input_df = input_file.load(is_run_input=run).set_index("id")
output_df = input_df[input_df["pos|fdr"] < 0.01].copy()
# register hits in output artifact
ln.Artifact.from_df(output_df, description="hits from schmidt22 crispra GWS", run=run).save()
mock_hit_identification_notebook()
Inspect data flow:
artifact = ln.Artifact.filter(description="hits from schmidt22 crispra GWS").one()
artifact.view_lineage()
Sequencer upload #
Upload files from sequencer via script chromium_10x_upload.py:
!python project-flow-scripts/chromium_10x_upload.py
π‘ connected lamindb: testuser1/mydata
π‘ saved: Transform(uid='qCJPkOuZAi9q5zKv', name='chromium_10x_upload.py', key='chromium_10x_upload.py', version='1', type='script', updated_at=2024-04-22 10:27:17 UTC, created_by_id=1)
π‘ saved: Run(uid='BykoALMl9mp8dzfXUNqm', transform_id=3, created_by_id=1)
β
saved transform.source_code: Artifact(uid='zKbQLfb8wAhavsv2ubkE', suffix='.py', description='Source of transform qCJPkOuZAi9q5zKv', version='1', size=474, hash='o-QoKgEZGxbk5oBtcAKoWw', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2024-04-22 10:27:18 UTC, storage_id=1, created_by_id=1)
β
saved run.environment: Artifact(uid='3McctApJlP650n8VE3cY', suffix='.txt', description='requirements.txt', size=3400, hash='lrHLv26VOiHp8JkBy2B7zw', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2024-04-22 10:27:18 UTC, storage_id=1, created_by_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
π‘ connected lamindb: testuser1/mydata
π‘ saved: Transform(uid='w6eKweXO1stJDZiW', name='Cell Ranger', version='7.2.0', type='pipeline', reference='https://www.10xgenomics.com/support/software/cell-ranger/7.2', updated_at=2024-04-22 10:27:20 UTC, created_by_id=2)
π‘ saved: Run(uid='oCsKHG1XuH1jK4o0J1BX', 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
π‘ connected lamindb: testuser1/mydata
π‘ saved: Transform(uid='YqmbO6oMXjRj65cN', name='postprocess_cellranger.py', key='postprocess_cellranger.py', version='2', type='script', updated_at=2024-04-22 10:27:22 UTC, created_by_id=2)
π‘ saved: Run(uid='nCDH4kLNiN2ZhCjuwVuO', transform_id=5, created_by_id=2)
β
saved transform.source_code: Artifact(uid='j9i7StnK6LjbBRQ7fpN3', suffix='.py', description='Source of transform YqmbO6oMXjRj65cN', version='2', size=495, hash='iLSbWXZ-j7pkIgzO0i6c0w', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2024-04-22 10:27:23 UTC, storage_id=1, created_by_id=2)
β returning existing artifact with same hash: Artifact(uid='3McctApJlP650n8VE3cY', suffix='.txt', description='requirements.txt', size=3400, hash='lrHLv26VOiHp8JkBy2B7zw', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2024-04-22 10:27:18 UTC, storage_id=1, created_by_id=1)
β
saved run.environment: Artifact(uid='3McctApJlP650n8VE3cY', suffix='.txt', description='requirements.txt', size=3400, hash='lrHLv26VOiHp8JkBy2B7zw', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2024-04-22 10:27:18 UTC, storage_id=1, created_by_id=1)
Inspect data flow:
output_file = ln.Artifact.filter(description="perturbseq counts").one()
output_file.view_lineage()
Integrate scRNA-seq & phenotypic data #
Integrate data in a notebook:
# This function mimics the integrated analysis notebook
# In reality, you would run this in a notebook titled "Perform single cell analysis, integrate with CRISPRa screen"
def mock_integrated_analysis_notebook():
import scanpy as sc
# Create a new transform to mimic a new notebook
# In reality you just run ln.track() in a notebook
transform = ln.Transform(
name="Perform single cell analysis, integrate with CRISPRa screen",
type="notebook",
)
transform.save()
run = ln.Run(transform=transform)
run.save()
# access the output files of bfx pipeline and previous analysis
file_ps = ln.Artifact.filter(description__icontains="perturbseq").one()
adata = file_ps.load(is_run_input=run)
file_hits = ln.Artifact.filter(description="hits from schmidt22 crispra GWS").one()
screen_hits = file_hits.load(is_run_input=run)
# perform analysis and register output plot files
sc.tl.score_genes(adata, adata.var_names.intersection(screen_hits.index).tolist())
filesuffix = "_fig1_score-wgs-hits.png"
sc.pl.umap(adata, color="score", show=False, save=filesuffix)
filepath = f"figures/umap{filesuffix}"
artifact = ln.Artifact(filepath, key=filepath, run=run)
artifact.save()
filesuffix = "fig2_score-wgs-hits-per-cluster.png"
sc.pl.matrixplot(
adata, groupby="cluster_name", var_names=["score"], show=False, save=filesuffix
)
filepath = f"figures/matrixplot_{filesuffix}"
artifact = ln.Artifact(filepath, key=filepath, run=run)
artifact.save()
mock_integrated_analysis_notebook()
Show code cell output
WARNING: saving figure to file figures/umap_fig1_score-wgs-hits.png
WARNING: saving figure to file figures/matrixplot_fig2_score-wgs-hits-per-cluster.png
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.23.0 lamindb==0.70.3 scanpy==1.10.1
π‘ saved: Transform(uid='1LCd8kco9lZU6K79', name='Project flow', key='project-flow', version='0', type='notebook', updated_at=2024-04-22 10:27:25 UTC, created_by_id=1)
π‘ saved: Run(uid='7HvWOjdBAUthkJUtjJyV', 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/5ARkXuM8SnPEOg93JZph.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", return_queryset=True).first()
transform.parents.df()
uid | name | key | version | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
6 | Oah4jGcn72kwOhS9 | Perform single cell analysis, integrate with C... | None | None | None | notebook | None | None | None | None | 2024-04-22 10:27:24.934286+00:00 | 2024-04-22 10:27:24.934319+00:00 | 1 |
transform.view_parents()
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 stage()
, 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", return_queryset=True).first()
And then find all the artifacts created by that notebook:
ln.Artifact.filter(transform=transform).df()
uid | storage_id | key | suffix | accessor | description | version | size | hash | hash_type | n_objects | n_observations | transform_id | run_id | visibility | key_is_virtual | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||
2 | T0Bso2o2lFp1D72YmXuP | 1 | None | .parquet | DataFrame | hits from schmidt22 crispra GWS | None | 18368 | PihzyuN-FWc-ld6ioxAuPg | md5 | None | None | 2 | 2 | 1 | True | 2024-04-22 10:27:15.719802+00:00 | 2024-04-22 10:27:15.719834+00:00 | 1 |
Which transform ingested a given artifact?
artifact = ln.Artifact.filter().first()
artifact.transform
Transform(uid='IklsxKrGLRImLZh0', name='Upload GWS CRISPRa result', type='upload', updated_at=2024-04-22 10:27:14 UTC, created_by_id=1)
And which user?
artifact.created_by
User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2024-04-22 10:27:17 UTC)
Which transforms were created by a given user?
users = ln.User.lookup()
ln.Transform.filter(created_by=users.testuser1).df()
uid | name | key | version | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
1 | IklsxKrGLRImLZh0 | Upload GWS CRISPRa result | None | None | None | upload | None | NaN | None | None | 2024-04-22 10:27:14.273844+00:00 | 2024-04-22 10:27:14.273864+00:00 | 1 |
2 | AoqJpZR5fTDQWDmg | GWS CRIPSRa analysis | None | None | None | notebook | None | NaN | None | None | 2024-04-22 10:27:15.667273+00:00 | 2024-04-22 10:27:15.667310+00:00 | 1 |
3 | qCJPkOuZAi9q5zKv | chromium_10x_upload.py | chromium_10x_upload.py | 1 | None | script | None | 3.0 | None | None | 2024-04-22 10:27:17.721778+00:00 | 2024-04-22 10:27:18.204983+00:00 | 1 |
6 | Oah4jGcn72kwOhS9 | Perform single cell analysis, integrate with C... | None | None | None | notebook | None | NaN | None | None | 2024-04-22 10:27:24.934286+00:00 | 2024-04-22 10:27:24.934319+00:00 | 1 |
7 | 1LCd8kco9lZU6K79 | Project flow | project-flow | 0 | None | notebook | None | NaN | None | None | 2024-04-22 10:27:25.844322+00:00 | 2024-04-22 10:27:25.844361+00:00 | 1 |
Which notebooks were created by a given user?
ln.Transform.filter(created_by=users.testuser1, type="notebook").df()
uid | name | key | version | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
2 | AoqJpZR5fTDQWDmg | GWS CRIPSRa analysis | None | None | None | notebook | None | None | None | None | 2024-04-22 10:27:15.667273+00:00 | 2024-04-22 10:27:15.667310+00:00 | 1 |
6 | Oah4jGcn72kwOhS9 | Perform single cell analysis, integrate with C... | None | None | None | notebook | None | None | None | None | 2024-04-22 10:27:24.934286+00:00 | 2024-04-22 10:27:24.934319+00:00 | 1 |
7 | 1LCd8kco9lZU6K79 | Project flow | project-flow | 0 | None | notebook | None | None | None | None | 2024-04-22 10:27:25.844322+00:00 | 2024-04-22 10:27:25.844361+00:00 | 1 |
We can also view all recent additions to the entire database:
ln.view()
Show code cell output
Artifact
uid | storage_id | key | suffix | accessor | description | version | size | hash | hash_type | n_objects | n_observations | transform_id | run_id | visibility | key_is_virtual | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||
13 | 5ARkXuM8SnPEOg93JZph | 1 | figures/matrixplot_fig2_score-wgs-hits-per-clu... | .png | None | None | None | 28814 | 8zXF_cVwaZnfhmrLbt_0kA | md5 | None | None | 6 | 6 | 1 | True | 2024-04-22 10:27:25.540623+00:00 | 2024-04-22 10:27:25.540652+00:00 | 1 |
12 | yOd8h7IYJiPcsVn21m3I | 1 | figures/umap_fig1_score-wgs-hits.png | .png | None | None | None | 118999 | DCFDLUMF-UohaBvkThn0mA | md5 | None | None | 6 | 6 | 1 | True | 2024-04-22 10:27:25.197568+00:00 | 2024-04-22 10:27:25.197596+00:00 | 1 |
11 | 0yd8V63gtJmF3dgJ5fBB | 1 | schmidt22_perturbseq.h5ad | .h5ad | AnnData | perturbseq counts | None | 20659936 | la7EvqEUMDlug9-rpw-udA | md5 | None | None | 5 | 5 | 1 | False | 2024-04-22 10:27:23.655543+00:00 | 2024-04-22 10:27:23.655575+00:00 | 2 |
9 | XzwrfUB2aHg4gA2ibxAv | 1 | perturbseq/filtered_feature_bc_matrix/matrix.m... | .mtx.gz | None | None | None | 6 | 1CMzKRaZQPd0YsqeZLW2WA | md5 | None | None | 4 | 4 | 1 | False | 2024-04-22 10:27:20.945048+00:00 | 2024-04-22 10:27:20.945068+00:00 | 2 |
8 | y9QEQXXttDsVMoFcjZX6 | 1 | perturbseq/filtered_feature_bc_matrix/features... | .tsv.gz | None | None | None | 6 | ju_g0clsk42vS2RhqFRXdQ | md5 | None | None | 4 | 4 | 1 | False | 2024-04-22 10:27:20.944388+00:00 | 2024-04-22 10:27:20.944416+00:00 | 2 |
7 | 4zjsgH1BeeA149zyMDHc | 1 | perturbseq/filtered_feature_bc_matrix/barcodes... | .tsv.gz | None | None | None | 6 | n3K0imoBddWNvh6-slrRUA | md5 | None | None | 4 | 4 | 1 | False | 2024-04-22 10:27:20.943479+00:00 | 2024-04-22 10:27:20.943508+00:00 | 2 |
6 | XdN42RTBrOalaBBwf1rO | 1 | fastq/perturbseq_R2_001.fastq.gz | .fastq.gz | None | None | None | 6 | YV4QFaBVS5k7_jvWw8ckNQ | md5 | None | None | 3 | 3 | 1 | False | 2024-04-22 10:27:18.214035+00:00 | 2024-04-22 10:27:18.214054+00:00 | 1 |
Run
uid | transform_id | started_at | finished_at | created_by_id | json | report_id | environment_id | is_consecutive | reference | reference_type | created_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
1 | EWfQAIrW3wbA1uOGeERV | 1 | 2024-04-22 10:27:14.277397+00:00 | NaT | 1 | None | None | NaN | True | None | None | 2024-04-22 10:27:14.277594+00:00 |
2 | iXfKJZMNgbp4ObvxtuIk | 2 | 2024-04-22 10:27:15.669288+00:00 | NaT | 1 | None | None | NaN | None | None | None | 2024-04-22 10:27:15.669384+00:00 |
3 | BykoALMl9mp8dzfXUNqm | 3 | 2024-04-22 10:27:17.724368+00:00 | 2024-04-22 10:27:18.215857+00:00 | 1 | None | None | 4.0 | None | None | None | 2024-04-22 10:27:17.724492+00:00 |
4 | oCsKHG1XuH1jK4o0J1BX | 4 | 2024-04-22 10:27:20.450484+00:00 | NaT | 2 | None | None | NaN | None | None | None | 2024-04-22 10:27:20.450607+00:00 |
5 | nCDH4kLNiN2ZhCjuwVuO | 5 | 2024-04-22 10:27:22.669651+00:00 | NaT | 2 | None | None | 4.0 | None | None | None | 2024-04-22 10:27:22.669781+00:00 |
6 | WlJjYCJooGQYcl4Lnkpo | 6 | 2024-04-22 10:27:24.936851+00:00 | NaT | 1 | None | None | NaN | None | None | None | 2024-04-22 10:27:24.936952+00:00 |
7 | 7HvWOjdBAUthkJUtjJyV | 7 | 2024-04-22 10:27:25.849930+00:00 | NaT | 1 | None | None | NaN | True | None | None | 2024-04-22 10:27:25.850031+00:00 |
Storage
uid | root | description | type | region | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|
id | ||||||||
1 | 3vZBLuqy | /home/runner/work/lamin-usecases/lamin-usecase... | None | local | None | 2024-04-22 10:27:12.274302+00:00 | 2024-04-22 10:27:12.274327+00:00 | 1 |
Transform
uid | name | key | version | description | type | latest_report_id | source_code_id | reference | reference_type | created_at | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||
7 | 1LCd8kco9lZU6K79 | Project flow | project-flow | 0 | None | notebook | None | NaN | None | None | 2024-04-22 10:27:25.844322+00:00 | 2024-04-22 10:27:25.844361+00:00 | 1 |
6 | Oah4jGcn72kwOhS9 | Perform single cell analysis, integrate with C... | None | None | None | notebook | None | NaN | None | None | 2024-04-22 10:27:24.934286+00:00 | 2024-04-22 10:27:24.934319+00:00 | 1 |
5 | YqmbO6oMXjRj65cN | postprocess_cellranger.py | postprocess_cellranger.py | 2 | None | script | None | 10.0 | None | None | 2024-04-22 10:27:22.666862+00:00 | 2024-04-22 10:27:23.146977+00:00 | 2 |
4 | w6eKweXO1stJDZiW | Cell Ranger | None | 7.2.0 | None | pipeline | None | NaN | https://www.10xgenomics.com/support/software/c... | None | 2024-04-22 10:27:20.448137+00:00 | 2024-04-22 10:27:20.448161+00:00 | 2 |
3 | qCJPkOuZAi9q5zKv | chromium_10x_upload.py | chromium_10x_upload.py | 1 | None | script | None | 3.0 | None | None | 2024-04-22 10:27:17.721778+00:00 | 2024-04-22 10:27:18.204983+00:00 | 1 |
2 | AoqJpZR5fTDQWDmg | GWS CRIPSRa analysis | None | None | None | notebook | None | NaN | None | None | 2024-04-22 10:27:15.667273+00:00 | 2024-04-22 10:27:15.667310+00:00 | 1 |
1 | IklsxKrGLRImLZh0 | Upload GWS CRISPRa result | None | None | None | upload | None | NaN | None | None | 2024-04-22 10:27:14.273844+00:00 | 2024-04-22 10:27:14.273864+00:00 | 1 |
User
uid | handle | name | created_at | updated_at | |
---|---|---|---|---|---|
id | |||||
2 | bKeW4T6E | testuser2 | Test User2 | 2024-04-22 10:27:15.658644+00:00 | 2024-04-22 10:27:20.423826+00:00 |
1 | DzTjkKse | testuser1 | Test User1 | 2024-04-22 10:27:12.271119+00:00 | 2024-04-22 10:27:17.588457+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)
π‘ deleting instance testuser1/mydata
β manually delete your stored data: /home/runner/work/lamin-usecases/lamin-usecases/docs/mydata