Skip to content

Commit

Permalink
Merge pull request #145 from bcgsc/release-v3.12.3
Browse files Browse the repository at this point in the history
Release v3.13.0
  • Loading branch information
elewis2 authored Feb 29, 2024
2 parents 699321a + 685b92d commit 4d75e9e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
7 changes: 3 additions & 4 deletions ipr/annotate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
handles annotating variants with annotation information from graphkb
"""

from requests.exceptions import HTTPError

from graphkb import GraphKBConnection
Expand Down Expand Up @@ -55,7 +56,6 @@ def get_ipr_statements_from_variants(
if not matches:
return []
rows = []

statements = get_statements_from_variants(graphkb_conn, matches)
existing_statements = {s['@rid'] for s in statements}

Expand All @@ -76,9 +76,8 @@ def get_ipr_statements_from_variants(
for ipr_row in convert_statements_to_alterations(
graphkb_conn, inferred_statements, disease_name, convert_to_rid_set(inferred_matches)
):
new_row = KbMatch({'kbData': {'inferred': True}})
new_row.update(ipr_row)
rows.append(new_row)
ipr_row['kbData']['inferred'] = True
rows.append(ipr_row)

return rows

Expand Down
1 change: 1 addition & 0 deletions ipr/inputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Read/Validate the variant input files
"""

import json
import jsonschema
import os
Expand Down
31 changes: 28 additions & 3 deletions ipr/ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Contains functions specific to formatting reports for IPR that are unlikely to be used
by other reporting systems
"""

from graphkb import GraphKBConnection
from graphkb import statement as gkb_statement
from graphkb import vocab as gkb_vocab
Expand Down Expand Up @@ -130,6 +131,23 @@ def convert_statements_to_alterations(
# GERO-318 - add all IPR-A evidence equivalents to the approvedTherapy flag
approved = set([ev for (ev, ipr) in ev_map.items() if ipr == 'IPR-A'])

# get the recruitment status for any trial associated with a statement
clinical_trials = [
s['subject']['@rid'] for s in statements if s['subject']['@class'] == 'ClinicalTrial'
]
recruitment_statuses = {}
if clinical_trials:
clinical_trials = list(set(clinical_trials))
for rid in clinical_trials:
query_result = graphkb_conn.query(
{
'target': {'target': 'ClinicalTrial', 'filters': {'@rid': rid}},
'returnProperties': ['@rid', 'recruitmentStatus'],
}
)
if query_result:
recruitment_statuses[rid] = query_result[0]['recruitmentStatus']

for statement in statements:
variants = [c for c in statement['conditions'] if c['@class'] in VARIANT_CLASSES]
diseases = [c for c in statement['conditions'] if c['@class'] == 'Disease']
Expand Down Expand Up @@ -175,13 +193,20 @@ def convert_statements_to_alterations(
'reference': pmid,
'relevance': statement['relevance']['displayName'],
'kbRelevanceId': statement['relevance']['@rid'],
'externalSource': str(statement['source'].get('displayName', ''))
if statement['source']
else None,
'externalSource': (
str(statement['source'].get('displayName', ''))
if statement['source']
else None
),
'externalStatementId': statement.get('sourceId'),
'reviewStatus': statement.get('reviewStatus'),
'kbData': {},
}
)
if statement['relevance']['name'] == 'eligibility':
row['kbData']['recruitment_status'] = recruitment_statuses.get(
row['kbContextId'], 'not found'
)
rows.append(row)
return rows

Expand Down
1 change: 1 addition & 0 deletions ipr/therapeutic_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
upload variant and report information to IPR
"""

import pandas
from graphkb import GraphKBConnection
from typing import Dict, List, Sequence
Expand Down
3 changes: 2 additions & 1 deletion ipr/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Union
from typing import List, Optional, Union, Dict

try:
from typing import TypedDict # type: ignore
Expand Down Expand Up @@ -30,6 +30,7 @@ class KbMatch(TypedDict):
externalSource: str
externalStatementId: str
reviewStatus: str
kbData: Optional[Dict]


class IprGene(TypedDict):
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ known_standard_library = requests

[metadata]
name = ipr
version = 3.12.2
version = 3.13.0
author_email = ipr@bcgsc.ca
author = ipr
maintainer_email = ipr@bcgsc.ca
Expand All @@ -28,7 +28,7 @@ long_description_content_type = text/markdown

[options]
packages = find:
python_requires = >=3.6
python_requires = >=3.7
dependency_links = []
include_package_data = True
install_requires =
Expand Down
12 changes: 10 additions & 2 deletions tests/test_ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,18 @@ def base_graphkb_statement(
},
],
"evidence": [],
"subject": None,
"subject": {
"@class": 'dummy_value',
"@rid": "101:010",
"displayName": 'dummy_display_name',
},
"source": None,
"sourceId": None,
"relevance": {"@rid": relevance_rid, "displayName": "relevance_display_name"},
"relevance": {
"@rid": relevance_rid,
"displayName": "relevance_display_name",
"name": "relevance_name",
},
"@rid": "statement_rid",
}
)
Expand Down

0 comments on commit 4d75e9e

Please sign in to comment.