Manage flow cytometry data#

Hide code cell content
!lamin init --storage ./test-flow --schema bionty
import lamindb as ln
import lnschema_bionty as lb
import readfcs

ln.settings.verbosity = 3  # show hints
lb.settings.species = "human"  # globally set species
ln.track()

We start with a flow cytometry file from Alpert19:

Hide code cell content
filepath = ln.dev.datasets.file_fcs_alpert19()
filepath

Use readfcs to read the fcs file into memory:

adata = readfcs.read("Alpert19.fcs")
adata

Track data with cell markers#

We’ll use the CellMarker reference to link features:

file = ln.File.from_anndata(adata, description="Alpert19", var_ref=lb.CellMarker.name)
file.save()
file.features
file.features["var"].df().head(10)

Let’s register another flow file:

Hide code cell content
adata2 = readfcs.read(ln.dev.datasets.file_fcs())
file2 = ln.File.from_anndata(
    adata2, description="My fcs file", var_ref=lb.CellMarker.name
)
file2.save()

Query by cell markers#

Which datasets have CD14 in the flow panel:

cell_markers = lb.CellMarker.lookup()
cell_markers.cd14
ln.File.filter(feature_sets__cell_markers=cell_markers.cd14).df()

Shared cell markers between two files:

file1 = ln.File.filter(feature_sets__cell_markers=cell_markers.cd14).all()[0]
file2 = ln.File.filter(feature_sets__cell_markers=cell_markers.cd14).all()[1]
file1_markers = file1.features["var"]
file2_markers = file2.features["var"]

shared_markers = file1_markers & file2_markers
shared_markers.list("name")

Flow marker registry#

Check out the first 10 rows of the CellMarker table:

lb.CellMarker.filter().df().head(10)
Hide code cell content
# throw error if there is none
ln.File.filter(feature_sets__cell_markers=cell_markers.cd14).exists()
# clean up test instance
!lamin delete test-flow
!rm -r test-flow