Skip to content

Commit b191575

Browse files
authored
Merge pull request #13 from bcgsc/improvement/lint_typing_fixes_TypedDict
Improvement/lint typing fixes typed dict
2 parents b9a1eb5 + e6fdfc2 commit b191575

20 files changed

+127
-125
lines changed

pori_python/graphkb/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
from typing import Dict
33

4-
from .types import CategoryBaseTermMapping
4+
from pori_python.types import CategoryBaseTermMapping
55

66
DEFAULT_LIMIT = 1000
77
GKB_BASE_URL = "https://graphkb-api.bcgsc.ca/api"

pori_python/graphkb/genes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import Any, Dict, List, Sequence, Set, Tuple, cast
44

5+
from pori_python.types import Ontology, Statement, Variant
6+
57
from . import GraphKBConnection
68
from .constants import (
79
BASE_THERAPEUTIC_TERMS,
@@ -18,7 +20,6 @@
1820
TUMOUR_SUPPRESSIVE,
1921
)
2022
from .match import get_equivalent_features
21-
from .types import Ontology, Statement, Variant
2223
from .util import get_rid, logger
2324
from .vocab import get_terms_set
2425

pori_python/graphkb/match.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
from typing import Dict, List, Optional, Set, Union, cast
66

7+
from pori_python.types import (
8+
BasicPosition,
9+
Ontology,
10+
ParsedVariant,
11+
PositionalVariant,
12+
Record,
13+
Variant,
14+
)
15+
716
from . import GraphKBConnection
817
from .constants import (
918
AMBIGUOUS_AA,
@@ -15,7 +24,6 @@
1524
STRUCTURAL_VARIANT_TYPES,
1625
VARIANT_RETURN_PROPERTIES,
1726
)
18-
from .types import BasicPosition, Ontology, ParsedVariant, PositionalVariant, Record, Variant
1927
from .util import (
2028
FeatureNotFoundError,
2129
convert_to_rid_list,

pori_python/graphkb/statement.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import List, cast
22

3+
from pori_python.types import CategoryBaseTermMapping, Statement, Variant
4+
35
from . import GraphKBConnection
46
from .constants import FAILED_REVIEW_STATUS, RELEVANCE_BASE_TERMS, STATEMENT_RETURN_PROPERTIES
5-
from .types import CategoryBaseTermMapping, Statement, Variant
67
from .util import convert_to_rid_list
78
from .vocab import get_terms_set
89

pori_python/graphkb/types.py

-92
This file was deleted.

pori_python/graphkb/util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
from typing import Any, Dict, Iterable, List, Optional, Union, cast
1111
from urllib3.util.retry import Retry
1212

13+
from pori_python.types import OntologyTerm, ParsedVariant, PositionalVariant, Record
14+
1315
from .constants import DEFAULT_LIMIT, DEFAULT_URL, TYPES_TO_NOTATION, AA_3to1_MAPPING
14-
from .types import OntologyTerm, ParsedVariant, PositionalVariant, Record
1516

1617
QUERY_CACHE: Dict[Any, Any] = {}
1718

pori_python/graphkb/vocab.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Callable, Dict, Iterable, List, Set, cast
22

3+
from pori_python.types import Ontology
4+
35
from . import GraphKBConnection
4-
from .types import Ontology
56
from .util import convert_to_rid_list
67

78

pori_python/ipr/annotate.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
from pori_python.graphkb import match as gkb_match
1313
from pori_python.graphkb.match import INPUT_COPY_CATEGORIES
1414
from pori_python.graphkb.statement import get_statements_from_variants
15-
from pori_python.graphkb.types import Variant
1615
from pori_python.graphkb.util import FeatureNotFoundError
16+
from pori_python.types import (
17+
GkbStatement,
18+
IprCopyVariant,
19+
IprExprVariant,
20+
IprStructuralVariant,
21+
KbMatch,
22+
Variant,
23+
)
1724

1825
from .constants import TMB_HIGH_CATEGORY
1926
from .ipr import convert_statements_to_alterations
20-
from .types import GkbStatement, IprCopyVariant, IprExprVariant, IprStructuralVariant, KbMatch
2127
from .util import Hashabledict, convert_to_rid_set, logger
2228

2329
REPORTED_COPY_VARIANTS = (INPUT_COPY_CATEGORIES.AMP, INPUT_COPY_CATEGORIES.DEEP)

pori_python/ipr/inputs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from typing import Callable, Dict, Iterable, List, Set, Tuple, cast
1111

1212
from pori_python.graphkb.match import INPUT_COPY_CATEGORIES, INPUT_EXPRESSION_CATEGORIES
13-
14-
from .types import (
13+
from pori_python.types import (
1514
IprCopyVariant,
1615
IprExprVariant,
1716
IprFusionVariant,
1817
IprSmallMutationVariant,
1918
IprVariant,
2019
)
20+
2121
from .util import hash_key, logger, pandas_falsy
2222

2323
protein_letters_3to1.setdefault("Ter", "*")

pori_python/ipr/ipr.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
from pori_python.graphkb import GraphKBConnection
99
from pori_python.graphkb import statement as gkb_statement
1010
from pori_python.graphkb import vocab as gkb_vocab
11+
from pori_python.types import (
12+
GkbStatement,
13+
ImageDefinition,
14+
IprFusionVariant,
15+
IprGene,
16+
IprVariant,
17+
KbMatch,
18+
)
1119

1220
from .constants import GERMLINE_BASE_TERMS, VARIANT_CLASSES
13-
from .types import GkbStatement, ImageDefinition, IprFusionVariant, IprGene, IprVariant, KbMatch
1421
from .util import find_variant, logger
1522

1623

pori_python/ipr/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pori_python.graphkb import GraphKBConnection
1111
from pori_python.graphkb.genes import get_gene_information
12+
from pori_python.types import IprVariant, KbMatch
1213

1314
from .annotate import (
1415
annotate_copy_variants,
@@ -36,7 +37,6 @@
3637
)
3738
from .summary import summarize
3839
from .therapeutic_options import create_therapeutic_options
39-
from .types import IprVariant, KbMatch
4040
from .util import LOG_LEVELS, logger, trim_empty_values
4141

4242
CACHE_GENE_MINIMUM = 5000

pori_python/ipr/summary.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
from pori_python.graphkb import GraphKBConnection
77
from pori_python.graphkb.constants import RELEVANCE_BASE_TERMS
88
from pori_python.graphkb.statement import categorize_relevance
9-
from pori_python.graphkb.types import Ontology, Record
109
from pori_python.graphkb.util import convert_to_rid_list
1110
from pori_python.graphkb.vocab import get_term_tree
1211
from pori_python.ipr.inputs import create_graphkb_sv_notation
12+
from pori_python.types import GkbStatement, IprVariant, KbMatch, Ontology, Record
1313

14-
from .types import GkbStatement, IprVariant, KbMatch
1514
from .util import (
1615
convert_to_rid_set,
1716
generate_ontology_preference_key,

pori_python/ipr/therapeutic_options.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"""
44

55
import pandas
6-
from typing import Dict, List, Sequence
6+
from typing import Any, Dict, List, Sequence
77

88
from pori_python.graphkb import GraphKBConnection
9+
from pori_python.types import IprVariant, KbMatch
910

10-
from .types import IprVariant, KbMatch
1111
from .util import (
1212
create_variant_name_tuple,
1313
find_variant,
@@ -22,7 +22,7 @@ def create_therapeutic_options(
2222
"""
2323
Generate therapeutic options summary from the list of kb-matches
2424
"""
25-
options = []
25+
options: List[Dict[str, Any]] = []
2626
resistance_markers = get_terms_set(graphkb_conn, ["no sensitivity"])
2727

2828
for match in kb_matches:

pori_python/ipr/util.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from typing import Any, Dict, List, Sequence, Set, Tuple, cast
77

88
from pori_python.graphkb import GraphKBConnection
9-
from pori_python.graphkb.types import Ontology, Record
109
from pori_python.graphkb.vocab import get_term_tree
11-
12-
from .types import IprVariant
10+
from pori_python.types import IprVariant, Ontology, Record
1311

1412
GENE_NEIGHBORS_MAX = 3
1513

@@ -100,7 +98,7 @@ def generate_ontology_preference_key(record: Ontology, sources_sort: Dict[str, i
10098
record.get("deprecated", False),
10199
record.get("alias", False),
102100
bool(record.get("dependency", "")),
103-
sources_sort.get(record["source"], 99999),
101+
sources_sort.get(str(record.get("source")), 99999),
104102
record["sourceId"],
105103
record.get("sourceIdVersion", ""),
106104
record["name"],

pori_python/ipr/types.py pori_python/types.py

+79-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
1-
from typing import Dict, List, Optional, Union
1+
from typing import Dict, List, Optional, Tuple, TypedDict, Union
22

3-
try:
4-
from typing import TypedDict # type: ignore
5-
except ImportError:
6-
from typing_extensions import TypedDict
3+
# TODO: Can constants in inputs.py like COPY_REQ, SMALL_MUT_REQ, just be replaced by types?
74

8-
from pori_python.graphkb.types import Ontology, Record
5+
CategoryBaseTermMapping = List[Tuple[str, List[str]]]
6+
Record = TypedDict("Record", {"@rid": str, "@class": str})
7+
EmbeddedRecord = TypedDict("EmbeddedRecord", {"@class": str})
8+
RecordLink = Union[str, Record]
99

10-
# TODO: Can constants in inputs.py like COPY_REQ, SMALL_MUT_REQ, just be replaced by types?
10+
11+
class Ontology(Record):
12+
sourceId: str
13+
name: str
14+
source: RecordLink
15+
displayName: str
16+
17+
18+
class OntologyTerm(Record):
19+
name: Optional[str]
20+
sourceId: Optional[str]
21+
sourceIdVersion: Optional[str]
22+
displayName: Optional[str]
23+
24+
25+
OntologyLink = Union[str, Ontology]
26+
27+
28+
class BasicPosition(EmbeddedRecord):
29+
pos: int
30+
31+
32+
class CytobandPosition(EmbeddedRecord):
33+
arm: str
34+
majorBand: str
35+
minorBand: str
36+
37+
38+
Position = Union[BasicPosition, CytobandPosition]
39+
40+
41+
class Variant(Record):
42+
reference1: OntologyLink
43+
reference2: Optional[OntologyLink]
44+
type: OntologyLink
45+
zygosity: str
46+
germline: bool
47+
displayName: str
48+
49+
50+
class PositionalVariant(Variant):
51+
break1Start: Union[Position, CytobandPosition]
52+
break1End: Optional[Union[Position, CytobandPosition]]
53+
break2Start: Optional[Union[Position, CytobandPosition]]
54+
break2End: Optional[Union[Position, CytobandPosition]]
55+
refSeq: Optional[str]
56+
untemplatedSeq: Optional[str]
57+
untemplatedSeqSize: Optional[int]
58+
59+
60+
class ParsedVariant(TypedDict):
61+
reference1: str
62+
reference2: Optional[str]
63+
type: str
64+
zygosity: str
65+
germline: bool
66+
break1Start: Union[Position, CytobandPosition]
67+
break1End: Optional[Union[Position, CytobandPosition]]
68+
break2Start: Optional[Union[Position, CytobandPosition]]
69+
break2End: Optional[Union[Position, CytobandPosition]]
70+
refSeq: Optional[str]
71+
untemplatedSeq: Optional[str]
72+
untemplatedSeqSize: Optional[int]
73+
74+
75+
class Statement(Record):
76+
relevance: OntologyLink
77+
subject: OntologyLink
78+
conditions: List[OntologyLink]
79+
evidence: List[OntologyLink]
80+
evidenceLevel: List[OntologyLink]
81+
source: RecordLink
82+
sourceId: str
1183

1284

1385
class KbMatch(TypedDict):

0 commit comments

Comments
 (0)