Skip to content

Commit 2b22fcf

Browse files
committed
Cleanup
- Remove circular dependency of mapping by moving all to `mappings.py` - Constants moved to `constants.py`
1 parent 3b40691 commit 2b22fcf

File tree

10 files changed

+50
-42
lines changed

10 files changed

+50
-42
lines changed

pyard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
from .blender import blender as dr_blender
2525
from .broad_splits import find_splits as find_broad_splits
26-
from .misc import DEFAULT_CACHE_SIZE
26+
from .constants import DEFAULT_CACHE_SIZE
2727
from .misc import get_imgt_db_versions as db_versions
2828

2929
__author__ = """NMDP Bioinformatics"""

pyard/ard.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
from .misc import (
3434
get_n_field_allele,
3535
get_2field_allele,
36-
expression_chars,
37-
DEFAULT_CACHE_SIZE,
36+
validate_reduction_type,
37+
)
38+
from .constants import (
3839
HLA_regex,
3940
VALID_REDUCTION_TYPES,
40-
validate_reduction_type,
41+
expression_chars,
42+
DEFAULT_CACHE_SIZE,
4143
)
4244
from .smart_sort import smart_sort_comparator
4345

pyard/constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import re
2+
3+
DEFAULT_CACHE_SIZE = 1_000
4+
5+
HLA_regex = re.compile("^HLA-")
6+
7+
VALID_REDUCTION_TYPES = ["G", "P", "lg", "lgx", "W", "exon", "U2"]
8+
expression_chars = ["N", "Q", "L", "S"]
9+
# List of P and G characters
10+
PandG_chars = ["P", "G"]

pyard/data_repository.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import copy
2424
import functools
2525
import sqlite3
26-
from collections import namedtuple
2726

2827
import pandas as pd
2928

@@ -37,32 +36,15 @@
3736
load_serology_mappings,
3837
load_latest_version,
3938
)
40-
from .misc import expression_chars
39+
from .constants import expression_chars
40+
from .mappings import ars_mapping_tables, ARSMapping, code_mapping_tables
4141
from .misc import (
4242
get_2field_allele,
4343
get_3field_allele,
4444
number_of_fields,
4545
get_1field_allele,
4646
)
4747

48-
ars_mapping_tables = [
49-
"dup_g",
50-
"dup_lgx",
51-
"g_group",
52-
"p_group",
53-
"lgx_group",
54-
"exon_group",
55-
"p_not_g",
56-
]
57-
ARSMapping = namedtuple("ARSMapping", ars_mapping_tables)
58-
59-
code_mapping_tables = [
60-
"alleles",
61-
"xx_codes",
62-
"who_alleles",
63-
"who_group",
64-
]
65-
6648

6749
def expression_reduce(df):
6850
"""

pyard/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sqlite3
2525
from typing import Tuple, Dict, Set, List
2626

27-
from .data_repository import ARSMapping
27+
from .mappings import ARSMapping
2828
from .misc import get_imgt_db_versions, get_default_db_directory
2929

3030

pyard/mappings.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import namedtuple
2+
3+
ars_mapping_tables = [
4+
"dup_g",
5+
"dup_lgx",
6+
"g_group",
7+
"p_group",
8+
"lgx_group",
9+
"exon_group",
10+
"p_not_g",
11+
]
12+
code_mapping_tables = [
13+
"alleles",
14+
"exp_alleles",
15+
"xx_codes",
16+
"who_alleles",
17+
"who_group",
18+
]
19+
20+
ARSMapping = namedtuple("ARSMapping", ars_mapping_tables)

pyard/misc.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
# List of expression characters
22
import pathlib
3-
import re
43
import tempfile
54
from typing import List
65

7-
HLA_regex = re.compile("^HLA-")
8-
9-
VALID_REDUCTION_TYPES = ["G", "P", "lg", "lgx", "W", "exon", "U2"]
10-
expression_chars = ["N", "Q", "L", "S"]
11-
# List of P and G characters
12-
PandG_chars = ["P", "G"]
13-
14-
DEFAULT_CACHE_SIZE = 1_000
6+
from pyard.constants import VALID_REDUCTION_TYPES, expression_chars, PandG_chars
157

168

179
def get_n_field_allele(allele: str, n: int, preserve_expression=False) -> str:

scripts/pyard

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import argparse
2525
import sys
2626

27+
from pyard.constants import VALID_REDUCTION_TYPES
2728
import pyard.misc
2829
from pyard.exceptions import InvalidAlleleError
2930
from pyard.misc import get_data_dir, get_imgt_version
@@ -57,7 +58,7 @@ if __name__ == "__main__":
5758
parser.add_argument(
5859
"-r",
5960
"--redux-type",
60-
choices=pyard.misc.VALID_REDUCTION_TYPES,
61+
choices=VALID_REDUCTION_TYPES,
6162
dest="redux_type",
6263
help="Reduction Method",
6364
)
@@ -85,11 +86,12 @@ if __name__ == "__main__":
8586
if args.redux_type:
8687
print(ard.redux(args.gl_string, args.redux_type))
8788
else:
88-
for redux_type in pyard.misc.VALID_REDUCTION_TYPES:
89+
for redux_type in VALID_REDUCTION_TYPES:
8990
redux_type_info = f"Reduction Method: {redux_type}"
9091
print(redux_type_info)
9192
print("-" * len(redux_type_info))
9293
print(ard.redux(args.gl_string, redux_type))
94+
print()
9395
except InvalidAlleleError as e:
9496
print("Error:", e)
9597

scripts/pyard-status

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import os
2626
import re
2727

2828
import pyard
29+
import pyard.mappings
2930
from pyard import db, data_repository
3031
from pyard.misc import get_data_dir
3132

@@ -93,8 +94,8 @@ if __name__ == "__main__":
9394
print(f"|{'Table Name':20}|{'Rows':20}|")
9495
print(f"|{'-' * 41}|")
9596
for table in (
96-
data_repository.ars_mapping_tables
97-
+ data_repository.code_mapping_tables
97+
pyard.mappings.ars_mapping_tables
98+
+ pyard.mappings.code_mapping_tables
9899
+ ["mac_codes"]
99100
):
100101
if db.table_exists(db_connection, table):

tests/test_pyard.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import unittest
3434

3535
import pyard
36+
from pyard.constants import DEFAULT_CACHE_SIZE
3637
from pyard.exceptions import InvalidAlleleError, InvalidMACError, InvalidTypingError
3738
from pyard.misc import validate_reduction_type
3839

@@ -170,11 +171,9 @@ def test_xx_codes_broad_split(self):
170171
def test_cache_info(self):
171172
# validate the default cache size
172173
self.assertEqual(
173-
self.ard._redux_allele.cache_info().maxsize, pyard.misc.DEFAULT_CACHE_SIZE
174-
)
175-
self.assertEqual(
176-
self.ard.redux.cache_info().maxsize, pyard.misc.DEFAULT_CACHE_SIZE
174+
self.ard._redux_allele.cache_info().maxsize, DEFAULT_CACHE_SIZE
177175
)
176+
self.assertEqual(self.ard.redux.cache_info().maxsize, DEFAULT_CACHE_SIZE)
178177
# validate you can change the cache size
179178
higher_cache_size = 5_000_000
180179
another_ard = pyard.init(

0 commit comments

Comments
 (0)