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

Custom cohorts in metamist #615

Merged
merged 177 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 162 commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
5ceb5f6
In progress
vivbak Nov 15, 2023
d7ef222
In progress
vivbak Nov 15, 2023
da2f9db
Cohort GraphQL Skeleton -- functional now
vivbak Nov 16, 2023
c2ff6c9
Merge branch 'dev' into custom-cohorts
vivbak Nov 16, 2023
6f1d9da
This should go in another PR
vivbak Nov 16, 2023
a956cee
Merge branch 'dev' into custom-cohorts
vivbak Nov 17, 2023
25155ab
ignore venv
daniaki Nov 23, 2023
7a5d978
Updated docker mariadb setup instructions
daniaki Nov 23, 2023
d5103a1
support for `name`, `derived_from` & other fields
daniaki Nov 23, 2023
9d655e9
Fix error if applying `ord` to int
daniaki Nov 23, 2023
f69cde0
Add all fields to model
daniaki Nov 23, 2023
5d24669
Set empty dict to fix GraphQL non-null error
daniaki Nov 23, 2023
32fc088
Fix error applying `ord` to int
daniaki Nov 23, 2023
7dc373d
Add `name` to `cohort` table
daniaki Nov 23, 2023
312c6f8
version bump
daniaki Nov 23, 2023
9fb6a06
Formatting; cohort GQL schema
daniaki Nov 27, 2023
57afc9f
cohort layer update
daniaki Nov 27, 2023
203a49b
cohort db table update
daniaki Nov 27, 2023
60798c1
CohortBuilder route
daniaki Nov 27, 2023
5af95cc
Single SG ID form
daniaki Nov 27, 2023
c5cdb17
SG ID from project(s) form
daniaki Nov 27, 2023
58c80d4
Cohort Builder page
daniaki Nov 27, 2023
003ffff
Re-usable SG scrolling table
daniaki Nov 27, 2023
4cdfde0
types definition
daniaki Nov 27, 2023
3f27185
Add link to nav bar to cohort builder
daniaki Nov 27, 2023
f153df2
Add substring search
daniaki Nov 27, 2023
4db1ca7
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Nov 27, 2023
a0385d5
Formatting; add assay filter on sample
daniaki Nov 28, 2023
7858fc7
Allow hashable assay filter when `meta` present
daniaki Nov 28, 2023
39e0c8b
Type for project
daniaki Nov 28, 2023
adce34b
Add GQL query to project form
daniaki Nov 28, 2023
b4b0a5b
Add GQL query to ID form
daniaki Nov 28, 2023
7f0b62e
Handle form submission
daniaki Nov 28, 2023
9f361ef
Atomic transaction
daniaki Nov 28, 2023
cd94354
Put query params in POST body
daniaki Nov 28, 2023
1747882
add APIError type
daniaki Nov 28, 2023
8217790
Add TODO note; add loader to search button
daniaki Nov 28, 2023
d6017cb
merge dupe sgs from search results
daniaki Nov 28, 2023
4a334d5
Use auto-gen API; better error handling
daniaki Nov 28, 2023
7f24180
clean up imports
daniaki Nov 28, 2023
ada2c01
Make inputs reactive
daniaki Nov 28, 2023
7d1c8eb
Cohort detail view
daniaki Nov 28, 2023
706cf01
import updates
daniaki Nov 28, 2023
05066b0
add detail route
daniaki Nov 28, 2023
d60db2a
use with router hooks
daniaki Nov 28, 2023
654b9ae
exclude ids input
daniaki Nov 28, 2023
c002f88
navigate to new detail vie
daniaki Nov 28, 2023
af8f4d9
make project required
daniaki Nov 28, 2023
f1e491c
Add space between muck and msg
daniaki Nov 28, 2023
deaa491
Get project info
daniaki Nov 28, 2023
d2662f2
Convert ids to int to fix not found error
daniaki Nov 28, 2023
1ca9df4
cohort project resolver
daniaki Nov 28, 2023
c5f0fd8
Update table rendering logic
daniaki Nov 28, 2023
573b57b
Update table rendering logic
daniaki Nov 28, 2023
49a1245
Add search result info in warning box
daniaki Nov 28, 2023
2b9ba76
Linter fixes
daniaki Dec 3, 2023
0172dff
formatting
daniaki Dec 4, 2023
62ea338
Merge branch 'dev' into custom-cohorts
daniaki Dec 4, 2023
4b0661a
lint fix
daniaki Dec 4, 2023
cfd21eb
unused import
daniaki Dec 4, 2023
7a3611c
Tmp fix for billing query inside NavBar
daniaki Dec 4, 2023
bc5e0b9
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Jan 10, 2024
32fac2b
Custom cohorts SG query optimisation (#630)
daniaki Jan 31, 2024
146e6b2
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Jan 31, 2024
b8e88c3
Merge branch dev into custom-cohorts
vivbak Jan 31, 2024
dcd5e68
update dbbase import
vivbak Jan 31, 2024
9ef10ef
Update to_sql signature to match superclass. An attempt at pleasing t…
vivbak Feb 5, 2024
f82f816
Fix click overwriting param to None when not specified
vivbak Feb 8, 2024
9e33d7f
Create endpoint to create cohort from criteria - Project/s
vivbak Feb 16, 2024
3fdc803
Fix query cohort, call connection directly
vivbak Feb 16, 2024
558b073
Add further criteria to create_cohort_from_criteria endpoint
vivbak Feb 22, 2024
3b00f6c
Fix the linter, import order, spaces, etc
vivbak Feb 22, 2024
ae3c271
Remove AddFromIdListForm.tsx
vivbak Feb 26, 2024
9a4668f
Delete AddFromIDListForm
vivbak Feb 26, 2024
bcfe23e
Delete custom cohorts UI elements
vivbak Feb 26, 2024
70673a0
Remove link to Cohort Builder from NavBar
vivbak Feb 26, 2024
a2d9fca
Remove link to custom cohorts page in routes
vivbak Feb 26, 2024
c529a31
Revert package-lock to main
vivbak Feb 26, 2024
82d0b6b
Merge branch dev into custom-cohorts
vivbak Feb 26, 2024
1008612
Handle SG ID exclusion in cohort creation
vivbak Feb 26, 2024
69c8e46
Add cohort_template table
vivbak Feb 26, 2024
345348a
Add create cohort template endpoint
vivbak Feb 27, 2024
04d208c
Fix linting issues including;
vivbak Feb 28, 2024
1b9fe45
Add basic support for cohort creation from template
vivbak Feb 28, 2024
960f026
Support query template in graphql, including adding project column
vivbak Feb 28, 2024
e9e2bf2
Handle cohort criteria and cohort template cases
vivbak Mar 4, 2024
1e31f43
Handle Templates in the layer and table
vivbak Mar 4, 2024
e5ac19c
Add skeleton for create_custom_cohort script
vivbak Mar 4, 2024
583004f
Add dry-run, refactor script to reduce args, fix bug that doesnt allo…
vivbak Mar 5, 2024
a8829b7
Return rich ids in dry mode
vivbak Mar 5, 2024
a54a256
Return rich ids when dry-run is false too
vivbak Mar 5, 2024
d95d4e4
Add support for rich custom cohort IDs i.e. COHXXX
vivbak Mar 6, 2024
81f4a5b
Add initial basic create_cohort_from_criteria() tests
jmarshall Mar 4, 2024
2850110
Merge dev (in particular, the testcontainers fix) into custom-cohorts
jmarshall Mar 13, 2024
0414940
Surely incorrect fix for `Field 'timestamp' doesn't have a default va…
jmarshall Mar 13, 2024
646740f
Fix failing tests, move cohort creation to after dry run exit
vivbak Mar 14, 2024
78df334
Rename derived_from to template_id, in line with user feedback, to ad…
vivbak Mar 19, 2024
8ca7d35
Refactor generating sg_filter, to make room for supporting more inputs
vivbak Mar 19, 2024
e265981
Fix FK issue in project.xml, delete old, add new
vivbak Mar 19, 2024
d2fa327
Handle Sample Type as Cohort Criteria
vivbak Mar 19, 2024
672d751
D'oh, blackify those parentheses
jmarshall Mar 14, 2024
ab9cdb4
Add test case exercising template_id foreign key
jmarshall Mar 18, 2024
f1e6780
Remove debugging print
jmarshall Mar 19, 2024
9829c22
Add tranche of tests that need some sample data
jmarshall Mar 18, 2024
69014ca
Add cohort-related tables to SYSTEM VERSIONING and TABLES_ORDERED_BY_…
jmarshall Mar 19, 2024
6435265
Merge dev into custom-cohorts
jmarshall Mar 20, 2024
903314d
Set audit_log_id when INSERTing into cohort tables
jmarshall Mar 21, 2024
e8f0594
Create cohort rows with timestamp set to (localtime) now
jmarshall Mar 21, 2024
ffcb24b
Further tests for individual CohortCriteria fields
jmarshall Mar 21, 2024
f989ae7
Validate projects on input for create_template
vivbak Mar 24, 2024
bec2fdd
Remove what I assume is an artefact from a merge mistake
vivbak Mar 24, 2024
e576d1f
Add cohorts to analysis objects
vivbak Mar 25, 2024
9a7a379
Account for cohort_ids in test_get_analysis() test case
jmarshall Mar 25, 2024
7a36150
Verify that create_cohort_template now validates projects
jmarshall Mar 25, 2024
3aec432
Another test for an individual CohortCriteria field
jmarshall Mar 25, 2024
0b1fa91
Add test exercising re-evaluation of a cohort template
jmarshall Mar 26, 2024
726a48e
Add test using all CohortCriteria fields
jmarshall Mar 26, 2024
1caeecf
Update schema docs
vivbak Mar 26, 2024
6ace026
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Mar 26, 2024
7335354
Combine project.xml entries
vivbak Mar 26, 2024
d705285
Add human readable CTPL prefix to templates
vivbak Mar 26, 2024
92091b5
Fix incorrect call of lunh_compute instead of lunh_is_valid
vivbak Mar 26, 2024
14aebd3
Combine John's project.xml entries into Vivian's
jmarshall Mar 26, 2024
f570e03
Add sample-type to cohort builder, fix typos
vivbak Mar 26, 2024
d7a61b5
Return all the cohort details in builder
vivbak Mar 26, 2024
6b17473
Add function to query analyses by cohort
vivbak Mar 27, 2024
52b86bb
Catch value error sooner when template ID is invalid
vivbak Mar 27, 2024
d6f4ac4
return None instead of error
vivbak Mar 27, 2024
31ebd7c
Add tests exercising cohort queries
jmarshall Apr 8, 2024
8aa7b17
Add test_query_cohort
jmarshall Apr 10, 2024
5993bcf
Cohort -> cohorts
vivbak Apr 15, 2024
8801c27
Fix indent
vivbak Apr 15, 2024
ac5cb09
Remove passing author to cohortlayer explicitly.
vivbak Apr 15, 2024
8e94421
Add type hints
vivbak Apr 15, 2024
bcc4541
Rename clayer and cohortlayer to cohort_layer
vivbak Apr 15, 2024
19ae714
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Apr 15, 2024
2e08db4
fix lint, author removed. Add newline
vivbak Apr 15, 2024
669341e
Fix whitespace for linter
vivbak Apr 15, 2024
ffb1847
Merge branch 'dev' into custom-cohorts
vivbak Apr 16, 2024
892128b
template id should not be nullable
vivbak Apr 16, 2024
68cd5b8
Remove template_id, specify as strawberry field instead. Rename Cohor…
vivbak Apr 18, 2024
6f42610
Fix CohortTemplateInternal object is not subscriptable
vivbak Apr 18, 2024
3ee14ba
Fix failing tests by modifying type hints, dict[str,str] -> CohortTem…
vivbak Apr 18, 2024
e1c6b86
Add project ID checks
vivbak Apr 19, 2024
750a18c
Raise ValueError instead of assertion, to ensure it is caught
vivbak Apr 19, 2024
65b2212
Remove author being explicitly passed, use one from connection
vivbak Apr 19, 2024
f594167
Plural cohort, cohort_template fields
vivbak Apr 19, 2024
ae19d20
map to dict later, pass model
vivbak Apr 19, 2024
ef9d85e
execute -> execute_many
vivbak Apr 19, 2024
c8021f7
Fix type of id on Cohort model
vivbak Apr 19, 2024
f82103a
New model for creating cohorts, fix project missing bug, rename Cohor…
vivbak Apr 19, 2024
8dac650
Fix lint, although interesting that my linter didnt catch it
vivbak Apr 19, 2024
8be79e7
Fix type hint, cohort_ids should be int not str
vivbak Apr 19, 2024
3d9c0b6
Fix create_analysis, so it can handle no sgs as inputs
vivbak Apr 19, 2024
7ba3371
Create two where_strs, remove unused import
vivbak Apr 19, 2024
64349cd
Remove sgs from cohortinternal model!
vivbak Apr 19, 2024
ac89b83
Add strict param to id transform function
vivbak Apr 19, 2024
37d300c
redundant, no? remove a type check that already happened above
vivbak Apr 19, 2024
b2c5efb
Add typing to function, raise value error if template nor projects pr…
vivbak Apr 19, 2024
7db7f7b
Fetch assay external ids too
vivbak Apr 21, 2024
1b7632b
Move escape_like_terms to utils, apply to contains filter
vivbak Apr 21, 2024
3c2af5f
Implement Internal and External models for all objects. Move transfor…
vivbak Apr 22, 2024
86e9237
Use UTC for test_query_with_creation_date comparisons
jmarshall Apr 22, 2024
b10f10e
Add basic tests for scripts/create_custom_cohort.py
jmarshall Apr 23, 2024
6f78b9b
Add separate CohortCriteria/Template.to_internal() tests
jmarshall Apr 24, 2024
9aaaa10
Switch get_project_write_connection to get_project_readonly_connectio…
vivbak Apr 28, 2024
ed2d840
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Apr 28, 2024
b7b9d1a
Return [] if no template meets criteria, switch return order of proje…
vivbak Apr 28, 2024
f52af30
Cohort ID should be None in dry-run mode
vivbak Apr 28, 2024
c347309
sample_types -> sample_type
vivbak Apr 29, 2024
49b146d
Merge dev (in particular, the empty list SQL fix) into custom-cohorts
jmarshall Apr 29, 2024
5f5cf23
Only run _query_cohort_ids query if :analysis_ids will be non-empty
jmarshall Apr 30, 2024
0d1757f
Improve mocking in test_cohort_builder.py tests
jmarshall Apr 29, 2024
f793927
Escape metacharacters in icontains query string (and add tests)
jmarshall Apr 30, 2024
b8e1252
Make --dry-run an argumentless flag option
jmarshall Apr 30, 2024
9fcc2a9
Bump version: 6.9.1 → 6.10.0
vivbak Apr 30, 2024
dfe3c20
Merge branch 'custom-cohorts' of github.com:populationgenomics/sample…
vivbak Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ It comprises three key components:

As of Jan 15, 2024 this schema should reflect the data structure on the tables:

![Database Structure](resources/2024-01-15_db-diagram.png)
![Database Structure](resources/schemav7.7.png.png)

You can also find this at [DbDiagram](https://dbdiagram.io/d/Metamist-Schema-v6-6-2-65a48ac7ac844320aee60d16).
You can also find this at [DbDiagram](https://dbdiagram.io/d/Metamist-Schema-v7-7-6600c875ae072629ced6a1fc).

The codebase contains the following modules worth noting:

Expand Down
10 changes: 10 additions & 0 deletions api/graphql/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class GraphQLFilter(Generic[T]):
gte: T | None = None
lt: T | None = None
lte: T | None = None
contains: T | None = None
vivbak marked this conversation as resolved.
Show resolved Hide resolved
icontains: T | None = None

def all_values(self):
"""
Expand All @@ -38,6 +40,10 @@ def all_values(self):
v.append(self.lt)
if self.lte:
v.append(self.lte)
if self.contains:
v.append(self.contains)
if self.icontains:
v.append(self.icontains)

return v

Expand All @@ -53,6 +59,8 @@ def to_internal_filter(self, f: Callable[[T], Any] = None):
gte=f(self.gte) if self.gte else None,
lt=f(self.lt) if self.lt else None,
lte=f(self.lte) if self.lte else None,
contains=f(self.contains) if self.contains else None,
icontains=f(self.icontains) if self.icontains else None,
)

return GenericFilter(
Expand All @@ -63,6 +71,8 @@ def to_internal_filter(self, f: Callable[[T], Any] = None):
gte=self.gte,
lt=self.lt,
lte=self.lte,
contains=self.contains,
icontains=self.icontains,
)


Expand Down
7 changes: 5 additions & 2 deletions api/graphql/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,13 @@ async def load_projects_for_ids(project_ids: list[int], connection) -> list[Proj
"""
pttable = ProjectPermissionsTable(connection)
projects = await pttable.get_and_check_access_to_projects_for_ids(
user=connection.user, project_ids=project_ids, readonly=True
user=connection.author, project_ids=project_ids, readonly=True
vivbak marked this conversation as resolved.
Show resolved Hide resolved
)

p_by_id = {p.id: p for p in projects}
return [p_by_id.get(p) for p in project_ids]
projects = [p_by_id.get(p) for p in project_ids]

return [p for p in projects if p is not None]


@connected_data_loader(LoaderKeys.FAMILIES_FOR_PARTICIPANTS)
Expand Down
221 changes: 217 additions & 4 deletions api/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# type: ignore
# flake8: noqa
# pylint: disable=no-value-for-parameter,redefined-builtin,missing-function-docstring,unused-argument
# pylint: disable=no-value-for-parameter,redefined-builtin,missing-function-docstring,unused-argument,too-many-lines
vivbak marked this conversation as resolved.
Show resolved Hide resolved
"""
Schema for GraphQL.

Expand All @@ -22,13 +22,15 @@
AnalysisLayer,
AnalysisRunnerLayer,
AssayLayer,
CohortLayer,
FamilyLayer,
SampleLayer,
SequencingGroupLayer,
)
from db.python.tables.analysis import AnalysisFilter
from db.python.tables.analysis_runner import AnalysisRunnerFilter
from db.python.tables.assay import AssayFilter
from db.python.tables.cohort import CohortFilter, CohortTemplateFilter
from db.python.tables.project import ProjectPermissionsTable
from db.python.tables.sample import SampleFilter
from db.python.tables.sequencing_group import SequencingGroupFilter
Expand All @@ -38,6 +40,8 @@
AnalysisInternal,
AssayInternal,
AuditLogInternal,
CohortInternal,
CohortTemplateInternal,
FamilyInternal,
ParticipantInternal,
Project,
Expand All @@ -46,6 +50,11 @@
)
from models.models.analysis_runner import AnalysisRunnerInternal
from models.models.sample import sample_id_transform_to_raw
from models.utils.cohort_id_format import cohort_id_format, cohort_id_transform_to_raw
from models.utils.cohort_template_id_format import (
cohort_template_id_format,
cohort_template_id_transform_to_raw,
)
from models.utils.sample_id_format import sample_id_format
from models.utils.sequencing_group_id_format import (
sequencing_group_id_format,
Expand Down Expand Up @@ -73,6 +82,87 @@ async def m(info: Info) -> list[str]:
GraphQLEnum = strawberry.type(type('GraphQLEnum', (object,), enum_methods))


# Create cohort GraphQL model
@strawberry.type
class GraphQLCohort:
"""Cohort GraphQL model"""

id: str
name: str
description: str
author: str

@staticmethod
def from_internal(internal: CohortInternal) -> 'GraphQLCohort':
return GraphQLCohort(
id=cohort_id_format(internal.id),
name=internal.name,
description=internal.description,
author=internal.author,
)

@strawberry.field()
async def template(self, info: Info, root: 'Cohort') -> 'GraphQLCohortTemplate':
connection = info.context['connection']
template = await CohortLayer(connection).get_template_by_cohort_id(
cohort_id_transform_to_raw(root.id)
)

return GraphQLCohortTemplate.from_internal(template)

@strawberry.field()
async def sequencing_groups(
self, info: Info, root: 'Cohort'
) -> list['GraphQLSequencingGroup']:
connection = info.context['connection']
cohort_layer = CohortLayer(connection)
sg_ids = await cohort_layer.get_cohort_sequencing_group_ids(
cohort_id_transform_to_raw(root.id)
)

sg_layer = SequencingGroupLayer(connection)
sequencing_groups = await sg_layer.get_sequencing_groups_by_ids(sg_ids)
return [GraphQLSequencingGroup.from_internal(sg) for sg in sequencing_groups]

@strawberry.field()
async def analyses(self, info: Info, root: 'Cohort') -> list['GraphQLAnalysis']:
vivbak marked this conversation as resolved.
Show resolved Hide resolved
connection = info.context['connection']
connection.project = root.project
internal_analysis = await AnalysisLayer(connection).query(
AnalysisFilter(
cohort_id=GenericFilter(in_=[cohort_id_transform_to_raw(root.id)]),
)
)
return [GraphQLAnalysis.from_internal(a) for a in internal_analysis]

@strawberry.field()
async def project(self, info: Info, root: 'Cohort') -> 'GraphQLProject':
loader = info.context[LoaderKeys.PROJECTS_FOR_IDS]
project = await loader.load(root.project)
return GraphQLProject.from_internal(project)


# Create cohort template GraphQL model
@strawberry.type
class GraphQLCohortTemplate:
"""CohortTemplate GraphQL model"""

id: str
name: str
description: str
criteria: strawberry.scalars.JSON

@staticmethod
def from_internal(internal: CohortTemplateInternal) -> 'GraphQLCohortTemplate':
# At this point, the object that comes in doesn't have an ID field.
return GraphQLCohortTemplate(
id=cohort_template_id_format(internal.id),
name=internal.name,
description=internal.description,
criteria=internal.criteria,
)


@strawberry.type
class GraphQLProject:
"""Project GraphQL model"""
Expand Down Expand Up @@ -243,6 +333,35 @@ async def analyses(
)
return [GraphQLAnalysis.from_internal(a) for a in internal_analysis]

@strawberry.field()
async def cohorts(
self,
info: Info,
root: 'Project',
id: GraphQLFilter[int] | None = None,
name: GraphQLFilter[str] | None = None,
author: GraphQLFilter[str] | None = None,
template_id: GraphQLFilter[int] | None = None,
timestamp: GraphQLFilter[datetime.datetime] | None = None,
vivbak marked this conversation as resolved.
Show resolved Hide resolved
) -> list['GraphQLCohort']:
connection = info.context['connection']
connection.project = root.id

c_filter = CohortFilter(
id=id.to_internal_filter(cohort_id_transform_to_raw) if id else None,
name=name.to_internal_filter() if name else None,
author=author.to_internal_filter() if author else None,
template_id=(
template_id.to_internal_filter(cohort_template_id_transform_to_raw)
if template_id
else None
),
timestamp=timestamp.to_internal_filter() if timestamp else None,
)

cohorts = await CohortLayer(connection).query(c_filter)
return [GraphQLCohort.from_internal(c) for c in cohorts]


@strawberry.type
class GraphQLAuditLog:
Expand Down Expand Up @@ -472,11 +591,16 @@ async def participant(

@strawberry.field
async def assays(
self, info: Info, root: 'GraphQLSample', type: GraphQLFilter[str] | None = None
self,
info: Info,
root: 'GraphQLSample',
type: GraphQLFilter[str] | None = None,
meta: GraphQLMetaFilter | None = None,
) -> list['GraphQLAssay']:
loader_assays_for_sample_ids = info.context[LoaderKeys.ASSAYS_FOR_SAMPLES]
filter_ = AssayFilter(
type=type.to_internal_filter() if type else None,
meta=meta,
)
assays = await loader_assays_for_sample_ids.load(
{'id': root.internal_id, 'filter': filter_}
Expand Down Expand Up @@ -607,7 +731,8 @@ async def assays(
self, info: Info, root: 'GraphQLSequencingGroup'
) -> list['GraphQLAssay']:
loader = info.context[LoaderKeys.ASSAYS_FOR_SEQUENCING_GROUPS]
return await loader.load(root.internal_id)
assays = await loader.load(root.internal_id)
return [GraphQLAssay.from_internal(assay) for assay in assays]


@strawberry.type
Expand Down Expand Up @@ -696,13 +821,92 @@ async def project(


@strawberry.type
class Query:
class Query: # entry point to graphql.
"""GraphQL Queries"""

@strawberry.field()
def enum(self, info: Info) -> GraphQLEnum:
return GraphQLEnum()

@strawberry.field()
async def cohort_templates(
self,
info: Info,
id: GraphQLFilter[str] | None = None,
project: GraphQLFilter[str] | None = None,
) -> list[GraphQLCohortTemplate]:
connection = info.context['connection']
cohort_layer = CohortLayer(connection)

ptable = ProjectPermissionsTable(connection)
project_name_map: dict[str, int] = {}
project_filter = None
if project:
project_names = project.all_values()
projects = await ptable.get_and_check_access_to_projects_for_names(
user=connection.author, project_names=project_names, readonly=True
)
project_name_map = {p.name: p.id for p in projects}
project_filter = project.to_internal_filter(
lambda pname: project_name_map[pname]
)

filter_ = CohortTemplateFilter(
id=(
id.to_internal_filter(cohort_template_id_transform_to_raw)
if id
else None
),
project=project_filter,
)

cohort_templates = await cohort_layer.query_cohort_templates(filter_)
return [
GraphQLCohortTemplate.from_internal(cohort_template)
for cohort_template in cohort_templates
]

@strawberry.field()
async def cohorts(
self,
info: Info,
id: GraphQLFilter[str] | None = None,
project: GraphQLFilter[str] | None = None,
name: GraphQLFilter[str] | None = None,
author: GraphQLFilter[str] | None = None,
template_id: GraphQLFilter[int] | None = None,
) -> list[GraphQLCohort]:
connection = info.context['connection']
cohort_layer = CohortLayer(connection)

ptable = ProjectPermissionsTable(connection)
project_name_map: dict[str, int] = {}
project_filter = None
if project:
project_names = project.all_values()
projects = await ptable.get_and_check_access_to_projects_for_names(
user=connection.author, project_names=project_names, readonly=True
)
project_name_map = {p.name: p.id for p in projects}
project_filter = project.to_internal_filter(
lambda pname: project_name_map[pname]
)

filter_ = CohortFilter(
id=id.to_internal_filter(cohort_id_transform_to_raw) if id else None,
name=name.to_internal_filter() if name else None,
project=project_filter,
author=author.to_internal_filter() if author else None,
template_id=(
template_id.to_internal_filter(cohort_template_id_transform_to_raw)
if template_id
else None
),
)

cohorts = await cohort_layer.query(filter_)
return [GraphQLCohort.from_internal(cohort) for cohort in cohorts]

@strawberry.field()
async def project(self, info: Info, name: str) -> GraphQLProject:
connection = info.context['connection']
Expand Down Expand Up @@ -761,6 +965,7 @@ async def sample(
samples = await slayer.query(filter_)
vivbak marked this conversation as resolved.
Show resolved Hide resolved
return [GraphQLSample.from_internal(sample) for sample in samples]

# pylint: disable=too-many-arguments
@strawberry.field
async def sequencing_groups(
self,
Expand All @@ -772,6 +977,10 @@ async def sequencing_groups(
technology: GraphQLFilter[str] | None = None,
platform: GraphQLFilter[str] | None = None,
active_only: GraphQLFilter[bool] | None = None,
created_on: GraphQLFilter[datetime.date] | None = None,
assay_meta: GraphQLMetaFilter | None = None,
has_cram: bool | None = None,
has_gvcf: bool | None = None,
) -> list[GraphQLSequencingGroup]:
connection = info.context['connection']
sglayer = SequencingGroupLayer(connection)
Expand Down Expand Up @@ -812,6 +1021,10 @@ async def sequencing_groups(
if active_only
else GenericFilter(eq=True)
),
created_on=created_on.to_internal_filter() if created_on else None,
assay_meta=assay_meta,
has_cram=has_cram,
has_gvcf=has_gvcf,
)
sgs = await sglayer.query(filter_)
return [GraphQLSequencingGroup.from_internal(sg) for sg in sgs]
Expand Down
1 change: 1 addition & 0 deletions api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from api.routes.analysis_runner import router as analysis_runner_router
from api.routes.assay import router as assay_router
from api.routes.billing import router as billing_router
from api.routes.cohort import router as cohort_router
from api.routes.enum import router as enum_router
from api.routes.family import router as family_router
from api.routes.imports import router as import_router
Expand Down
Loading
Loading