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

Release - Cohort SG active only filter & SQL table font update #1019

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 7.7.0
current_version = 7.8.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
17 changes: 13 additions & 4 deletions api/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
ReadAccessRoles,
)
from models.models.sample import sample_id_transform_to_raw
from models.models.sequencing_group import SequencingGroupUpsertInternal
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,
Expand Down Expand Up @@ -180,7 +179,10 @@ async def template(

@strawberry.field()
async def sequencing_groups(
self, info: Info[GraphQLContext, 'Query'], root: 'GraphQLCohort'
self,
info: Info[GraphQLContext, 'Query'],
root: 'GraphQLCohort',
active_only: GraphQLFilter[bool] | None = None,
) -> list['GraphQLSequencingGroup']:
connection = info.context['connection']
cohort_layer = CohortLayer(connection)
Expand All @@ -189,7 +191,12 @@ async def sequencing_groups(
)

sg_layer = SequencingGroupLayer(connection)
sequencing_groups = await sg_layer.get_sequencing_groups_by_ids(sg_ids)
filter = SequencingGroupFilter(
id=GenericFilter(in_=sg_ids),
active_only=active_only.to_internal_filter() if active_only else None,
)
sequencing_groups = await sg_layer.query(filter_=filter)

return [GraphQLSequencingGroup.from_internal(sg) for sg in sequencing_groups]

@strawberry.field()
Expand Down Expand Up @@ -1103,13 +1110,14 @@ class GraphQLSequencingGroup:
platform: str
meta: strawberry.scalars.JSON
external_ids: strawberry.scalars.JSON
archived: bool | None

internal_id: strawberry.Private[int]
sample_id: strawberry.Private[int]

@staticmethod
def from_internal(
internal: SequencingGroupInternal | SequencingGroupUpsertInternal,
internal: SequencingGroupInternal,
) -> 'GraphQLSequencingGroup':
if not internal.id:
raise ValueError('SequencingGroup must have an id')
Expand All @@ -1121,6 +1129,7 @@ def from_internal(
platform=internal.platform,
meta=internal.meta,
external_ids=internal.external_ids or {},
archived=internal.archived,
# internal
internal_id=internal.id,
sample_id=internal.sample_id,
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from db.python.utils import get_logger

# This tag is automatically updated by bump2version
_VERSION = '7.7.0'
_VERSION = '7.8.0'


logger = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion deploy/python/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.7.0
7.8.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
name=PKG,
# This tag is automatically updated by bump2version
version='7.7.0',
version='7.8.0',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down
103 changes: 102 additions & 1 deletion test/test_cohort.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
from test.testbase import DbIsolatedTest, run_as_sync

from pymysql.err import IntegrityError

from db.python.filters import GenericFilter
from db.python.layers import CohortLayer, SampleLayer
from db.python.layers.sequencing_group import SequencingGroupLayer
from db.python.tables.cohort import CohortFilter
from models.models import (
PRIMARY_EXTERNAL_ORG,
Expand All @@ -21,6 +21,7 @@
)
from models.utils.cohort_id_format import cohort_id_format
from models.utils.sequencing_group_id_format import sequencing_group_id_format
from test.testbase import DbIsolatedTest, run_as_sync


class TestCohortBasic(DbIsolatedTest):
Expand Down Expand Up @@ -487,3 +488,103 @@ async def test_query_cohort(self):
self.assertEqual(2, len(result))
self.assertIn(self.sA.sequencing_groups[0].id, result)
self.assertIn(self.sB.sequencing_groups[0].id, result)


class TestCohortGraphql(DbIsolatedTest):
"""Test custom cohort endpoints that need some sequencing groups already set up"""

# pylint: disable=too-many-instance-attributes

@run_as_sync
async def setUp(self):
super().setUp()
self.cohortl = CohortLayer(self.connection)
self.samplel = SampleLayer(self.connection)
self.sgl = SequencingGroupLayer(self.connection)

@run_as_sync
async def test_cohort_with_archived_sgs(self):
"""Check that archived sequencing groups are shown by default in cohorts"""
sample_model = SampleUpsertInternal(
meta={},
external_ids={PRIMARY_EXTERNAL_ORG: 'EXID1'},
type='blood',
sequencing_groups=[
SequencingGroupUpsertInternal(
type='genome',
technology='short-read',
platform='illumina',
meta={},
assays=[],
),
SequencingGroupUpsertInternal(
type='exome',
technology='short-read',
platform='illumina',
meta={},
assays=[],
),
],
)

sample = await self.samplel.upsert_sample(sample_model)
assert sample.sequencing_groups
sg1 = sample.sequencing_groups[0].id
sg2 = sample.sequencing_groups[1].id

assert sg1, sg2

cohort_name = 'Archive test cohort 1'
await self.cohortl.create_cohort_from_criteria(
project_to_write=self.project_id,
description='Genome & Exome cohort',
cohort_name=cohort_name,
dry_run=False,
cohort_criteria=CohortCriteriaInternal(
projects=[self.project_id],
sg_type=['genome', 'exome'],
),
)

# Archive the first sequencing group
await self.sgl.archive_sequencing_group(sg1)

query_result_incl_archived = await self.run_graphql_query_async(
"""
query Cohort($name: StrGraphQLFilter) {
cohorts(name:$name) {
name
sequencingGroups {
id
archived
}
}
}
""",
{'name': {'eq': cohort_name}},
)

incl_archived_cohort = query_result_incl_archived['cohorts'][0]
self.assertEqual(incl_archived_cohort['name'], cohort_name)
self.assertEqual(len(incl_archived_cohort['sequencingGroups']), 2)
self.assertEqual(incl_archived_cohort['sequencingGroups'][0]['archived'], True)
self.assertEqual(incl_archived_cohort['sequencingGroups'][1]['archived'], False)

query_result_excl_archived = await self.run_graphql_query_async(
"""
query Cohort($name: StrGraphQLFilter, $active_only: BoolGraphQLFilter) {
cohorts(name:$name) {
name
sequencingGroups(activeOnly: $active_only) {
id
archived
}
}
}
""",
{'name': {'eq': cohort_name}, 'active_only': {'eq': True}},
)

excl_archived_cohort = query_result_excl_archived['cohorts'][0]
self.assertEqual(len(excl_archived_cohort['sequencingGroups']), 1)
self.assertEqual(excl_archived_cohort['sequencingGroups'][0]['archived'], False)
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamist",
"version": "7.7.0",
"version": "7.8.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.11.5",
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/report/chart/TableFromQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export function TableFromQuery(props: TableProps) {
columns={columns}
getRowId={(row) => row.__index}
density="compact"
sx={{
fontFamily: 'monospace',
}}
/>
)
}
Loading