Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍱 Add an example using wetlab.Biosample to the registries guide #2243

Open
falexwolf opened this issue Dec 2, 2024 · 0 comments
Open

Comments

@falexwolf
Copy link
Member

falexwolf commented Dec 2, 2024

Given how common this is, it'd be nice to create a few biosamples in the toy data. Or maybe do it with ULabels. 🤔

Something along these lines:

import wetlab as wl
from django.db.models import F

wl.Biosample.filter(
    created_at__gt="2024-12-01"
).annotate(
    fcs_file__key=F('artifacts__key')
).filter(
    artifacts__key__endswith='.fcs'
).df()

It might also be that this doesn't work entirely yet because of the annotate() call.

Also adding a more complex example

import pandas as pd
from django.db.models import F, Subquery, OuterRef

# First, create a subquery to get only .fcs artifacts
fcs_artifacts = (
    Biosample.artifacts.through.objects
    .filter(artifact__key__endswith='.fcs')
    .filter(biosample=OuterRef('pk'))
    .values('artifact__key')
)

# Now use this subquery in the main query
queryset = (
    wl.Biosample.filter(
    created_at__gt="2024-12-01"
).annotate(
artifacts__key=Subquery(fcs_artifacts[:1])
).filter(artifacts__key__isnull=False)
)

# Convert to DataFrame with all fields
df = pd.DataFrame.from_records(
    queryset.values()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant