Skip to content

Commit

Permalink
Merge pull request #142 from bcgsc/bugfix/SDEV-4041_gsc_report_fail_P…
Browse files Browse the repository at this point in the history
…OG1650

Bugfix/sdev 4041 gsc report fail pog1650
  • Loading branch information
dustinbleile authored Dec 6, 2023
2 parents 12bb8c2 + 808df51 commit 699321a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 45 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/automerge_back_to_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This will trigger when master branch gets updated, it will make a PR to develop
name: Auto-pr-master-develop

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the develop branch
pull_request:
branches: [master]
types: [closed]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
merge-master-to-dev:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# If master pull request is merged
if: github.event.pull_request.merged == true

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
ref: develop

- name: Set Git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "Github Actions"
- name: Reset master branch
run: |
git fetch origin master:master
git reset --hard master
- name: Read and set version
id: versioning
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo ::set-output name=tag::${PACKAGE_VERSION}
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
branch: merge-master-to-dev-${{ steps.versioning.outputs.tag }}
title: update develop from master-${{ steps.versioning.outputs.tag }}
commit-message: auto PR master to develop
2 changes: 1 addition & 1 deletion ipr/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ def get_spec(self) -> Dict:
"""
Get the current IPR spec, for the purposes of current report upload fields
"""
return self.request(f'/spec.json', method='GET')
return self.request('/spec.json', method='GET')
79 changes: 37 additions & 42 deletions ipr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@
)
from .summary import summarize
from .therapeutic_options import create_therapeutic_options
from .types import IprVariant, KbMatch, IprGene
from .types import IprVariant, KbMatch
from .util import LOG_LEVELS, logger, trim_empty_values

CACHE_GENE_MINIMUM = 5000
RENAMED_GENE_PROPERTIES = {
# old_name: new_name
'cancerRelated': 'kbStatementRelated',
'cancerGene': 'cancerGeneListMatch',
}


def file_path(path: str) -> str:
Expand Down Expand Up @@ -105,9 +110,9 @@ def command_interface() -> None:
)


def clean_unsupported_content(upload_content: Dict, ipr_spec: json = {}) -> Dict:
"""
Remove unsupported content. This content is either added to facilitate creation
def clean_unsupported_content(upload_content: Dict, ipr_spec: Dict = {}) -> Dict:
"""Remove unsupported content.
This content is either added to facilitate creation
or to support upcoming and soon to be supported content that we would like
to implement but is not yet supported by the upload
"""
Expand All @@ -121,30 +126,39 @@ def clean_unsupported_content(upload_content: Dict, ipr_spec: json = {}) -> Dict
genes_spec = ipr_spec['components']['schemas']['genesCreate']['properties'].keys()

# check what ipr report upload expects and adjust contents to match
# TODO: remove this code after IPR-API is released with DEVSU-2143
if 'cancerRelated' in genes_spec:
for gene in upload_content['genes']:
logger.warning(
f"Renamed property 'kbStatementRelated' to 'cancerRelated' for upload in gene {gene['name']}"
)
gene['cancerRelated'] = gene['kbStatementRelated']
gene.pop('kbStatementRelated')
if 'cancerGene' in genes_spec:
for gene in upload_content['genes']:
for old_name, new_name in RENAMED_GENE_PROPERTIES.items():
if old_name in genes_spec:
logger.warning(
f"Renamed property 'cancerGeneListMatch' to 'cancerGene' for upload in gene {gene['name']}"
f"Legacy IPR - Renaming property {new_name} to {old_name} for compatibility to ipr_spec"
)
gene['cancerGene'] = gene['cancerGeneListMatch']
gene.pop('cancerGeneListMatch')
for gene in upload_content['genes']:
if new_name in gene:
gene[old_name] = gene[new_name]
gene.pop(new_name)
else:
outdate_properties = 0
for gene in upload_content['genes']:
if old_name in gene:
gene[new_name] = gene[old_name]
gene.pop(old_name)
outdate_properties += 1
if outdate_properties:
logger.warning(
f"Renamed property {old_name} to {new_name} on {outdate_properties} genes for ipr_spec"
)

# remove any unhandled incompatible keys
ipr_gene_keys = IprGene.__required_keys__ | IprGene.__optional_keys__
unexpected_keys = [item for item in genes_spec if item not in ipr_gene_keys]
removed_keys: Dict[str, int] = {}
for gene in upload_content['genes']:
for key in unexpected_keys:
if key in gene.keys():
logger.warning(f"Unexpected property '{key}' removed from gene {gene['name']}")
gene.pop(key)
unsupported_keys = [key for key in gene.keys() if key not in genes_spec]
for key in unsupported_keys:
if key in removed_keys:
removed_keys[key] += 1
else:
removed_keys[key] = 1
gene.pop(key)
for key, count in removed_keys.items():
logger.warning(f"IPR unsupported property '{key}' removed from {count} genes.")

drop_columns = ['variant', 'variantType', 'histogramImage']
# DEVSU-2034 - use a 'displayName'
Expand Down Expand Up @@ -375,25 +389,6 @@ def ipr_report(
logger.info('fetching gene annotations')
gene_information = get_gene_information(graphkb_conn, sorted(genes_with_variants))

# handle old and new column names coming in from GraphKB.
# TODO: remove this code when GraphKB is released with KBDEV-1136
def update_old_field_name(gene):
if 'cancerRelated' in gene.keys():
logger.warning(
f"Property 'kbStatementRelated' obtained as 'cancerRelated' in gene {gene['name']}"
)
gene['kbStatementRelated'] = gene['cancerRelated']
gene.pop('cancerRelated')
if 'cancerGene' in gene.keys():
logger.warning(
f"Property 'cancerGeneListMatch' obtained as 'cancerGene' in gene {gene['name']}"
)
gene['cancerGeneListMatch'] = gene['cancerGene']
gene.pop('cancerGene')
return gene

gene_information = [update_old_field_name(gene) for gene in gene_information]

if generate_therapeutics:
logger.info('generating therapeutic options')
targets = create_therapeutic_options(graphkb_conn, gkb_matches, all_variants)
Expand Down
2 changes: 1 addition & 1 deletion 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.1
version = 3.12.2
author_email = [email protected]
author = ipr
maintainer_email = [email protected]
Expand Down
11 changes: 10 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

from ipr.connection import IprConnection
from ipr.main import command_interface
from ipr.types import IprGene

from .constants import EXCLUDE_INTEGRATION_TESTS


def get_test_spec():
ipr_spec = {'components': {'schemas': {'genesCreate': {'properties': {}}}}}
ipr_gene_keys = IprGene.__required_keys__ | IprGene.__optional_keys__
for key in ipr_gene_keys:
ipr_spec['components']['schemas']['genesCreate']['properties'][key] = ""
return ipr_spec


def get_test_file(name: str) -> str:
return os.path.join(os.path.dirname(__file__), 'test_data', name)

Expand Down Expand Up @@ -65,7 +74,7 @@ def report_upload_content(tmp_path_factory) -> Dict:
],
):
with patch.object(IprConnection, 'upload_report', new=mock):
with patch.object(IprConnection, 'get_spec', return_value={}):
with patch.object(IprConnection, 'get_spec', return_value=get_test_spec()):
command_interface()

assert mock.called
Expand Down

0 comments on commit 699321a

Please sign in to comment.