Skip to content

Commit

Permalink
Fix pid sgid map api (#680)
Browse files Browse the repository at this point in the history
* Fix participant to sg_id api bug

* Remove sample id format import

* Add sequencing type option to endpoint

* Bump version: 6.6.2 → 6.7.0
  • Loading branch information
EddieLF authored Feb 11, 2024
1 parent 3c77ac2 commit 5debebf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
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 = 6.6.2
current_version = 6.7.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
24 changes: 14 additions & 10 deletions api/routes/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from api.utils.export import ExportType
from db.python.layers.participant import ParticipantLayer
from models.models.participant import ParticipantUpsert
from models.models.sample import sample_id_format
from models.models.sequencing_group import sequencing_group_id_format

router = APIRouter(prefix='/participant', tags=['participant'])

Expand Down Expand Up @@ -111,35 +111,37 @@ async def update_many_participant_external_ids(


@router.get(
'/{project}/external-pid-to-internal-sample-id',
operation_id='getExternalParticipantIdToInternalSampleId',
'/{project}/external-pid-to-sg-id',
operation_id='getExternalParticipantIdToSequencingGroupId',
tags=['seqr'],
)
async def get_external_participant_id_to_internal_sample_id(
async def get_external_participant_id_to_sequencing_group_id(
project: str,
sequencing_type: str = None,
export_type: ExportType = ExportType.JSON,
flip_columns: bool = False,
connection: Connection = get_project_readonly_connection,
):
"""
Get csv / tsv export of external_participant_id to internal_sample_id
Get csv / tsv export of external_participant_id to sequencing_group_id
Get a map of {external_participant_id} -> {internal_sample_id}
useful to matching joint-called samples in the matrix table to the participant
Get a map of {external_participant_id} -> {sequencing_group_id}
useful to matching joint-called sequencing groups in the matrix table to the participant
Return a list not dictionary, because dict could lose
participants with multiple samples.
:param sequencing_type: Leave empty to get all sequencing types
:param flip_columns: Set to True when exporting for seqr
"""
player = ParticipantLayer(connection)
# this wants project ID (connection.project)
assert connection.project
m = await player.get_external_participant_id_to_internal_sequencing_group_id_map(
project=connection.project
project=connection.project, sequencing_type=sequencing_type
)

rows = [[pid, sample_id_format(sid)] for pid, sid in m]
rows = [[pid, sequencing_group_id_format(sgid)] for pid, sgid in m]
if flip_columns:
rows = [r[::-1] for r in rows]

Expand All @@ -151,7 +153,9 @@ async def get_external_participant_id_to_internal_sample_id(
writer.writerows(rows)

ext = export_type.get_extension()
filename = f'{project}-participant-to-sample-map-{date.today().isoformat()}{ext}'
filename = f'{project}-participant-to-sequencing-group-map-{date.today().isoformat()}{ext}'
if sequencing_type:
filename = f'{project}-{sequencing_type}-participant-to-sequencing-group-map-{date.today().isoformat()}{ext}'
return StreamingResponse(
# stream the whole file at once, because it's all in memory anyway
iter([output.getvalue()]),
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from db.python.utils import get_logger

# This tag is automatically updated by bump2version
_VERSION = '6.6.2'
_VERSION = '6.7.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 @@
6.6.2
6.7.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='6.6.2',
version='6.7.0',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down
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": "6.6.2",
"version": "6.7.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.3",
Expand Down

0 comments on commit 5debebf

Please sign in to comment.