pori-python 1.0.0__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. {pori_python-1.0.0/pori_python.egg-info → pori_python-1.1.0}/PKG-INFO +9 -5
  2. {pori_python-1.0.0 → pori_python-1.1.0}/README.md +8 -4
  3. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/util.py +7 -1
  4. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/annotate.py +102 -88
  5. pori_python-1.1.0/pori_python/ipr/constants.py +28 -0
  6. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/inputs.py +84 -9
  7. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/ipr.py +1 -1
  8. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/main.py +38 -143
  9. {pori_python-1.0.0 → pori_python-1.1.0/pori_python.egg-info}/PKG-INFO +9 -5
  10. {pori_python-1.0.0 → pori_python-1.1.0}/setup.cfg +1 -1
  11. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_annotate.py +92 -2
  12. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_inputs.py +75 -27
  13. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_main.py +1 -0
  14. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_upload.py +5 -4
  15. pori_python-1.0.0/pori_python/ipr/constants.py +0 -12
  16. {pori_python-1.0.0 → pori_python-1.1.0}/LICENSE +0 -0
  17. {pori_python-1.0.0 → pori_python-1.1.0}/MANIFEST.in +0 -0
  18. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/__init__.py +0 -0
  19. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/__init__.py +0 -0
  20. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/constants.py +0 -0
  21. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/genes.py +0 -0
  22. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/match.py +0 -0
  23. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/py.typed +0 -0
  24. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/statement.py +0 -0
  25. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/graphkb/vocab.py +0 -0
  26. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/__init__.py +0 -0
  27. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/connection.py +0 -0
  28. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/content.spec.json +0 -0
  29. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/py.typed +0 -0
  30. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/summary.py +0 -0
  31. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/therapeutic_options.py +0 -0
  32. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/ipr/util.py +0 -0
  33. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python/types.py +0 -0
  34. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python.egg-info/SOURCES.txt +0 -0
  35. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python.egg-info/dependency_links.txt +0 -0
  36. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python.egg-info/entry_points.txt +0 -0
  37. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python.egg-info/requires.txt +0 -0
  38. {pori_python-1.0.0 → pori_python-1.1.0}/pori_python.egg-info/top_level.txt +0 -0
  39. {pori_python-1.0.0 → pori_python-1.1.0}/pyproject.toml +0 -0
  40. {pori_python-1.0.0 → pori_python-1.1.0}/setup.py +0 -0
  41. {pori_python-1.0.0 → pori_python-1.1.0}/tests/__init__.py +0 -0
  42. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/__init__.py +0 -0
  43. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/data.py +0 -0
  44. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_genes.py +0 -0
  45. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_graphkb.py +0 -0
  46. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_match.py +0 -0
  47. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_statement.py +0 -0
  48. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_util.py +0 -0
  49. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_graphkb/test_vocab.py +0 -0
  50. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/__init__.py +0 -0
  51. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/constants.py +0 -0
  52. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_connection.py +0 -0
  53. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_ipr.py +0 -0
  54. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_probe.py +0 -0
  55. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_summary.py +0 -0
  56. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/test_util.py +0 -0
  57. {pori_python-1.0.0 → pori_python-1.1.0}/tests/test_ipr/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pori_python
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Home-page: https://github.com/bcgsc/pori_python
5
5
  Author-email: dat@bcgsc.ca
6
6
  Maintainer-email: dat@bcgsc.ca
@@ -97,7 +97,7 @@ Note that IPR tests will try to use the BCGSC production GraphKB API by default.
97
97
  If you want to test interaction with a different instance, you will need to
98
98
  set the GraphKB variables.
99
99
 
100
- Set EXCLUDE vars to 1 if you don't want to run these tests.
100
+ Set EXCLUDE vars to 1 if you don't want to run these tests.
101
101
  ONCOKB and BCGSC tests are enabled by default.
102
102
 
103
103
  ```bash
@@ -107,17 +107,21 @@ export IPR_URL='http://localhost:8081/api'
107
107
  export GRAPHKB_USER='pori_admin'
108
108
  export GRAPHKB_PASS='pori_admin'
109
109
  export GRAPHKB_URL='http://localhost:8080/api'
110
- EXCLUDE_BCGSC_TESTS = 1
111
- EXCLUDE_ONCOKB_TESTS = 1
110
+ export EXCLUDE_BCGSC_TESTS=1
111
+ export EXCLUDE_ONCOKB_TESTS=1
112
112
  ```
113
113
 
114
114
  If you want to run tests that upload reports to a live IPR instance,
115
115
  specify the url of the IPR API you want to use and set the test var to 1.
116
116
  These tests are disabled by default.
117
117
 
118
+ The created reports are deleted by default. If you want to keep them,
119
+ set DELETE_UPLOAD_TEST_REPORTS to 0 in the env.
120
+
118
121
  ```bash
119
122
  export IPR_TEST_URL='http://localhost:8081/api'
120
- INCLUDE_UPLOAD_TESTS = 1
123
+ export INCLUDE_UPLOAD_TESTS=1
124
+ export DELETE_UPLOAD_TEST_REPORTS=0
121
125
  ```
122
126
 
123
127
  ```bash
@@ -51,7 +51,7 @@ Note that IPR tests will try to use the BCGSC production GraphKB API by default.
51
51
  If you want to test interaction with a different instance, you will need to
52
52
  set the GraphKB variables.
53
53
 
54
- Set EXCLUDE vars to 1 if you don't want to run these tests.
54
+ Set EXCLUDE vars to 1 if you don't want to run these tests.
55
55
  ONCOKB and BCGSC tests are enabled by default.
56
56
 
57
57
  ```bash
@@ -61,17 +61,21 @@ export IPR_URL='http://localhost:8081/api'
61
61
  export GRAPHKB_USER='pori_admin'
62
62
  export GRAPHKB_PASS='pori_admin'
63
63
  export GRAPHKB_URL='http://localhost:8080/api'
64
- EXCLUDE_BCGSC_TESTS = 1
65
- EXCLUDE_ONCOKB_TESTS = 1
64
+ export EXCLUDE_BCGSC_TESTS=1
65
+ export EXCLUDE_ONCOKB_TESTS=1
66
66
  ```
67
67
 
68
68
  If you want to run tests that upload reports to a live IPR instance,
69
69
  specify the url of the IPR API you want to use and set the test var to 1.
70
70
  These tests are disabled by default.
71
71
 
72
+ The created reports are deleted by default. If you want to keep them,
73
+ set DELETE_UPLOAD_TEST_REPORTS to 0 in the env.
74
+
72
75
  ```bash
73
76
  export IPR_TEST_URL='http://localhost:8081/api'
74
- INCLUDE_UPLOAD_TESTS = 1
77
+ export INCLUDE_UPLOAD_TESTS=1
78
+ export DELETE_UPLOAD_TEST_REPORTS=0
75
79
  ```
76
80
 
77
81
  ```bash
@@ -163,11 +163,16 @@ class GraphKBConnection:
163
163
  # about catching OSError as well as ConnectionError:
164
164
  # https://stackoverflow.com/questions/74253820
165
165
  attempts = range(15)
166
+ need_refresh_login = False
166
167
  for attempt in attempts:
167
168
  if attempt > 0:
168
169
  time.sleep(2) # wait between retries
169
170
  try:
170
- self.refresh_login()
171
+
172
+ if need_refresh_login:
173
+ self.refresh_login()
174
+ need_refresh_login = False
175
+
171
176
  self.request_count += 1
172
177
  resp = requests.request(
173
178
  method, url, headers=self.headers, timeout=timeout, **kwargs
@@ -175,6 +180,7 @@ class GraphKBConnection:
175
180
  if resp.status_code == 401 or resp.status_code == 403:
176
181
  logger.debug(f"/{endpoint} - {resp.status_code} - retrying")
177
182
  # try to re-login if the token expired
183
+ need_refresh_login = True
178
184
  continue
179
185
  else:
180
186
  break
@@ -8,7 +8,7 @@ from requests.exceptions import HTTPError
8
8
 
9
9
  from pandas import isnull
10
10
  from tqdm import tqdm
11
- from typing import Dict, List, Sequence, cast
11
+ from typing import Dict, List, Sequence
12
12
 
13
13
  from pori_python.graphkb import GraphKBConnection
14
14
  from pori_python.graphkb import match as gkb_match
@@ -20,13 +20,14 @@ from pori_python.types import (
20
20
  IprCopyVariant,
21
21
  IprExprVariant,
22
22
  IprSignatureVariant,
23
+ IprSmallMutationVariant,
23
24
  IprStructuralVariant,
24
25
  KbMatch,
25
26
  Statement,
26
27
  Variant,
27
28
  )
28
29
 
29
- from .constants import TMB_HIGH_CATEGORY
30
+ from .constants import TMB_SIGNATURE
30
31
  from .ipr import convert_statements_to_alterations
31
32
  from .util import convert_to_rid_set, logger
32
33
 
@@ -308,92 +309,6 @@ def annotate_positional_variants(
308
309
  return alterations
309
310
 
310
311
 
311
- def annotate_msi(
312
- graphkb_conn: GraphKBConnection,
313
- disease_matches: List[str],
314
- msi_category: str = "microsatellite instability",
315
- ) -> List[KbMatch]:
316
- """Annotate microsatellite instablity from GraphKB in the IPR alterations format.
317
-
318
- Match to GraphKb Category variants with similar names
319
- Args:
320
- graphkb_conn (GraphKBConnection): the graphkb api connection object
321
- disease_matches (list.str): GraphKB disease RIDs
322
- msi_category (str): such as 'microsatellite instability'
323
-
324
- Returns:
325
- list of kbMatches records for IPR
326
- """
327
- gkb_matches = []
328
- msi_categories = graphkb_conn.query(
329
- {
330
- "target": {
331
- "target": "CategoryVariant",
332
- "filters": {
333
- "reference1": {
334
- "target": "Signature",
335
- "filters": {"name": msi_category},
336
- }
337
- },
338
- },
339
- "queryType": "similarTo",
340
- "returnProperties": ["@rid", "displayName"],
341
- }
342
- )
343
- if msi_categories:
344
- msi_variants = [cast(Variant, var) for var in msi_categories]
345
- for ipr_row in get_ipr_statements_from_variants(
346
- graphkb_conn, msi_variants, disease_matches
347
- ):
348
- ipr_row["variant"] = msi_category
349
- ipr_row["variantType"] = "msi"
350
- gkb_matches.append(ipr_row)
351
- return gkb_matches
352
-
353
-
354
- def annotate_tmb(
355
- graphkb_conn: GraphKBConnection,
356
- disease_matches: List[str],
357
- category: str = TMB_HIGH_CATEGORY,
358
- ) -> List[KbMatch]:
359
- """Annotate Tumour Mutation Burden (tmb) categories from GraphKB in the IPR alterations format.
360
-
361
- Match to GraphKb Category variants with similar names
362
- Args:
363
- graphkb_conn (GraphKBConnection): the graphkb api connection object
364
- disease_matches (list.str): GraphKB disease RIDs
365
- category: such as 'high mutation burden'
366
-
367
- Returns:
368
- list of kbMatches records for IPR
369
- """
370
- gkb_matches = []
371
- categories = graphkb_conn.query(
372
- {
373
- "target": {
374
- "target": "CategoryVariant",
375
- "filters": {
376
- "reference1": {
377
- "target": "Signature",
378
- "filters": {"OR": [{"name": category}, {"displayName": category}]},
379
- }
380
- },
381
- },
382
- "queryType": "similarTo",
383
- "returnProperties": ["@rid", "displayName"],
384
- }
385
- )
386
- if categories:
387
- cat_variants = [cast(Variant, var) for var in categories]
388
- for ipr_row in get_ipr_statements_from_variants(
389
- graphkb_conn, cat_variants, disease_matches
390
- ):
391
- ipr_row["variant"] = category
392
- ipr_row["variantType"] = "tmb"
393
- gkb_matches.append(ipr_row)
394
- return gkb_matches
395
-
396
-
397
312
  def annotate_signature_variants(
398
313
  graphkb_conn: GraphKBConnection,
399
314
  disease_matches: List[str],
@@ -425,6 +340,20 @@ def annotate_signature_variants(
425
340
  variant["variantTypeName"],
426
341
  reference_class="Signature",
427
342
  )
343
+ # KBDEV-1246
344
+ # Keep support for 'high mutation burden' until statement datafix
345
+ if (
346
+ variant["signatureName"] == TMB_SIGNATURE
347
+ and TMB_SIGNATURE != 'high mutation burden'
348
+ ):
349
+ matched_variants.extend(
350
+ gkb_match.match_category_variant(
351
+ graphkb_conn,
352
+ 'high mutation burden',
353
+ variant["variantTypeName"],
354
+ reference_class="Signature",
355
+ )
356
+ )
428
357
  # Matching GKB Variants to GKB Statements
429
358
  for ipr_row in get_ipr_statements_from_variants(
430
359
  graphkb_conn, matched_variants, disease_matches
@@ -444,3 +373,88 @@ def annotate_signature_variants(
444
373
  )
445
374
 
446
375
  return alterations
376
+
377
+
378
+ def annotate_variants(
379
+ graphkb_conn: GraphKBConnection,
380
+ interactive: bool = False,
381
+ disease_matches: List[str] = [],
382
+ signature_variants: List[IprSignatureVariant] = [],
383
+ small_mutations: List[IprSmallMutationVariant] = [],
384
+ structural_variants: List[IprStructuralVariant] = [],
385
+ copy_variants: List[IprCopyVariant] = [],
386
+ expression_variants: List[IprExprVariant] = [],
387
+ ) -> List[Hashabledict]:
388
+ """Annotating (matching to GraphKB) all observed variants, per type
389
+ Args:
390
+ graphkb_conn: the graphkb api connection object
391
+ interactive: progressbars for interactive users
392
+ disease_matches: list of matched disease RID strings,
393
+ signature_variants: signature CategoryVariants (incl. cosmic, dmmr, hla, tmb & msi),
394
+ small_mutations: small PositionalVariants,
395
+ structural_variants: structural PositionalVariants (incl. fusion)
396
+ copy_variants: copy number CategoryVariants (e.g. of type 'copy loss', 'copy gain', etc.),
397
+ expression_variants: expression CategoryVariant (e.g. of type 'overexpression', etc. ),
398
+ Returns:
399
+ A list of matched Statements to GraphKB
400
+ """
401
+ gkb_matches: List[Hashabledict] = []
402
+
403
+ # MATCHING SIGNATURE CATEGORY VARIANTS
404
+ logger.info(f"annotating {len(signature_variants)} signatures")
405
+ gkb_matches.extend(
406
+ annotate_signature_variants(
407
+ graphkb_conn, disease_matches, signature_variants, show_progress=interactive
408
+ )
409
+ )
410
+ logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
411
+
412
+ # MATCHING SMALL MUTATIONS
413
+ logger.info(f"annotating {len(small_mutations)} small mutations")
414
+ gkb_matches.extend(
415
+ annotate_positional_variants(
416
+ graphkb_conn, small_mutations, disease_matches, show_progress=interactive
417
+ )
418
+ )
419
+ logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
420
+
421
+ # MATCHING STRUCTURAL VARIANTS
422
+ logger.info(f"annotating {len(structural_variants)} structural variants")
423
+ gkb_matches.extend(
424
+ annotate_positional_variants(
425
+ graphkb_conn,
426
+ structural_variants,
427
+ disease_matches,
428
+ show_progress=interactive,
429
+ )
430
+ )
431
+ logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
432
+
433
+ # MATCHING COPY VARIANTS
434
+ logger.info(f"annotating {len(copy_variants)} copy variants")
435
+ gkb_matches.extend(
436
+ [
437
+ Hashabledict(copy_var)
438
+ for copy_var in annotate_copy_variants(
439
+ graphkb_conn, disease_matches, copy_variants, show_progress=interactive
440
+ )
441
+ ]
442
+ )
443
+ logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
444
+
445
+ # MATCHING EXPRESSION VARIANTS
446
+ logger.info(f"annotating {len(expression_variants)} expression variants")
447
+ gkb_matches.extend(
448
+ [
449
+ Hashabledict(exp_var)
450
+ for exp_var in annotate_expression_variants(
451
+ graphkb_conn,
452
+ disease_matches,
453
+ expression_variants,
454
+ show_progress=interactive,
455
+ )
456
+ ]
457
+ )
458
+ logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
459
+
460
+ return gkb_matches
@@ -0,0 +1,28 @@
1
+ DEFAULT_URL = "https://iprstaging-api.bcgsc.ca/api"
2
+ GERMLINE_BASE_TERMS = ("pharmacogenomic", "cancer predisposition") # based on graphkb.constants
3
+ VARIANT_CLASSES = {"Variant", "CategoryVariant", "PositionalVariant", "CatalogueVariant"}
4
+
5
+ # all possible values for review status are: ['pending', 'not required', 'passed', 'failed', 'initial']
6
+ FAILED_REVIEW_STATUS = "failed"
7
+
8
+ # Signatures
9
+ COSMIC_SIGNATURE_VARIANT_TYPE = "high signature"
10
+ HLA_SIGNATURE_VARIANT_TYPE = "signature present"
11
+ TMB_SIGNATURE = "mutation burden"
12
+ TMB_SIGNATURE_HIGH_THRESHOLD = (
13
+ 10.0 # genomic mutations per mb - https://www.bcgsc.ca/jira/browse/GERO-296
14
+ )
15
+ TMB_SIGNATURE_VARIANT_TYPE = "high signature"
16
+ # Mapping micro-satellite from pipeline terms to GraphKB terms
17
+ MSI_MAPPING = {
18
+ 'microsatellite instability': { # MSI
19
+ 'displayName': 'microsatellite instability high signature',
20
+ 'signatureName': 'microsatellite instability',
21
+ 'variantTypeName': 'high signature',
22
+ },
23
+ 'microsatellite stable': { # MSS
24
+ 'displayName': 'microsatellite stable signature present',
25
+ 'signatureName': 'microsatellite stable',
26
+ 'variantTypeName': 'signature present',
27
+ },
28
+ }
@@ -7,10 +7,11 @@ from __future__ import annotations
7
7
  import json
8
8
  import jsonschema
9
9
  import os
10
- import re
11
10
  import pandas as pd
11
+ import re
12
12
  from Bio.Data.IUPACData import protein_letters_3to1
13
- from typing import Callable, Dict, Iterable, List, Set, Tuple, cast
13
+ from numpy import nan
14
+ from typing import Any, Callable, Dict, Iterable, List, Set, Tuple, cast
14
15
 
15
16
  from pori_python.graphkb.match import INPUT_COPY_CATEGORIES, INPUT_EXPRESSION_CATEGORIES
16
17
  from pori_python.types import (
@@ -26,6 +27,9 @@ from .constants import (
26
27
  COSMIC_SIGNATURE_VARIANT_TYPE,
27
28
  DEFAULT_URL,
28
29
  HLA_SIGNATURE_VARIANT_TYPE,
30
+ MSI_MAPPING,
31
+ TMB_SIGNATURE,
32
+ TMB_SIGNATURE_VARIANT_TYPE,
29
33
  )
30
34
  from .util import hash_key, logger, pandas_falsy
31
35
 
@@ -442,19 +446,13 @@ def preprocess_cosmic(rows: Iterable[Dict]) -> Iterable[Dict]:
442
446
  Process cosmic inputs into preformatted signature inputs
443
447
  Note: Cosmic and dMMR already evaluated against thresholds in gsc_report
444
448
  """
445
- cosmic = set()
446
- for row in rows:
447
- if not set(SIGV_COSMIC).issubset(row.keys()):
448
- continue
449
- cosmic.add(row[SIGV_COSMIC[0]])
450
-
451
449
  return [
452
450
  {
453
451
  "displayName": f"{signature} {COSMIC_SIGNATURE_VARIANT_TYPE}",
454
452
  "signatureName": signature,
455
453
  "variantTypeName": COSMIC_SIGNATURE_VARIANT_TYPE,
456
454
  }
457
- for signature in cosmic
455
+ for signature in rows
458
456
  ]
459
457
 
460
458
 
@@ -480,6 +478,83 @@ def preprocess_hla(rows: Iterable[Dict]) -> Iterable[Dict]:
480
478
  ]
481
479
 
482
480
 
481
+ def preprocess_tmb(
482
+ tmb_high: float, tmburMutationBurden: Dict = None, genomeTmb: str = None
483
+ ) -> Iterable[Dict]:
484
+ """
485
+ Process tumour mutation burden (tmb) input(s) into preformatted signature input.
486
+ Get compared to threshold; signature CategoryVariant created only if threshold met.
487
+ """
488
+ tmbur_tmb_val = nan
489
+ tmb_val = 0.0
490
+
491
+ # tmburMutationBurden, for backwards compatibility purpose
492
+ # derived from tmburMutationBurden["genomeIndelTmb"] + tmburMutationBurden["genomeSnvTmb"]
493
+ if tmburMutationBurden:
494
+ try:
495
+ tmbur_tmb_val = float(
496
+ tmburMutationBurden["genomeIndelTmb"] + tmburMutationBurden["genomeSnvTmb"]
497
+ )
498
+ if genomeTmb == None:
499
+ logger.error(
500
+ "backwards compatibility: deriving genomeTmb from tmburMutationBurden genomeIndelTmb + genomeSnvTmb"
501
+ )
502
+ tmb_val = tmbur_tmb_val
503
+ except Exception as err:
504
+ logger.error(f"tmburMutationBurden parsing failure: {err}")
505
+
506
+ # genomeTmb
507
+ # SDEV-4811 - mutation burden is now expected to be uploaded in genomeTmb as mutations/megabase
508
+ if genomeTmb != None and genomeTmb != "":
509
+ try:
510
+ tmb_val = float(genomeTmb)
511
+ if tmburMutationBurden and tmbur_tmb_val != tmb_val:
512
+ logger.warning(
513
+ f"genomeTmb given {tmb_val} does not match tmburMutationBurden TMB {tmbur_tmb_val}"
514
+ )
515
+ except Exception as err:
516
+ logger.error(f"genomeTmb parsing failure {genomeTmb}: {err}")
517
+
518
+ # comparaing tmb_val to threshold
519
+ # Signature CategoryVariant created only if threshold met
520
+ if tmb_val >= tmb_high:
521
+ return [
522
+ {
523
+ "displayName": f'{TMB_SIGNATURE} {TMB_SIGNATURE_VARIANT_TYPE}',
524
+ "signatureName": TMB_SIGNATURE,
525
+ "variantTypeName": TMB_SIGNATURE_VARIANT_TYPE,
526
+ }
527
+ ]
528
+ return []
529
+
530
+
531
+ def preprocess_msi(msi: Any) -> Iterable[Dict]:
532
+ """
533
+ Process micro-satellite input into preformatted signature input.
534
+ Both msi & mss gets mapped to corresponding GraphKB Signature CategoryVariants.
535
+ """
536
+ if msi:
537
+
538
+ # MSI category is given from upstream (only one msi variant per library)
539
+ if isinstance(msi, list):
540
+ # msi is given as a list of one dict
541
+ msi_cat = msi[0].get("kbCategory", "")
542
+ elif isinstance(msi, str):
543
+ # msi is given as a string
544
+ msi_cat = msi
545
+ else:
546
+ # msi is given as a dict; uncatched error if not.
547
+ msi_cat = msi.get("kbCategory", "")
548
+
549
+ msi_variant = MSI_MAPPING.get(msi_cat, None)
550
+
551
+ # Signature CategoryVariant created either for msi or mss
552
+ if msi_variant:
553
+ return [msi_variant]
554
+
555
+ return []
556
+
557
+
483
558
  def check_variant_links(
484
559
  small_mutations: List[IprSmallMutationVariant],
485
560
  expression_variants: List[IprExprVariant],
@@ -653,4 +653,4 @@ def get_kb_disease_matches(
653
653
  logger.error(msg)
654
654
  raise ValueError(msg)
655
655
 
656
- return disease_matches
656
+ return list(disease_matches)
@@ -15,23 +15,15 @@ from pori_python.types import (
15
15
  Hashabledict,
16
16
  IprCopyVariant,
17
17
  IprExprVariant,
18
- IprFusionVariant,
19
18
  IprSignatureVariant,
20
19
  IprSmallMutationVariant,
20
+ IprStructuralVariant,
21
21
  IprVariant,
22
- KbMatchSections,
23
22
  )
24
23
 
25
- from .annotate import (
26
- annotate_copy_variants,
27
- annotate_expression_variants,
28
- annotate_msi,
29
- annotate_positional_variants,
30
- annotate_signature_variants,
31
- annotate_tmb,
32
- )
24
+ from .annotate import annotate_variants
33
25
  from .connection import IprConnection
34
- from .constants import DEFAULT_URL, TMB_HIGH, TMB_HIGH_CATEGORY
26
+ from .constants import DEFAULT_URL, TMB_SIGNATURE_HIGH_THRESHOLD
35
27
  from .inputs import (
36
28
  check_comparators,
37
29
  check_variant_links,
@@ -39,9 +31,11 @@ from .inputs import (
39
31
  preprocess_cosmic,
40
32
  preprocess_expression_variants,
41
33
  preprocess_hla,
34
+ preprocess_msi,
42
35
  preprocess_signature_variants,
43
36
  preprocess_small_mutations,
44
37
  preprocess_structural_variants,
38
+ preprocess_tmb,
45
39
  validate_report_content,
46
40
  )
47
41
  from .ipr import (
@@ -223,7 +217,6 @@ def clean_unsupported_content(upload_content: Dict, ipr_spec: Dict = {}) -> Dict
223
217
  "structuralVariants",
224
218
  "probeResults",
225
219
  "signatureVariants",
226
- "msi",
227
220
  ]
228
221
  for variant_list_section in VARIANT_LIST_KEYS:
229
222
  for variant in upload_content.get(variant_list_section, []):
@@ -295,6 +288,7 @@ def ipr_report(
295
288
  include_nonspecific_project: bool = False,
296
289
  include_nonspecific_template: bool = False,
297
290
  allow_partial_matches: bool = False,
291
+ tmb_high: float = TMB_SIGNATURE_HIGH_THRESHOLD,
298
292
  ) -> Dict:
299
293
  """Run the matching and create the report JSON for upload to IPR.
300
294
 
@@ -323,6 +317,7 @@ def ipr_report(
323
317
  include_nonspecific_project: if include_ipr_variant_text is True, if no project match is found use project-nonspecific variant comment
324
318
  include_nonspecific_template: if include_ipr_variant_text is True, if no template match is found use template-nonspecific variant comment
325
319
  allow_partial_matches: allow matches to statements where not all conditions are satisfied
320
+ tmb_high: mutation burden threshold/cutoff to qualify as 'high'
326
321
  Returns:
327
322
  ipr_conn.upload_report return dictionary
328
323
  """
@@ -339,23 +334,30 @@ def ipr_report(
339
334
  logger.error("Failed schema check - report variants may be corrupted or unmatched.")
340
335
  logger.error(f"Failed schema check: {err}")
341
336
 
342
- # validate the input variants
343
- signatureVariants: List[IprSignatureVariant] = preprocess_signature_variants(
337
+ # INPUT VARIANTS VALIDATION & PREPROCESSING (OBSERVED BIOMARKERS)
338
+ signature_variants: List[IprSignatureVariant] = preprocess_signature_variants(
344
339
  [
345
- *preprocess_cosmic(content.get("cosmicSignatures", [])),
340
+ *preprocess_cosmic(content.get("cosmicSignatures", [])), # includes dMMR
346
341
  *preprocess_hla(content.get("hlaTypes", [])),
342
+ *preprocess_tmb(
343
+ tmb_high,
344
+ content.get("tmburMutationBurden", None), # old tmb pipeline
345
+ content.get("genomeTmb", None), # newer tmb pipeline
346
+ ),
347
+ *preprocess_msi(content.get("msi", None)),
347
348
  ]
348
349
  )
349
350
  small_mutations: List[IprSmallMutationVariant] = preprocess_small_mutations(
350
351
  content.get("smallMutations", [])
351
352
  )
352
- structural_variants: List[IprFusionVariant] = preprocess_structural_variants(
353
+ structural_variants: List[IprStructuralVariant] = preprocess_structural_variants(
353
354
  content.get("structuralVariants", [])
354
355
  )
355
356
  copy_variants: List[IprCopyVariant] = preprocess_copy_variants(content.get("copyVariants", []))
356
357
  expression_variants: List[IprExprVariant] = preprocess_expression_variants(
357
358
  content.get("expressionVariants", [])
358
359
  )
360
+ # Additional checks
359
361
  if expression_variants:
360
362
  check_comparators(content, expression_variants)
361
363
 
@@ -387,138 +389,28 @@ def ipr_report(
387
389
  # (Will raise uncatched error if no match)
388
390
  disease_matches: list[str] = get_kb_disease_matches(graphkb_conn, kb_disease_match)
389
391
 
390
- # GKB MATCHING
391
- gkb_matches: List[Hashabledict] = []
392
-
393
- # MATCHING TMB
394
- tmb_variant: IprVariant = {} # type: ignore
395
- tmb_matches = []
396
- if "tmburMutationBurden" in content.keys():
397
- tmb_val = 0.0
398
- tmb = {}
399
- try:
400
- tmb = content.get("tmburMutationBurden", {})
401
- tmb_val = tmb["genomeIndelTmb"] + tmb["genomeSnvTmb"]
402
- except Exception as err:
403
- logger.error(f"tmburMutationBurden parsing failure: {err}")
404
-
405
- if tmb_val >= TMB_HIGH:
406
- logger.warning(
407
- f"GERO-296 - tmburMutationBurden high -checking graphkb matches for {TMB_HIGH_CATEGORY}"
408
- )
409
- if not tmb.get("key"):
410
- tmb["key"] = TMB_HIGH_CATEGORY
411
- if not tmb.get("kbCategory"):
412
- tmb["kbCategory"] = TMB_HIGH_CATEGORY
413
-
414
- # GERO-296 - try matching to graphkb
415
- tmb_matches = annotate_tmb(graphkb_conn, disease_matches, TMB_HIGH_CATEGORY)
416
- if tmb_matches:
417
- tmb_variant["kbCategory"] = TMB_HIGH_CATEGORY # type: ignore
418
- tmb_variant["variant"] = TMB_HIGH_CATEGORY
419
- tmb_variant["key"] = tmb["key"]
420
- tmb_variant["variantType"] = "tmb"
421
- logger.info(
422
- f"GERO-296 '{TMB_HIGH_CATEGORY}' matches {len(tmb_matches)} statements."
423
- )
424
- gkb_matches.extend([Hashabledict(tmb_statement) for tmb_statement in tmb_matches])
425
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
426
-
427
- # MATCHING MSI
428
- msi = content.get("msi", [])
429
- msi_matches = []
430
- msi_variant: IprVariant = {} # type: ignore
431
- if msi:
432
- # only one msi variant per library
433
- if isinstance(msi, list):
434
- msi_cat = msi[0].get("kbCategory")
435
- elif isinstance(msi, str):
436
- msi_cat = msi
437
- else:
438
- msi_cat = msi.get("kbCategory")
439
- msi_variant = msi.copy()
440
- logger.info(f"Matching GKB msi {msi_cat}")
441
- msi_matches = annotate_msi(graphkb_conn, disease_matches, msi_cat)
442
- if msi_matches:
443
- msi_variant["kbCategory"] = msi_cat # type: ignore
444
- msi_variant["variant"] = msi_cat
445
- msi_variant["key"] = msi_cat
446
- msi_variant["variantType"] = "msi"
447
- logger.info(f"GERO-295 '{msi_cat}' matches {len(msi_matches)} msi statements.")
448
- gkb_matches.extend([Hashabledict(msi) for msi in msi_matches])
449
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
450
-
451
- # MATCHING SIGNATURE CATEGORY VARIANTS
452
- logger.info(f"annotating {len(signatureVariants)} signatures")
453
- gkb_matches.extend(
454
- annotate_signature_variants(
455
- graphkb_conn, disease_matches, signatureVariants, show_progress=interactive
456
- )
392
+ # GKB MATCHING (AKA ANNOTATION)
393
+ gkb_matches: List[Hashabledict] = annotate_variants(
394
+ graphkb_conn=graphkb_conn,
395
+ interactive=interactive,
396
+ disease_matches=disease_matches,
397
+ # Variants, per type:
398
+ signature_variants=signature_variants,
399
+ small_mutations=small_mutations,
400
+ structural_variants=structural_variants,
401
+ copy_variants=copy_variants,
402
+ expression_variants=expression_variants,
457
403
  )
458
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
459
404
 
460
- # MATCHING SMALL MUTATIONS
461
- logger.info(f"annotating {len(small_mutations)} small mutations")
462
- gkb_matches.extend(
463
- annotate_positional_variants(
464
- graphkb_conn, small_mutations, disease_matches, show_progress=interactive
465
- )
466
- )
467
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
468
-
469
- # MATCHING STRUCTURAL VARIANTS
470
- logger.info(f"annotating {len(structural_variants)} structural variants")
471
- gkb_matches.extend(
472
- annotate_positional_variants(
473
- graphkb_conn,
474
- structural_variants,
475
- disease_matches,
476
- show_progress=interactive,
477
- )
478
- )
479
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
480
-
481
- # MATCHING COPY VARIANTS
482
- logger.info(f"annotating {len(copy_variants)} copy variants")
483
- gkb_matches.extend(
484
- [
485
- Hashabledict(copy_var)
486
- for copy_var in annotate_copy_variants(
487
- graphkb_conn, disease_matches, copy_variants, show_progress=interactive
488
- )
489
- ]
490
- )
491
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
492
-
493
- # MATCHING EXPRESSION VARIANTS
494
- logger.info(f"annotating {len(expression_variants)} expression variants")
495
- gkb_matches.extend(
496
- [
497
- Hashabledict(exp_var)
498
- for exp_var in annotate_expression_variants(
499
- graphkb_conn,
500
- disease_matches,
501
- expression_variants,
502
- show_progress=interactive,
503
- )
504
- ]
505
- )
506
- logger.debug(f"\tgkb_matches: {len(gkb_matches)}")
507
-
508
- # ALL VARIANTS
405
+ # GROUPING ALL VARIANTS TOGETHER
509
406
  all_variants: Sequence[IprVariant] = [
510
407
  *copy_variants,
511
408
  *expression_variants,
512
- *signatureVariants,
409
+ *signature_variants,
513
410
  *small_mutations,
514
411
  *structural_variants,
515
412
  ] # type: ignore
516
413
 
517
- if msi_matches:
518
- all_variants.append(msi_variant) # type: ignore
519
- if tmb_matches:
520
- all_variants.append(tmb_variant) # type: ignore
521
-
522
414
  # GKB_MATCHES FILTERING
523
415
  if match_germline:
524
416
  # verify germline kb statements matched germline observed variants, not somatic variants
@@ -576,13 +468,16 @@ def ipr_report(
576
468
  comments_list.append(ipr_comments)
577
469
  comments = {'comments': "\n".join(comments_list)}
578
470
 
471
+ # REFORMATTING KBMATCHES
472
+ # kbMatches -> kbMatches, kbMatchedStatements & kbStatementMatchedConditions
473
+ kb_matched_sections = get_kb_matches_sections(
474
+ gkb_matches, allow_partial_matches=allow_partial_matches
475
+ )
476
+
579
477
  # OUTPUT CONTENT
580
478
  # thread safe deep-copy the original content
581
479
  output = json.loads(json.dumps(content))
582
480
 
583
- kb_matched_sections = get_kb_matches_sections(
584
- gkb_matches, allow_partial_matches=allow_partial_matches
585
- )
586
481
  output.update(kb_matched_sections)
587
482
  output.update(
588
483
  {
@@ -604,7 +499,7 @@ def ipr_report(
604
499
  structural_variants, gkb_matches, gene_information
605
500
  )
606
501
  ],
607
- "signatureVariants": [trim_empty_values(s) for s in signatureVariants],
502
+ "signatureVariants": [trim_empty_values(s) for s in signature_variants],
608
503
  "genes": gene_information,
609
504
  "genomicAlterationsIdentified": key_alterations,
610
505
  "variantCounts": variant_counts,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pori_python
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Home-page: https://github.com/bcgsc/pori_python
5
5
  Author-email: dat@bcgsc.ca
6
6
  Maintainer-email: dat@bcgsc.ca
@@ -97,7 +97,7 @@ Note that IPR tests will try to use the BCGSC production GraphKB API by default.
97
97
  If you want to test interaction with a different instance, you will need to
98
98
  set the GraphKB variables.
99
99
 
100
- Set EXCLUDE vars to 1 if you don't want to run these tests.
100
+ Set EXCLUDE vars to 1 if you don't want to run these tests.
101
101
  ONCOKB and BCGSC tests are enabled by default.
102
102
 
103
103
  ```bash
@@ -107,17 +107,21 @@ export IPR_URL='http://localhost:8081/api'
107
107
  export GRAPHKB_USER='pori_admin'
108
108
  export GRAPHKB_PASS='pori_admin'
109
109
  export GRAPHKB_URL='http://localhost:8080/api'
110
- EXCLUDE_BCGSC_TESTS = 1
111
- EXCLUDE_ONCOKB_TESTS = 1
110
+ export EXCLUDE_BCGSC_TESTS=1
111
+ export EXCLUDE_ONCOKB_TESTS=1
112
112
  ```
113
113
 
114
114
  If you want to run tests that upload reports to a live IPR instance,
115
115
  specify the url of the IPR API you want to use and set the test var to 1.
116
116
  These tests are disabled by default.
117
117
 
118
+ The created reports are deleted by default. If you want to keep them,
119
+ set DELETE_UPLOAD_TEST_REPORTS to 0 in the env.
120
+
118
121
  ```bash
119
122
  export IPR_TEST_URL='http://localhost:8081/api'
120
- INCLUDE_UPLOAD_TESTS = 1
123
+ export INCLUDE_UPLOAD_TESTS=1
124
+ export DELETE_UPLOAD_TEST_REPORTS=0
121
125
  ```
122
126
 
123
127
  ```bash
@@ -17,7 +17,7 @@ known_standard_library = requests
17
17
 
18
18
  [metadata]
19
19
  name = pori_python
20
- version = 1.0.0
20
+ version = 1.1.0
21
21
  url = https://github.com/bcgsc/pori_python
22
22
  author_email = dat@bcgsc.ca
23
23
  maintainer_email = dat@bcgsc.ca
@@ -2,7 +2,15 @@ import os
2
2
  import pytest
3
3
 
4
4
  from pori_python.graphkb import GraphKBConnection
5
- from pori_python.ipr.annotate import annotate_positional_variants
5
+ from pori_python.ipr.annotate import annotate_positional_variants, annotate_signature_variants
6
+ from pori_python.ipr.constants import (
7
+ COSMIC_SIGNATURE_VARIANT_TYPE,
8
+ HLA_SIGNATURE_VARIANT_TYPE,
9
+ MSI_MAPPING,
10
+ TMB_SIGNATURE,
11
+ TMB_SIGNATURE_VARIANT_TYPE,
12
+ )
13
+ from pori_python.ipr.inputs import preprocess_signature_variants
6
14
  from pori_python.types import IprSmallMutationVariant
7
15
  from .test_ipr import DISEASE_RIDS
8
16
 
@@ -113,9 +121,91 @@ class TestAnnotation:
113
121
  assert not nonsense, f"nonsense matched to {key}: {TP53_MUT_DICT[key]}"
114
122
  assert matched, f"should have matched in {key}: {TP53_MUT_DICT[key]}"
115
123
 
124
+ def test_annotate_signature_variants_cosmic(self, graphkb_conn):
125
+ """Test a Cosmic Signature CVs with known GKB statements"""
126
+ signature = 'SBS10B'
127
+ cosmic = annotate_signature_variants(
128
+ graphkb_conn,
129
+ DISEASE_RIDS,
130
+ preprocess_signature_variants(
131
+ [
132
+ {
133
+ "displayName": f"{signature} {COSMIC_SIGNATURE_VARIANT_TYPE}",
134
+ "signatureName": signature,
135
+ "variantTypeName": COSMIC_SIGNATURE_VARIANT_TYPE,
136
+ }
137
+ ]
138
+ ),
139
+ )
140
+ assert len(cosmic) != 0
141
+
142
+ @pytest.mark.skip(reason="no GKB statement for dMMR Signature CVs yet")
143
+ def test_annotate_signature_variants_dmmr(self, graphkb_conn):
144
+ """Test a dMMR (from Cosmic) Signature CVs with known GKB statements"""
145
+ signature = 'DMMR'
146
+ dmmr = annotate_signature_variants(
147
+ graphkb_conn,
148
+ DISEASE_RIDS,
149
+ preprocess_signature_variants(
150
+ [
151
+ {
152
+ "displayName": f"{signature} {COSMIC_SIGNATURE_VARIANT_TYPE}",
153
+ "signatureName": signature,
154
+ "variantTypeName": COSMIC_SIGNATURE_VARIANT_TYPE,
155
+ }
156
+ ]
157
+ ),
158
+ )
159
+ assert len(dmmr) != 0
160
+
161
+ @pytest.mark.skip(reason="no GKB statement for HLA Signature CVs yet")
162
+ def test_annotate_signature_variants_hla(self, graphkb_conn):
163
+ """Test an HLA Signature CVs with known GKB statements"""
164
+ signature = 'HLA-A*02:01'
165
+ hla = annotate_signature_variants(
166
+ graphkb_conn,
167
+ DISEASE_RIDS,
168
+ preprocess_signature_variants(
169
+ [
170
+ {
171
+ "displayName": f"{signature} {HLA_SIGNATURE_VARIANT_TYPE}",
172
+ "signatureName": signature,
173
+ "variantTypeName": HLA_SIGNATURE_VARIANT_TYPE,
174
+ }
175
+ ]
176
+ ),
177
+ )
178
+ assert len(hla) != 0
179
+
180
+ def test_annotate_signature_variants_tmb(self, graphkb_conn):
181
+ """Test a TMB Signature CVs with known GKB statements"""
182
+ tmb = annotate_signature_variants(
183
+ graphkb_conn,
184
+ DISEASE_RIDS,
185
+ preprocess_signature_variants(
186
+ [
187
+ {
188
+ "displayName": f"{TMB_SIGNATURE} {TMB_SIGNATURE_VARIANT_TYPE}",
189
+ "signatureName": TMB_SIGNATURE,
190
+ "variantTypeName": TMB_SIGNATURE_VARIANT_TYPE,
191
+ }
192
+ ]
193
+ ),
194
+ )
195
+ # Should also be matching to 'high mutation burden high signature'
196
+ assert len(tmb) != 0
197
+
198
+ def test_annotate_signature_variants_msi(self, graphkb_conn):
199
+ """Test a MSI Signature CVs with known GKB statements"""
200
+ msi = annotate_signature_variants(
201
+ graphkb_conn,
202
+ DISEASE_RIDS,
203
+ preprocess_signature_variants([MSI_MAPPING.get('microsatellite instability')]),
204
+ )
205
+ assert len(msi) != 0
206
+
116
207
  def test_annotate_structural_variants_tp53(self, graphkb_conn):
117
208
  """Verify alternate TP53 variants match."""
118
- disease = "cancer"
119
209
  ref_key = "prot_only"
120
210
  pref = annotate_positional_variants(graphkb_conn, [TP53_MUT_DICT[ref_key]], DISEASE_RIDS)
121
211
  # GERO-299 - nonsense - stop codon - should not match. This is missense not nonsense (#164:933).
@@ -6,6 +6,11 @@ import pytest
6
6
  from unittest import mock
7
7
 
8
8
  from pori_python.graphkb.match import INPUT_COPY_CATEGORIES
9
+ from pori_python.ipr.constants import (
10
+ MSI_MAPPING,
11
+ TMB_SIGNATURE,
12
+ TMB_SIGNATURE_HIGH_THRESHOLD,
13
+ )
9
14
  from pori_python.ipr.inputs import (
10
15
  COPY_OPTIONAL,
11
16
  check_comparators,
@@ -15,9 +20,11 @@ from pori_python.ipr.inputs import (
15
20
  preprocess_cosmic,
16
21
  preprocess_expression_variants,
17
22
  preprocess_hla,
23
+ preprocess_msi,
18
24
  preprocess_signature_variants,
19
25
  preprocess_small_mutations,
20
26
  preprocess_structural_variants,
27
+ preprocess_tmb,
21
28
  validate_report_content,
22
29
  )
23
30
  from pori_python.ipr.util import logger
@@ -40,6 +47,8 @@ EXPECTED_HLA = {
40
47
  "HLA-C*06:02",
41
48
  "HLA-C*06",
42
49
  }
50
+ EXPECTED_TMB = {TMB_SIGNATURE}
51
+ EXPECTED_MSI = {MSI_MAPPING.get('microsatellite instability')['signatureName']}
43
52
 
44
53
 
45
54
  def read_data_file(filename):
@@ -196,47 +205,86 @@ class TestPreProcessCopyVariants:
196
205
 
197
206
 
198
207
  class TestPreProcessSignatureVariants:
208
+
209
+ # Preprocessing records from file
210
+ cosmic = preprocess_cosmic(
211
+ [
212
+ r['signature']
213
+ for r in pd.read_csv(os.path.join(DATA_DIR, "cosmic_variants.tab"), sep="\t").to_dict(
214
+ "records"
215
+ )
216
+ ]
217
+ )
218
+ hla = preprocess_hla(
219
+ pd.read_csv(os.path.join(DATA_DIR, "hla_variants.tab"), sep="\t").to_dict("records")
220
+ )
221
+ tmb = preprocess_tmb(
222
+ tmb_high=TMB_SIGNATURE_HIGH_THRESHOLD,
223
+ tmburMutationBurden=pd.read_csv(
224
+ os.path.join(DATA_DIR, "tmburMutationBurden.tab"), sep="\t"
225
+ ).to_dict("records"),
226
+ genomeTmb="11.430000000000001",
227
+ )
228
+ msi = preprocess_msi(
229
+ [
230
+ {
231
+ "score": 27.55,
232
+ "kbCategory": "microsatellite instability",
233
+ "key": "microsatellite instability",
234
+ }
235
+ ]
236
+ )
237
+
238
+ # tests on preprocessed records
199
239
  def test_preprocess_cosmic(self) -> None:
200
- records = preprocess_cosmic(
201
- pd.read_csv(os.path.join(DATA_DIR, "cosmic_variants.tab"), sep="\t").to_dict("records")
202
- )
203
- assert records
204
- assert len(records) == len(EXPECTED_COSMIC)
205
- assert "variantTypeName" in records[0]
206
- assert "displayName" in records[0]
240
+ assert self.cosmic
241
+ assert len(self.cosmic) == len(EXPECTED_COSMIC)
242
+ assert "variantTypeName" in self.cosmic[0]
243
+ assert "displayName" in self.cosmic[0]
207
244
 
208
- signatureNames = {r.get("signatureName", "") for r in records}
245
+ signatureNames = {r.get("signatureName", "") for r in self.cosmic}
209
246
  assert len(EXPECTED_COSMIC.symmetric_difference(signatureNames)) == 0
210
247
 
211
248
  def test_preprocess_hla(self) -> None:
212
- records = preprocess_hla(
213
- pd.read_csv(os.path.join(DATA_DIR, "hla_variants.tab"), sep="\t").to_dict("records")
214
- )
215
- assert records
216
- assert len(records) == len(EXPECTED_HLA)
217
- assert "variantTypeName" in records[0]
218
- assert "displayName" in records[0]
249
+ assert self.hla
250
+ assert len(self.hla) == len(EXPECTED_HLA)
251
+ assert "variantTypeName" in self.hla[0]
252
+ assert "displayName" in self.hla[0]
219
253
 
220
- signatureNames = {r.get("signatureName", "") for r in records}
254
+ signatureNames = {r.get("signatureName", "") for r in self.hla}
221
255
  assert len(EXPECTED_HLA.symmetric_difference(signatureNames)) == 0
222
256
 
257
+ def test_preprocess_tmb(self) -> None:
258
+ assert self.tmb
259
+ assert len(self.tmb) == len(EXPECTED_TMB)
260
+ assert "variantTypeName" in self.tmb[0]
261
+ assert "displayName" in self.tmb[0]
262
+
263
+ signatureNames = {r.get("signatureName", "") for r in self.tmb}
264
+ assert len(EXPECTED_TMB.symmetric_difference(signatureNames)) == 0
265
+
266
+ def test_preprocess_msi(self) -> None:
267
+ assert self.msi
268
+ assert len(self.msi) == len(EXPECTED_MSI)
269
+ assert "variantTypeName" in self.msi[0]
270
+ assert "displayName" in self.msi[0]
271
+
272
+ signatureNames = {r.get("signatureName", "") for r in self.msi}
273
+ assert len(EXPECTED_MSI.symmetric_difference(signatureNames)) == 0
274
+
223
275
  def test_preprocess_signature_variants(self) -> None:
224
276
  records = preprocess_signature_variants(
225
277
  [
226
- *preprocess_cosmic(
227
- pd.read_csv(os.path.join(DATA_DIR, "cosmic_variants.tab"), sep="\t").to_dict(
228
- "records"
229
- )
230
- ),
231
- *preprocess_hla(
232
- pd.read_csv(os.path.join(DATA_DIR, "hla_variants.tab"), sep="\t").to_dict(
233
- "records"
234
- )
235
- ),
278
+ *self.cosmic,
279
+ *self.hla,
280
+ *self.tmb,
281
+ *self.msi,
236
282
  ]
237
283
  )
238
284
  assert records
239
- assert len(records) == len(EXPECTED_COSMIC) + len(EXPECTED_HLA)
285
+ assert len(records) == (
286
+ len(EXPECTED_COSMIC) + len(EXPECTED_HLA) + len(EXPECTED_TMB) + len(EXPECTED_MSI)
287
+ )
240
288
  assert "key" in records[0]
241
289
 
242
290
 
@@ -112,6 +112,7 @@ def report_upload_content(tmp_path_factory) -> Dict:
112
112
  return report_content
113
113
 
114
114
 
115
+ @pytest.mark.skip(reason="KBDEV-1308; taking too long, getting canceled after reaching max delay")
115
116
  @pytest.mark.skipif(EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests")
116
117
  class TestCreateReport:
117
118
  def test_main_sections_present(self, report_upload_content: Dict) -> None:
@@ -15,7 +15,8 @@ from .constants import EXCLUDE_INTEGRATION_TESTS
15
15
 
16
16
  EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
17
17
  EXCLUDE_ONCOKB_TESTS = os.environ.get("EXCLUDE_ONCOKB_TESTS") == "1"
18
- INCLUDE_UPLOAD_TESTS = os.environ.get("INCLUDE_UPLOAD_TESTS", 0) == "1"
18
+ INCLUDE_UPLOAD_TESTS = os.environ.get("INCLUDE_UPLOAD_TESTS", "0") == "1"
19
+ DELETE_UPLOAD_TEST_REPORTS = os.environ.get("DELETE_UPLOAD_TEST_REPORTS", "1") == "1"
19
20
 
20
21
 
21
22
  def get_test_spec():
@@ -154,9 +155,9 @@ def loaded_reports(tmp_path_factory) -> Generator:
154
155
  "async": (async_patient_id, async_loaded_report),
155
156
  }
156
157
  yield loaded_reports_result
157
- return
158
- ipr_conn.delete(uri=f"reports/{loaded_report['reports'][0]['ident']}")
159
- ipr_conn.delete(uri=f"reports/{async_loaded_report['reports'][0]['ident']}")
158
+ if DELETE_UPLOAD_TEST_REPORTS:
159
+ ipr_conn.delete(uri=f"reports/{loaded_report['reports'][0]['ident']}")
160
+ ipr_conn.delete(uri=f"reports/{async_loaded_report['reports'][0]['ident']}")
160
161
 
161
162
 
162
163
  def get_section(loaded_report, section_name):
@@ -1,12 +0,0 @@
1
- DEFAULT_URL = "https://iprstaging-api.bcgsc.ca/api"
2
- GERMLINE_BASE_TERMS = ("pharmacogenomic", "cancer predisposition") # based on graphkb.constants
3
- VARIANT_CLASSES = {"Variant", "CategoryVariant", "PositionalVariant", "CatalogueVariant"}
4
-
5
- # all possible values for review status are: ['pending', 'not required', 'passed', 'failed', 'initial']
6
- FAILED_REVIEW_STATUS = "failed"
7
-
8
- # Signatures
9
- COSMIC_SIGNATURE_VARIANT_TYPE = "high signature"
10
- HLA_SIGNATURE_VARIANT_TYPE = "signature present"
11
- TMB_HIGH = 10.0 # genomic mutations per mb - https://www.bcgsc.ca/jira/browse/GERO-296
12
- TMB_HIGH_CATEGORY = "high mutation burden"
File without changes
File without changes
File without changes
File without changes