pori-python 1.4.0__tar.gz → 1.5.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.4.0/pori_python.egg-info → pori_python-1.5.0}/PKG-INFO +1 -1
  2. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/constants.py +4 -1
  3. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/genes.py +130 -12
  4. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/util.py +68 -0
  5. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/vocab.py +2 -2
  6. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/connection.py +45 -14
  7. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/content.spec.json +143 -0
  8. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/inputs.py +58 -1
  9. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/ipr.py +80 -1
  10. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/main.py +75 -5
  11. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/util.py +5 -0
  12. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/types.py +2 -1
  13. {pori_python-1.4.0 → pori_python-1.5.0/pori_python.egg-info}/PKG-INFO +1 -1
  14. {pori_python-1.4.0 → pori_python-1.5.0}/setup.cfg +1 -1
  15. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_genes.py +33 -8
  16. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_util.py +42 -0
  17. pori_python-1.5.0/tests/test_ipr/test_connection.py +219 -0
  18. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_inputs.py +160 -0
  19. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_ipr.py +178 -0
  20. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_main.py +30 -1
  21. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_probe.py +5 -0
  22. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_upload.py +70 -2
  23. pori_python-1.5.0/tests/test_ipr/test_util.py +48 -0
  24. pori_python-1.4.0/tests/test_ipr/test_connection.py +0 -97
  25. pori_python-1.4.0/tests/test_ipr/test_util.py +0 -29
  26. {pori_python-1.4.0 → pori_python-1.5.0}/LICENSE +0 -0
  27. {pori_python-1.4.0 → pori_python-1.5.0}/MANIFEST.in +0 -0
  28. {pori_python-1.4.0 → pori_python-1.5.0}/README.md +0 -0
  29. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/__init__.py +0 -0
  30. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/__init__.py +0 -0
  31. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/match.py +0 -0
  32. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/graphkb/statement.py +0 -0
  33. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/__init__.py +0 -0
  34. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/annotate.py +0 -0
  35. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/constants.py +0 -0
  36. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/summary.py +0 -0
  37. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/ipr/therapeutic_options.py +0 -0
  38. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python/py.typed +0 -0
  39. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python.egg-info/SOURCES.txt +0 -0
  40. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python.egg-info/dependency_links.txt +0 -0
  41. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python.egg-info/entry_points.txt +0 -0
  42. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python.egg-info/requires.txt +0 -0
  43. {pori_python-1.4.0 → pori_python-1.5.0}/pori_python.egg-info/top_level.txt +0 -0
  44. {pori_python-1.4.0 → pori_python-1.5.0}/pyproject.toml +0 -0
  45. {pori_python-1.4.0 → pori_python-1.5.0}/setup.py +0 -0
  46. {pori_python-1.4.0 → pori_python-1.5.0}/tests/__init__.py +0 -0
  47. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/__init__.py +0 -0
  48. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/data.py +0 -0
  49. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_graphkb.py +0 -0
  50. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_match.py +0 -0
  51. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_statement.py +0 -0
  52. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_graphkb/test_vocab.py +0 -0
  53. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/__init__.py +0 -0
  54. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/constants.py +0 -0
  55. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_annotate.py +0 -0
  56. {pori_python-1.4.0 → pori_python-1.5.0}/tests/test_ipr/test_summary.py +0 -0
  57. {pori_python-1.4.0 → pori_python-1.5.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.4.0
3
+ Version: 1.5.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
@@ -59,7 +59,10 @@ ONCOKB_SOURCE_NAME = 'oncokb'
59
59
  TSO500_SOURCE_NAME = 'tso500'
60
60
  ONCOGENE = 'oncogenic'
61
61
  TUMOUR_SUPPRESSIVE = 'tumour suppressive'
62
- CANCER_GENE = 'cancer gene'
62
+ CANCER_GENE = [
63
+ 'cancer gene',
64
+ 'tumourigenesis',
65
+ ] # KBDEV-1532. tumourigenesis for backward compatibility
63
66
  FUSION_NAMES = ['structural variant', 'fusion']
64
67
 
65
68
  GSC_PHARMACOGENOMIC_SOURCE_EXCLUDE_LIST = ['cancer genome interpreter', 'civic']
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, List, Sequence, Set, Tuple, cast
5
+ from typing import Any, Dict, List, Sequence, Set, Tuple, cast, Union
6
6
  from typing_extensions import deprecated
7
7
 
8
8
  from pori_python.types import IprGene, Ontology, Record, Statement, Variant
@@ -27,8 +27,117 @@ from .util import get_rid, logger, looks_like_rid
27
27
  from .vocab import get_terms_set
28
28
 
29
29
 
30
+ def get_cancer_gene_flags(
31
+ conn: GraphKBConnection,
32
+ flags: bool = False,
33
+ ignore_cache: bool = False,
34
+ ) -> Union[List[Record], Dict[str, List[Record]]]:
35
+ """
36
+ Return all cancer genes, optionally sorted by flags.
37
+
38
+ Flag definitions:
39
+ oncogenic: relevance 'oncogenic' from OncoKB
40
+ tumourSuppressive: relevance 'tumour suppressive' from OncoKB
41
+ cancerGene: relevance 'cancer gene' AND child terms ('oncogenic', 'tumour suppressive', 'other cancer gene'), from OncoKB AND TSO500
42
+
43
+ Args:
44
+ conn: the graphkb connection object
45
+ flags: if the results should be sorted by flags
46
+ ignore_cache: if cache should be ignored when querying GraphKB API
47
+
48
+ Returns (if flags=False; default): list of unique gene records
49
+ [ <record>, <record>, ... ]
50
+
51
+ Returns (if flags=True): dict of flags as keys, and list of gene records as value
52
+ {
53
+ 'oncogenic': [ <record>, <record>, ... ],
54
+ 'tumourSuppressive': [ <record>, <record>, ... ],
55
+ 'cancerGene': [ <record>, <record>, ... ],
56
+ }
57
+ """
58
+ # all cancer gene statements
59
+ cancer_genes = conn.get_related_terms(
60
+ terms=CANCER_GENE,
61
+ subgraphType='children',
62
+ )
63
+ statements = cast(
64
+ List[Statement],
65
+ conn.query(
66
+ {
67
+ 'target': 'Statement',
68
+ 'filters': {
69
+ 'relevance': {'target': 'Vocabulary', 'filters': {'name': cancer_genes}}
70
+ },
71
+ 'returnProperties': [
72
+ 'source.name',
73
+ 'relevance.name',
74
+ *[f'subject.{prop}' for prop in GENE_RETURN_PROPERTIES],
75
+ ],
76
+ },
77
+ ignore_cache=ignore_cache,
78
+ ),
79
+ )
80
+
81
+ # post-query filtering (faster)
82
+ cancerGeneStms = list(
83
+ filter(
84
+ lambda r: (
85
+ r['subject']['@class'] == 'Feature'
86
+ and r['subject']['biotype'] == 'gene'
87
+ and r['source']['name'] in [ONCOKB_SOURCE_NAME, TSO500_SOURCE_NAME]
88
+ ),
89
+ statements,
90
+ )
91
+ )
92
+ oncogenicStms = list(
93
+ filter(
94
+ lambda r: (
95
+ r['relevance']['name'] == ONCOGENE and r['source']['name'] == ONCOKB_SOURCE_NAME
96
+ ),
97
+ cancerGeneStms,
98
+ )
99
+ )
100
+ tumourSuppressiveStms = list(
101
+ filter(
102
+ lambda r: (
103
+ r['relevance']['name'] == TUMOUR_SUPPRESSIVE
104
+ and r['source']['name'] == ONCOKB_SOURCE_NAME
105
+ ),
106
+ cancerGeneStms,
107
+ )
108
+ )
109
+
110
+ # Returning a sorted list of unique gene records, based on iProbe requirements
111
+ # Unique by name, sorted by displayName
112
+ if not flags:
113
+ seen: set = set()
114
+ unique_genes: List[Record] = []
115
+ for r in cancerGeneStms:
116
+ name = r['subject']['name']
117
+ if name not in seen:
118
+ seen.add(name)
119
+ unique_genes.append(r['subject'])
120
+
121
+ return cast(
122
+ List[Record],
123
+ sorted(unique_genes, key=lambda gene: gene['displayName']),
124
+ )
125
+
126
+ # Returning a Dict of flags, with list of associated gene records
127
+ # Duplicates are ok
128
+ return {
129
+ 'cancerGene': [r['subject'] for r in cancerGeneStms],
130
+ 'oncogenic': [r['subject'] for r in oncogenicStms],
131
+ 'tumourSuppressive': [r['subject'] for r in tumourSuppressiveStms],
132
+ }
133
+
134
+
135
+ @deprecated('functionality replaced by get_cancer_gene_flags')
30
136
  def _get_tumourigenesis_genes_list(
31
- conn: GraphKBConnection, relevance: str, sources: List[str], ignore_cache: bool = False
137
+ conn: GraphKBConnection,
138
+ relevance: Union[str, List[str]],
139
+ sources: Union[str, List[str]],
140
+ ignore_cache: bool = False,
32
141
  ) -> List[Ontology]:
33
142
  statements = cast(
34
143
  List[Statement],
@@ -57,6 +166,7 @@ def _get_tumourigenesis_genes_list(
57
166
  return [gene for gene in genes.values()]
58
167
 
59
168
 
169
+ @deprecated('functionality replaced by get_cancer_gene_flags')
60
170
  def get_oncokb_oncogenes(conn: GraphKBConnection) -> List[Ontology]:
61
171
  """Get the list of oncogenes stored in GraphKB derived from OncoKB.
62
172
 
@@ -66,9 +176,10 @@ def get_oncokb_oncogenes(conn: GraphKBConnection) -> List[Ontology]:
66
176
  Returns:
67
177
  gene (Feature) records
68
178
  """
69
- return _get_tumourigenesis_genes_list(conn, ONCOGENE, [ONCOKB_SOURCE_NAME])
179
+ return _get_tumourigenesis_genes_list(conn, ONCOGENE, ONCOKB_SOURCE_NAME)
70
180
 
71
181
 
182
+ @deprecated('functionality replaced by get_cancer_gene_flags')
72
183
  def get_oncokb_tumour_supressors(conn: GraphKBConnection) -> List[Ontology]:
73
184
  """Get the list of tumour supressor genes stored in GraphKB derived from OncoKB.
74
185
 
@@ -78,11 +189,14 @@ def get_oncokb_tumour_supressors(conn: GraphKBConnection) -> List[Ontology]:
78
189
  Returns:
79
190
  gene (Feature) records
80
191
  """
81
- return _get_tumourigenesis_genes_list(conn, TUMOUR_SUPPRESSIVE, [ONCOKB_SOURCE_NAME])
192
+ return _get_tumourigenesis_genes_list(conn, TUMOUR_SUPPRESSIVE, ONCOKB_SOURCE_NAME)
82
193
 
83
194
 
195
+ @deprecated('functionality replaced by get_cancer_gene_flags')
84
196
  def get_cancer_genes(conn: GraphKBConnection) -> List[Ontology]:
85
- """Get the list of cancer genes stored in GraphKB derived from OncoKB & TSO500.
197
+ """
198
+ Get the list of cancer genes stored in GraphKB derived from OncoKB & TSO500.
199
+ Cancer genes include oncogenes, tumour supressor genes and other cancer genes.
86
200
 
87
201
  Args:
88
202
  conn: the graphkb connection object
@@ -90,8 +204,12 @@ def get_cancer_genes(conn: GraphKBConnection) -> List[Ontology]:
90
204
  Returns:
91
205
  gene (Feature) records
92
206
  """
207
+ cancer_gene_terms = conn.get_related_terms(
208
+ terms=CANCER_GENE,
209
+ subgraphType='children',
210
+ )
93
211
  return _get_tumourigenesis_genes_list(
94
- conn, CANCER_GENE, [ONCOKB_SOURCE_NAME, TSO500_SOURCE_NAME]
212
+ conn, cancer_gene_terms, [ONCOKB_SOURCE_NAME, TSO500_SOURCE_NAME]
95
213
  )
96
214
 
97
215
 
@@ -513,12 +631,12 @@ def get_gene_information(
513
631
  # PositionalVariant without a reference2 implies a smallMutation type
514
632
  gene_flags['knownSmallMutation'].add(condition['reference1']) # type: ignore
515
633
 
516
- logger.info('fetching oncogenes list')
517
- gene_flags['oncogene'] = convert_to_rid_set(get_oncokb_oncogenes(graphkb_conn))
518
- logger.info('fetching tumour supressors list')
519
- gene_flags['tumourSuppressor'] = convert_to_rid_set(get_oncokb_tumour_supressors(graphkb_conn))
520
- logger.info('fetching cancerGeneListMatch list')
521
- gene_flags['cancerGeneListMatch'] = convert_to_rid_set(get_cancer_genes(graphkb_conn))
634
+ # cancer gene flags
635
+ logger.info('fetching cancer genes')
636
+ cancer_gene_flags = get_cancer_gene_flags(graphkb_conn, flags=True)
637
+ gene_flags['oncogene'] = convert_to_rid_set(cancer_gene_flags['oncogenic'])
638
+ gene_flags['tumourSuppressor'] = convert_to_rid_set(cancer_gene_flags['tumourSuppressive'])
639
+ gene_flags['cancerGeneListMatch'] = convert_to_rid_set(cancer_gene_flags['cancerGene'])
522
640
 
523
641
  logger.info('fetching therapeutic associated genes lists')
524
642
  gene_flags['therapeuticAssociated'] = convert_to_rid_set(
@@ -354,6 +354,74 @@ class GraphKBConnection:
354
354
  raise AssertionError(f'Unable to unqiuely identify source with name {name}')
355
355
  return source[0]
356
356
 
357
+ @property
358
+ def version(self) -> Dict[str, str]:
359
+ """
360
+ Retrieve GraphKB components version
361
+
362
+ Returns:
363
+ Dict[str, str]: component keys with version values
364
+
365
+ e.g. > {"api":"3.17.3","db":"production","parser":"2.1.0","schema":"4.1.1"}
366
+ """
367
+ return self.request('version')
368
+
369
+ def get_related_records(
370
+ self,
371
+ base: Union[str, List[str]],
372
+ ontology: str,
373
+ subgraphType: str,
374
+ returnProperties: Optional[List[str]] = None,
375
+ ) -> List[Record]:
376
+ """
377
+ Given some base node RIDs, an ontology class and a subgraph type,
378
+ leverage the subgraphs route to return the list of related nodes.
379
+
380
+ Args:
381
+ base: the base node RIDs to start the graph traversal from
382
+ ontology: the ontology class to traverse
383
+ subgraphType: the type of traversal. See options in API specs
384
+ returnProperties: additional record properties to return
385
+
386
+ Returns:
387
+ list of related node record(s) traversed
388
+ """
389
+ related = self.post(
390
+ uri=f'/subgraphs/{ontology}',
391
+ data={
392
+ 'base': base if isinstance(base, list) else [base],
393
+ 'subgraphType': subgraphType,
394
+ 'returnProperties': returnProperties or [],
395
+ },
396
+ )
397
+ return related['result']['g']['nodes']
398
+
399
+ def get_related_terms(
400
+ self,
401
+ terms: Union[str, List[str]],
402
+ ontology: str = 'Vocabulary',
403
+ subgraphType: str = 'similar',
404
+ ) -> List[str]:
405
+ """
406
+ Given some base term name(s), an ontology class and a subgraph type,
407
+ leverage the subgraphs route to return the list of related term name(s)
408
+
409
+ Args:
410
+ terms: the base term name(s) to start the graph traversal from
411
+ ontology: the ontology class to traverse
412
+ subgraphType: the type of traversal
413
+
414
+ Returns:
415
+ list of related term name(s)
416
+ """
417
+ rids = convert_to_rid_list(self.query({'target': ontology, 'filters': {'name': terms}}))
418
+ nodes = self.get_related_records(
419
+ base=rids,
420
+ ontology=ontology,
421
+ subgraphType=subgraphType,
422
+ )
423
+ return [x['name'] for x in nodes.values()]
424
+
357
425
 
358
426
  def get_rid(conn: GraphKBConnection, target: str, name: str) -> str:
359
427
  """
@@ -1,4 +1,4 @@
1
- from typing import Callable, Dict, Iterable, List, Set, cast
1
+ from typing import Callable, Dict, Iterable, List, Set, cast, Union
2
2
 
3
3
  from pori_python.types import Ontology
4
4
 
@@ -6,7 +6,7 @@ from . import GraphKBConnection
6
6
  from .util import convert_to_rid_list
7
7
 
8
8
 
9
- def query_by_name(ontology_class: str, base_term_name: str) -> Dict:
9
+ def query_by_name(ontology_class: str, base_term_name: Union[str, list[str]]) -> Dict:
10
10
  return {'target': ontology_class, 'filters': {'name': base_term_name}}
11
11
 
12
12
 
@@ -93,10 +93,54 @@ class IprConnection:
93
93
  **kwargs,
94
94
  )
95
95
 
96
+ def check_upload_permission(self, project_name: str) -> None:
97
+ """Check that the current user has permission to upload to the given project.
98
+
99
+ Fetches all projects and the current user info (including groups and
100
+ projects) up front. Checks for admin, manager, create report access,
101
+ all projects access, and project membership.
102
+ """
103
+ projects = self.get('project')
104
+ project_exists = any(p['name'] == project_name for p in projects)
105
+ if not project_exists:
106
+ raise Exception(
107
+ f'Project {project_name} does not exist or user does not have permission to view it'
108
+ )
109
+
110
+ user = self.get('user/me')
111
+ user_groups = user.get('groups', []) if isinstance(user, dict) else []
112
+ group_names = {
113
+ group.get('name', '').strip().lower()
114
+ if isinstance(group, dict)
115
+ else group.strip().lower()
116
+ for group in user_groups
117
+ }
118
+
119
+ is_admin = 'admin' in group_names
120
+ is_manager = 'manager' in group_names
121
+ has_create_report_access = 'create report access' in group_names
122
+ has_all_projects_access = 'all projects access' in group_names
123
+
124
+ # admins and managers can always create reports
125
+ can_create_report = is_admin or is_manager or has_create_report_access
126
+
127
+ user_projects = user.get('projects', []) if isinstance(user, dict) else []
128
+ has_project_access = (
129
+ is_admin
130
+ or has_all_projects_access
131
+ or any(isinstance(p, dict) and p.get('name') == project_name for p in user_projects)
132
+ )
133
+
134
+ if not can_create_report:
135
+ raise Exception('User does not have report creation permission')
136
+
137
+ if not has_project_access:
138
+ raise Exception(f'User has no permission to create report in project {project_name}')
139
+
96
140
  def upload_report(
97
141
  self,
98
142
  content: Dict,
99
- mins_to_wait: int = 5,
143
+ mins_to_wait: int = 10,
100
144
  async_upload: bool = False,
101
145
  ignore_extra_fields: bool = False,
102
146
  ) -> Dict:
@@ -105,19 +149,6 @@ class IprConnection:
105
149
  # or 'report'. jobStatus is no longer available once the report is successfully
106
150
  # uploaded.
107
151
 
108
- projects = self.get('project')
109
- project_names = [item['name'] for item in projects]
110
-
111
- # if project is not exist, create one
112
- if content['project'] not in project_names:
113
- logger.info(
114
- f'Project not found - attempting to create project {content["project"]}'
115
- )
116
- try:
117
- self.post('project', {'name': content['project']})
118
- except Exception as err:
119
- raise Exception(f'Project creation failed due to {err}')
120
-
121
152
  if ignore_extra_fields:
122
153
  initial_result = self.post('reports-async?ignore_extra_fields=true', content)
123
154
  else:
@@ -202,6 +202,16 @@
202
202
  "number",
203
203
  "null"
204
204
  ]
205
+ },
206
+ "flags": {
207
+ "description": "variant flags",
208
+ "items": {
209
+ "type": "string"
210
+ },
211
+ "type": [
212
+ "array",
213
+ "null"
214
+ ]
205
215
  }
206
216
  },
207
217
  "required": [
@@ -475,6 +485,16 @@
475
485
  "null",
476
486
  "string"
477
487
  ]
488
+ },
489
+ "flags": {
490
+ "description": "variant flags",
491
+ "items": {
492
+ "type": "string"
493
+ },
494
+ "type": [
495
+ "array",
496
+ "null"
497
+ ]
478
498
  }
479
499
  },
480
500
  "required": [
@@ -892,6 +912,109 @@
892
912
  "example": "POG",
893
913
  "type": "string"
894
914
  },
915
+ "seqQC": {
916
+ "default": [],
917
+ "type": "array",
918
+ "items": {
919
+ "type": "object",
920
+ "properties": {
921
+ "reads": {
922
+ "description": "Number of reads",
923
+ "example": "2534M",
924
+ "type": [
925
+ "string",
926
+ "null"
927
+ ]
928
+ },
929
+ "bioQC": {
930
+ "description": "Biological QC status",
931
+ "example": "passed",
932
+ "type": [
933
+ "string",
934
+ "null"
935
+ ]
936
+ },
937
+ "labQC": {
938
+ "description": "Lab QC status",
939
+ "example": "passed",
940
+ "type": [
941
+ "string",
942
+ "null"
943
+ ]
944
+ },
945
+ "sample": {
946
+ "description": "Sample identifier, e.g. Tumour DNA, Constitutional DNA",
947
+ "example": "Tumour DNA",
948
+ "type": [
949
+ "string",
950
+ "null"
951
+ ]
952
+ },
953
+ "library": {
954
+ "description": "Library identifier",
955
+ "example": "LIB0001",
956
+ "type": [
957
+ "string",
958
+ "null"
959
+ ]
960
+ },
961
+ "coverage": {
962
+ "description": "Sequencing coverage",
963
+ "example": "80x",
964
+ "type": [
965
+ "string",
966
+ "null"
967
+ ]
968
+ },
969
+ "inputNg": {
970
+ "description": "Input amount in nanograms",
971
+ "example": "500",
972
+ "type": [
973
+ "string",
974
+ "number",
975
+ "integer",
976
+ "null"
977
+ ]
978
+ },
979
+ "inputUg": {
980
+ "description": "Input amount in micrograms",
981
+ "example": "0.5",
982
+ "type": [
983
+ "string",
984
+ "number",
985
+ "integer",
986
+ "null"
987
+ ]
988
+ },
989
+ "protocol": {
990
+ "description": "Sequencing protocol",
991
+ "example": "WGS",
992
+ "type": [
993
+ "string",
994
+ "null"
995
+ ]
996
+ },
997
+ "sampleName": {
998
+ "description": "Full sample name",
999
+ "example": "SAMPLE1-FF-1",
1000
+ "type": [
1001
+ "string",
1002
+ "null"
1003
+ ]
1004
+ },
1005
+ "duplicateReadsPerc": {
1006
+ "description": "Percentage of duplicate reads",
1007
+ "example": "12.3",
1008
+ "type": [
1009
+ "string",
1010
+ "number",
1011
+ "integer",
1012
+ "null"
1013
+ ]
1014
+ }
1015
+ }
1016
+ }
1017
+ },
895
1018
  "smallMutations": {
896
1019
  "default": [],
897
1020
  "items": {
@@ -1106,6 +1229,16 @@
1106
1229
  "string",
1107
1230
  "null"
1108
1231
  ]
1232
+ },
1233
+ "flags": {
1234
+ "description": "variant flags",
1235
+ "items": {
1236
+ "type": "string"
1237
+ },
1238
+ "type": [
1239
+ "array",
1240
+ "null"
1241
+ ]
1109
1242
  }
1110
1243
  },
1111
1244
  "required": [
@@ -1290,6 +1423,16 @@
1290
1423
  "integer",
1291
1424
  "null"
1292
1425
  ]
1426
+ },
1427
+ "flags": {
1428
+ "description": "variant flags",
1429
+ "items": {
1430
+ "type": "string"
1431
+ },
1432
+ "type": [
1433
+ "array",
1434
+ "null"
1435
+ ]
1293
1436
  }
1294
1437
  },
1295
1438
  "required": [
@@ -60,6 +60,7 @@ COPY_OPTIONAL = [
60
60
  'comments',
61
61
  'library',
62
62
  'germline',
63
+ 'flags',
63
64
  ]
64
65
 
65
66
  SMALL_MUT_REQ = ['gene', 'proteinChange']
@@ -98,6 +99,7 @@ SMALL_MUT_OPTIONAL = [
98
99
  'tumourRefCount',
99
100
  'tumourRefCopies',
100
101
  'zygosity',
102
+ 'flags',
101
103
  ]
102
104
 
103
105
  EXP_REQ = ['gene', 'kbCategory']
@@ -130,6 +132,7 @@ EXP_OPTIONAL = [
130
132
  'rnaReads',
131
133
  'rpkm',
132
134
  'tpm',
135
+ 'flags',
133
136
  ]
134
137
 
135
138
  SV_REQ = [
@@ -162,6 +165,7 @@ SV_OPTIONAL = [
162
165
  'tumourDepth',
163
166
  'germline',
164
167
  'mavis_product_id',
168
+ 'flags',
165
169
  ]
166
170
 
167
171
  SIGV_REQ = ['signatureName', 'variantTypeName']
@@ -278,6 +282,7 @@ def preprocess_small_mutations(rows: Iterable[Dict]) -> List[IprSmallMutationVar
278
282
  return tuple(['small mutation'] + key_vals)
279
283
 
280
284
  result = validate_variant_rows(rows, SMALL_MUT_REQ, SMALL_MUT_OPTIONAL, row_key)
285
+
281
286
  if not result:
282
287
  return []
283
288
 
@@ -336,6 +341,7 @@ def preprocess_expression_variants(rows: Iterable[Dict]) -> List[IprExprVariant]
336
341
  return tuple(['expression'] + [row[key] for key in EXP_KEY])
337
342
 
338
343
  variants = validate_variant_rows(rows, EXP_REQ, EXP_OPTIONAL, row_key)
344
+
339
345
  result = [cast(IprExprVariant, var) for var in variants]
340
346
  float_columns = [
341
347
  col
@@ -371,7 +377,6 @@ def preprocess_expression_variants(rows: Iterable[Dict]) -> List[IprExprVariant]
371
377
 
372
378
  if errors:
373
379
  raise ValueError(f'{len(errors)} Invalid expression variants in file')
374
-
375
380
  return result
376
381
 
377
382
 
@@ -796,6 +801,58 @@ def extend_with_default(validator_class):
796
801
  DefaultValidatingDraft7Validator = extend_with_default(jsonschema.Draft7Validator)
797
802
 
798
803
 
804
+ def normalize_seqqc(content: Dict) -> Dict:
805
+ """
806
+ Normalize seqQC field names from production report format to schema format.
807
+
808
+ Maps inconsistent casing and underscores in field names to match content.spec.json requirements.
809
+ For example: 'Reads' -> 'reads', 'Sample Name' -> 'sampleName', etc.
810
+
811
+ Args:
812
+ content: Report content dictionary that may contain seqQC array
813
+
814
+ Returns:
815
+ A new content dictionary with seqQC fields normalized
816
+ """
817
+ content = {**content}
818
+ # Field name mapping from production/legacy format to schema format
819
+ field_mapping = {
820
+ 'Reads': 'reads',
821
+ 'Sample': 'sample',
822
+ 'Library': 'library',
823
+ 'Coverage': 'coverage',
824
+ 'Input_ng': 'inputNg',
825
+ 'Input_ug': 'inputUg',
826
+ 'Protocol': 'protocol',
827
+ 'Sample Name': 'sampleName',
828
+ 'Duplicate_Reads_Perc': 'duplicateReadsPerc',
829
+ }
830
+ normalized_keys = set(field_mapping.values())
831
+
832
+ if 'seqQC' in content and isinstance(content['seqQC'], list):
833
+ content['seqQC'] = list(content['seqQC'])
834
+ for i, item in enumerate(content['seqQC']):
835
+ if not isinstance(item, dict):
836
+ continue
837
+ # Preserve already-normalized keys (and unrelated keys) first so
838
+ # legacy aliases cannot overwrite them based on insertion order.
839
+ normalized_item = {}
840
+ for key, value in item.items():
841
+ if key in normalized_keys or key not in field_mapping:
842
+ normalized_item[key] = value
843
+
844
+ # Add legacy aliases only when the normalized key is not already
845
+ # present. This makes collision handling explicit and stable.
846
+ for old_key, new_key in field_mapping.items():
847
+ if old_key in item and new_key not in normalized_item:
848
+ normalized_item[new_key] = item[old_key]
849
+
850
+ # Replace the item with normalized version
851
+ content['seqQC'][i] = normalized_item
852
+
853
+ return content
854
+
855
+
799
856
  def validate_report_content(content: Dict, schema_file: str = SPECIFICATION) -> None:
800
857
  """
801
858
  Validate a report content input JSON object against the schema specification