Skip to content

Commit 39b59a1

Browse files
authored
Merge pull request #41 from pbashyal-nmdp/master
Specify a path for temp files
2 parents 3049b48 + 21272d4 commit 39b59a1

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

README.rst

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ py-ard
77
:target: https://pypi.python.org/pypi/py-ard
88

99
.. image:: https://readthedocs.org/projects/pyars/badge/?version=latest
10-
:target: https://pyars.readthedocs.io/en/latest/?badge=latest
10+
:target: https://pyard.readthedocs.io/en/latest/?badge=latest
1111
:alt: Documentation Status
1212

1313

@@ -22,45 +22,48 @@ Install from source
2222

2323
.. code-block::
2424
25-
python3 -m venv venv
26-
source venv/bin/activate
25+
python3 -m venv venv
26+
source venv/bin/activate
2727
28-
python setup.py install
28+
python setup.py install
2929
3030
Install from PyPi
3131
-----------------
3232

3333
.. code-block::
3434
35-
pip install py-ard
35+
pip install py-ard
3636
3737
3838
Example
3939
-------
4040

4141
.. code-block:: python3
4242
43-
from pyard import ARD
43+
from pyard import ARD
4444
45-
# Initialize ARD object
46-
ard = ARD('3290')
45+
# Initialize ARD object
46+
ard = ARD('3290')
4747
48-
# Initialize with latest DB
49-
ard = ARD()
48+
# You can specify a data directory for temp files
49+
# ard = ard = ARD('3290', data_dir='/tmp/py-ard')
5050
51-
allele = "A*01:01:01"
51+
# Initialize with latest DB
52+
ard = ARD()
5253
53-
ard.redux(allele, 'G')
54-
# >> 'A*01:01:01G'
54+
allele = "A*01:01:01"
5555
56-
ard.redux(allele, 'lg')
57-
# >> 'A*01:01g'
56+
ard.redux(allele, 'G')
57+
# >> 'A*01:01:01G'
5858
59-
ard.redux(allele, 'lgx')
60-
# 'A*01:01'
59+
ard.redux(allele, 'lg')
60+
# >> 'A*01:01g'
6161
62-
ard_gl = ard.redux_gl("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
63-
# >>> ard_gl
64-
# 'B*07:02:01G+B*07:02:01G^A*01:01:01G+A*02:01:01G/A*02:02'
62+
ard.redux(allele, 'lgx')
63+
# 'A*01:01'
64+
65+
ard_gl = ard.redux_gl("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
66+
# >>> ard_gl
67+
# 'B*07:02:01G+B*07:02:01G^A*01:01:01G+A*02:01:01G/A*02:02'
6568
6669

pyard/pyard.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from functools import partial
3636
from typing import Dict
3737
import logging
38+
import pathlib
3839

3940
ismac = lambda x: True if re.search(":\D+", x) else False
4041

@@ -79,7 +80,8 @@ class ARD(object):
7980
def __init__(self, dbversion: str='Latest',
8081
download_mac: bool=True,
8182
verbose: bool=False,
82-
remove_invalid: bool=True):
83+
remove_invalid: bool=True,
84+
data_dir: str=None):
8385
"""
8486
ARD -
8587
:param dbversion:
@@ -117,14 +119,20 @@ def __init__(self, dbversion: str='Latest',
117119

118120
# List of expression characters
119121
expre_chars = ['N', 'Q', 'L', 'S']
120-
data_dir = os.path.dirname(__file__)
121-
ars_url = 'https://raw.githubusercontent.com/ANHIG/IMGTHLA/' \
122-
+ dbversion + '/wmda/hla_nom_g.txt'
122+
123+
# Set data directory where all the downloaded files will go
124+
if data_dir is None:
125+
data_dir = os.path.dirname(__file__)
126+
else:
127+
pathlib.Path(data_dir).mkdir(exist_ok=True)
128+
129+
imgt_hla_url = 'https://raw.githubusercontent.com/ANHIG/IMGTHLA/'
130+
ars_url = imgt_hla_url + dbversion + '/wmda/hla_nom_g.txt'
123131
ars_file = data_dir + '/hla_nom_g.' + str(dbversion) + ".txt"
124132
allele_file = data_dir + '/AlleleList.' + str(dbversion) + ".txt"
125133
mac_file = data_dir + "/mac.txt"
126134
mac_pickle = data_dir + "/mac.pickle"
127-
broad_file = data_dir + "/dna_relshp.csv"
135+
broad_file = os.path.dirname(__file__) + "/dna_relshp.csv"
128136
#print("mac_file:", mac_file)
129137

130138
allele_url = "https://raw.githubusercontent.com/ANHIG/IMGTHLA/" \

pyard/smart_sort.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
22
import re
33

4-
expr_regex = re.compile('[NQLS]')
4+
expr_regex = re.compile('[NQLSGg]')
55

66
@functools.lru_cache(maxsize=None)
77
def smart_sort_comparator(a1, a2):

0 commit comments

Comments
 (0)