Skip to content

Commit

Permalink
Merge pull request #215 from pbashyal-nmdp/refactor_to_1.0
Browse files Browse the repository at this point in the history
Refactor to 1.0 (Release Candidate Version)
  • Loading branch information
mmaiers-nmdp authored Feb 27, 2023
2 parents efe0b36 + b2d513b commit 6e874ad
Show file tree
Hide file tree
Showing 22 changed files with 635 additions and 526 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,30 @@ Import `pyard` package.
import pyard
```

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

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

```python
ard = pyard.ARD(3290)
import pyard

ard = pyard.init('3510')
```

The cache size of pre-computed reductions can be changed from the default of 1000
```python
import pyard

max_cache_size = 1_000_000
ard = pyard.init('3510', cache_size=max_cache_size)

```

You can specify a different directory for the cached data.

```python
ard = pyard.ARD('3290', data_dir='/tmp/py-ard')
import pyard.ard

ard = pyard.init('3510', data_dir='/tmp/py-ard')
```

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

```python
ard = pyard.ARD()
import pyard

ard = pyard.init()
```

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

ard.redux_gl(allele, 'G')
ard.redux(allele, 'G')
# >>> 'A*01:01:01G'

ard.redux_gl(allele, 'lg')
ard.redux(allele, 'lg')
# >>> 'A*01:01g'

ard.redux_gl(allele, 'lgx')
ard.redux(allele, 'lgx')
# >>> 'A*01:01'
```

Expand All @@ -99,14 +110,14 @@ Reduce an ambiguous GL String
```python
# Reduce GL String
#
ard.redux_gl("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
ard.redux("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
# 'B*07:02:01G+B*07:02:01G^A*01:01:01G+A*02:01:01G/A*02:02'
```

You can also reduce serology based typings.

```python
ard.redux_gl('B14', 'lg')
ard.redux('B14', 'lg')
# >>> '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'
```

Expand Down
6 changes: 4 additions & 2 deletions api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: ARD Reduction
description: Reduce to ARD Level
version: "0.9.1"
version: "1.0.0rc1"
servers:
- url: 'http://localhost:8080'
tags:
Expand All @@ -14,6 +14,8 @@ tags:
description: Expand MAC to alleles
- name: DRBX Blender
description: Blend DRBX based on DRB1 and DRB3/4/5
- name: Validation
description: Validate a GL String or Allele
paths:
/version:
get:
Expand Down Expand Up @@ -134,7 +136,7 @@ paths:
/validate:
post:
tags:
- ARD Reduction
- Validation
operationId: api.validate_controller
summary: Validate GL String
description: |
Expand Down
7 changes: 3 additions & 4 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from flask import request

import pyard
from pyard import ARD
from pyard.blender import DRBXBlenderError
from pyard.exceptions import PyArdError, InvalidAlleleError

# Globally accessible for all endpoints
ard = ARD()
ard = pyard.init()


def validate_controller():
Expand Down Expand Up @@ -40,8 +39,8 @@ def redux_controller():
return {"message": "gl_string and reduction_method not provided"}, 404
# Perform redux
try:
redux_gl_string = ard.redux_gl(gl_string, reduction_method)
return {"ard": redux_gl_string}, 200
redux_string = ard.redux(gl_string, reduction_method)
return {"ard": redux_string}, 200
except PyArdError as e:
return {"message": e.message}, 400

Expand Down
24 changes: 22 additions & 2 deletions pyard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from functools import lru_cache

#
# pyard pyARD.
Expand All @@ -21,10 +22,29 @@
# > http://www.fsf.org/licensing/licenses/lgpl.html
# > http://www.opensource.org/licenses/lgpl-license.php
#
from .pyard import ARD
from .blender import blender as dr_blender
from .broad_splits import find_splits as find_broad_splits
from .misc import get_imgt_db_versions as db_versions
from .misc import DEFAULT_CACHE_SIZE

__author__ = """NMDP Bioinformatics"""
__version__ = "0.9.1"
__version__ = "1.0.0rc1"


def init(
imgt_version: str = "Latest",
data_dir: str = None,
load_mac: bool = True,
cache_size: int = DEFAULT_CACHE_SIZE,
config: dict = None,
):
from .ard import ARD

ard = ARD(
imgt_version=imgt_version,
data_dir=data_dir,
load_mac=load_mac,
max_cache_size=cache_size,
config=config,
)
return ard
Loading

0 comments on commit 6e874ad

Please sign in to comment.