Skip to content

Commit 6e874ad

Browse files
authored
Merge pull request #215 from pbashyal-nmdp/refactor_to_1.0
Refactor to 1.0 (Release Candidate Version)
2 parents efe0b36 + b2d513b commit 6e874ad

22 files changed

+635
-526
lines changed

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,30 @@ Import `pyard` package.
4848
import pyard
4949
```
5050

51-
The cache size of pre-computed reductions can be changed from the default of 1000 (_not working_: will be fixed in a later release.)
52-
```python
53-
pyard.max_cache_size = 1_000_000
54-
```
5551

5652
Initialize `ARD` object with a version of IMGT HLA database
5753

5854
```python
59-
ard = pyard.ARD(3290)
55+
import pyard
56+
57+
ard = pyard.init('3510')
58+
```
59+
60+
The cache size of pre-computed reductions can be changed from the default of 1000
61+
```python
62+
import pyard
63+
64+
max_cache_size = 1_000_000
65+
ard = pyard.init('3510', cache_size=max_cache_size)
66+
6067
```
6168

6269
You can specify a different directory for the cached data.
6370

6471
```python
65-
ard = pyard.ARD('3290', data_dir='/tmp/py-ard')
72+
import pyard.ard
73+
74+
ard = pyard.init('3510', data_dir='/tmp/py-ard')
6675
```
6776

6877
You can choose to refresh the MAC code for current IMGT HLA database version
@@ -74,7 +83,9 @@ ard.refresh_mac_codes()
7483
The default initialization is to use the latest IMGT HLA database
7584

7685
```python
77-
ard = pyard.ARD()
86+
import pyard
87+
88+
ard = pyard.init()
7889
```
7990

8091
### Reduce Typings
@@ -84,13 +95,13 @@ Reduce a single locus HLA Typing.
8495
```python
8596
allele = "A*01:01:01"
8697

87-
ard.redux_gl(allele, 'G')
98+
ard.redux(allele, 'G')
8899
# >>> 'A*01:01:01G'
89100

90-
ard.redux_gl(allele, 'lg')
101+
ard.redux(allele, 'lg')
91102
# >>> 'A*01:01g'
92103

93-
ard.redux_gl(allele, 'lgx')
104+
ard.redux(allele, 'lgx')
94105
# >>> 'A*01:01'
95106
```
96107

@@ -99,14 +110,14 @@ Reduce an ambiguous GL String
99110
```python
100111
# Reduce GL String
101112
#
102-
ard.redux_gl("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
113+
ard.redux("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
103114
# 'B*07:02:01G+B*07:02:01G^A*01:01:01G+A*02:01:01G/A*02:02'
104115
```
105116

106117
You can also reduce serology based typings.
107118

108119
```python
109-
ard.redux_gl('B14', 'lg')
120+
ard.redux('B14', 'lg')
110121
# >>> 'B*14:01g/B*14:02g/B*14:03g/B*14:04g/B*14:05g/B*14:06g/B*14:08g/B*14:09g/B*14:10g/B*14:11g/B*14:12g/B*14:13g/B*14:14g/B*14:15g/B*14:16g/B*14:17g/B*14:18g/B*14:19g/B*14:20g/B*14:21g/B*14:22g/B*14:23g/B*14:24g/B*14:25g/B*14:26g/B*14:27g/B*14:28g/B*14:29g/B*14:30g/B*14:31g/B*14:32g/B*14:33g/B*14:34g/B*14:35g/B*14:36g/B*14:37g/B*14:38g/B*14:39g/B*14:40g/B*14:42g/B*14:43g/B*14:44g/B*14:45g/B*14:46g/B*14:47g/B*14:48g/B*14:49g/B*14:50g/B*14:51g/B*14:52g/B*14:53g/B*14:54g/B*14:55g/B*14:56g/B*14:57g/B*14:58g/B*14:59g/B*14:60g/B*14:62g/B*14:63g/B*14:65g/B*14:66g/B*14:68g/B*14:70Qg/B*14:71g/B*14:73g/B*14:74g/B*14:75g/B*14:77g/B*14:82g/B*14:83g/B*14:86g/B*14:87g/B*14:88g/B*14:90g/B*14:93g/B*14:94g/B*14:95g/B*14:96g/B*14:97g/B*14:99g/B*14:102g'
111122
```
112123

api-spec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.0.3
22
info:
33
title: ARD Reduction
44
description: Reduce to ARD Level
5-
version: "0.9.1"
5+
version: "1.0.0rc1"
66
servers:
77
- url: 'http://localhost:8080'
88
tags:
@@ -14,6 +14,8 @@ tags:
1414
description: Expand MAC to alleles
1515
- name: DRBX Blender
1616
description: Blend DRBX based on DRB1 and DRB3/4/5
17+
- name: Validation
18+
description: Validate a GL String or Allele
1719
paths:
1820
/version:
1921
get:
@@ -134,7 +136,7 @@ paths:
134136
/validate:
135137
post:
136138
tags:
137-
- ARD Reduction
139+
- Validation
138140
operationId: api.validate_controller
139141
summary: Validate GL String
140142
description: |

api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from flask import request
22

33
import pyard
4-
from pyard import ARD
54
from pyard.blender import DRBXBlenderError
65
from pyard.exceptions import PyArdError, InvalidAlleleError
76

87
# Globally accessible for all endpoints
9-
ard = ARD()
8+
ard = pyard.init()
109

1110

1211
def validate_controller():
@@ -40,8 +39,8 @@ def redux_controller():
4039
return {"message": "gl_string and reduction_method not provided"}, 404
4140
# Perform redux
4241
try:
43-
redux_gl_string = ard.redux_gl(gl_string, reduction_method)
44-
return {"ard": redux_gl_string}, 200
42+
redux_string = ard.redux(gl_string, reduction_method)
43+
return {"ard": redux_string}, 200
4544
except PyArdError as e:
4645
return {"message": e.message}, 400
4746

pyard/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from functools import lru_cache
23

34
#
45
# pyard pyARD.
@@ -21,10 +22,29 @@
2122
# > http://www.fsf.org/licensing/licenses/lgpl.html
2223
# > http://www.opensource.org/licenses/lgpl-license.php
2324
#
24-
from .pyard import ARD
2525
from .blender import blender as dr_blender
2626
from .broad_splits import find_splits as find_broad_splits
2727
from .misc import get_imgt_db_versions as db_versions
28+
from .misc import DEFAULT_CACHE_SIZE
2829

2930
__author__ = """NMDP Bioinformatics"""
30-
__version__ = "0.9.1"
31+
__version__ = "1.0.0rc1"
32+
33+
34+
def init(
35+
imgt_version: str = "Latest",
36+
data_dir: str = None,
37+
load_mac: bool = True,
38+
cache_size: int = DEFAULT_CACHE_SIZE,
39+
config: dict = None,
40+
):
41+
from .ard import ARD
42+
43+
ard = ARD(
44+
imgt_version=imgt_version,
45+
data_dir=data_dir,
46+
load_mac=load_mac,
47+
max_cache_size=cache_size,
48+
config=config,
49+
)
50+
return ard

0 commit comments

Comments
 (0)