Skip to content

Commit 48fc326

Browse files
committed
Command Line Tool py-ard-import to import a new database
Command Line Tool `py-ard` to reduce a GL String
1 parent 589cfc5 commit 48fc326

File tree

4 files changed

+207
-4
lines changed

4 files changed

+207
-4
lines changed

README.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,31 @@ Example
8888
# 'HLA-A*24:19g/HLA-A*24:22g^HLA-A*26:01g/HLA-A*26:10g/HLA-A*26:15g/HLA-A*26:92g/HLA-A*66:01g/HLA-A*66:03g'
8989
9090
91+
Command Line Tools
92+
------------------
93+
94+
.. code-block:: bash
95+
96+
# Import the latest IMGT database
97+
$ pyard-import
98+
Created Latest py-ard database
99+
100+
# Import particular version of IMGT database
101+
$ pyard-import --import-db-version 3.29.0
102+
Created py-ard version 3290 database
103+
104+
# Import particular version of IMGT database and
105+
# replace the v2 to v3 mapping table
106+
$ pyard-import --import-db-version 3.29.0 --v2-to-v3-mapping map2to3.csv
107+
Created py-ard version 3290 database
108+
Updated v2_mapping table with 'map2to3.csv' mapping file.
109+
110+
# Reduce a gl string from command line
111+
$ pyard --gl 'A*01:AB' -r lgx
112+
A*01:01/A*01:02
113+
114+
$ pyard --gl 'DRB1*08:XX' -r G
115+
DRB1*08:01:01G/DRB1*08:02:01G/DRB1*08:03:02G/DRB1*08:04:01G/DRB1*08:05/ ...
116+
117+
$ pyard -v 3290 --gl 'A1' -r lgx
118+
A*01:01/A*01:02/A*01:03/A*01:06/A*01:07/A*01:08/A*01:09/A*01:10/A*01:12/ ...

scripts/pyard

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# py-ard
5+
# Copyright (c) 2020 Be The Match operated by National Marrow Donor Program. All Rights Reserved.
6+
#
7+
# This library is free software; you can redistribute it and/or modify it
8+
# under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation; either version 3 of the License, or (at
10+
# your option) any later version.
11+
#
12+
# This library is distributed in the hope that it will be useful, but WITHOUT
13+
# ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
14+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15+
# License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this library; if not, write to the Free Software Foundation,
19+
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20+
#
21+
# > http://www.fsf.org/licensing/licenses/lgpl.html
22+
# > http://www.opensource.org/licenses/lgpl-license.php
23+
#
24+
import argparse
25+
26+
import pyard
27+
28+
29+
def get_imgt_version(imgt_version):
30+
if imgt_version:
31+
version = imgt_version.replace('.', '')
32+
if version.isdigit():
33+
return version
34+
raise RuntimeError(f"{imgt_version} is not a valid IMGT database version number")
35+
return None
36+
37+
38+
if __name__ == '__main__':
39+
parser = argparse.ArgumentParser(
40+
usage="""[-v <IMGT DB Version>] [gl-string redux_type]""",
41+
description="""py-ard tool to redux GL String"""
42+
)
43+
parser.add_argument(
44+
"-v",
45+
"--imgt-version",
46+
dest="imgt_version"
47+
)
48+
parser.add_argument(
49+
"--gl",
50+
required=True,
51+
dest="gl_string"
52+
)
53+
parser.add_argument(
54+
"-r",
55+
choices=['G', 'lg', 'lgx'],
56+
required=True,
57+
dest="redux_type"
58+
)
59+
60+
args = parser.parse_args()
61+
62+
imgt_version = get_imgt_version(args.imgt_version)
63+
if imgt_version:
64+
ard = pyard.ARD(imgt_version)
65+
else:
66+
ard = pyard.ARD()
67+
68+
print(ard.redux_gl(args.gl_string, args.redux_type))
69+
del ard

scripts/pyard-import

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# py-ard
5+
# Copyright (c) 2020 Be The Match operated by National Marrow Donor Program. All Rights Reserved.
6+
#
7+
# This library is free software; you can redistribute it and/or modify it
8+
# under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation; either version 3 of the License, or (at
10+
# your option) any later version.
11+
#
12+
# This library is distributed in the hope that it will be useful, but WITHOUT
13+
# ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
14+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15+
# License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this library; if not, write to the Free Software Foundation,
19+
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20+
#
21+
# > http://www.fsf.org/licensing/licenses/lgpl.html
22+
# > http://www.opensource.org/licenses/lgpl-license.php
23+
#
24+
import argparse
25+
import pathlib
26+
27+
import pyard
28+
from pyard import db
29+
import pandas as pd
30+
31+
32+
def get_imgt_version(imgt_version):
33+
if imgt_version:
34+
version = imgt_version.replace('.', '')
35+
if version.isdigit():
36+
return version
37+
raise RuntimeError(f"{imgt_version} is not a valid IMGT database version number")
38+
return None
39+
40+
41+
def get_data_dir(data_dir):
42+
if data_dir:
43+
path = pathlib.Path(data_dir)
44+
if not path.exists() or not path.is_dir():
45+
raise RuntimeError(f"{data_dir} is not a valid directory")
46+
return data_dir
47+
48+
49+
def get_v2_v3_mapping(v2_v3_mapping):
50+
if v2_v3_mapping:
51+
path = pathlib.Path(v2_v3_mapping)
52+
if not path.exists() or not path.is_file():
53+
raise RuntimeError(f"{data_dir} is not a valid file")
54+
df = pd.read_csv(path, names=['v2', 'v3'])
55+
return df.set_index('v2')['v3'].to_dict()
56+
return None
57+
58+
59+
if __name__ == '__main__':
60+
parser = argparse.ArgumentParser(
61+
usage="""[--import-db-version <IMGT DB Version>]\
62+
[--data-dir <directory for db file>]\
63+
[--v2-to-v3-mapping <V2 to V3 mapping CSV file>]""",
64+
description="""py-ard tool to generate reference SQLite database.\
65+
Allows updating db with custom mappings."""
66+
)
67+
parser.add_argument(
68+
"--import-db-version",
69+
dest="imgt_version"
70+
)
71+
parser.add_argument(
72+
"--data-dir",
73+
dest="data_dir"
74+
)
75+
parser.add_argument(
76+
"--v2-to-v3-mapping",
77+
dest="v2_v3_mapping"
78+
)
79+
args = parser.parse_args()
80+
81+
imgt_version = get_imgt_version(args.imgt_version)
82+
# print(imgt_version)
83+
84+
data_dir = get_data_dir(args.data_dir)
85+
# print(data_dir)
86+
87+
v2_to_v3_dict = get_v2_v3_mapping(args.v2_v3_mapping)
88+
# print(len(v2_to_v3_dict))
89+
90+
if imgt_version:
91+
ard = pyard.ARD(imgt_version=imgt_version, data_dir=data_dir)
92+
print(f"Created py-ard version {imgt_version} database")
93+
else:
94+
ard = pyard.ARD(data_dir=data_dir)
95+
print(f"Created Latest py-ard database")
96+
del ard
97+
98+
if v2_to_v3_dict:
99+
db_connection = db.create_db_connection(data_dir, imgt_version, ro=False)
100+
db.save_dict(db_connection, table_name='v2_mapping',
101+
dictionary=v2_to_v3_dict, columns=('v2', 'v3'))
102+
print(f"Updated v2_mapping table with '{args.v2_v3_mapping}' mapping file.")

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,27 @@
3535
'pandas>=1.1.4'
3636
]
3737

38-
3938
test_requirements = [
40-
# TODO: put package test requirements here
39+
'behave==1.2.6',
40+
'PyHamcrest==2.0.2'
4141
]
4242

4343
setup(
4444
name='py-ard',
4545
version='0.5.1',
46-
description="ARD reduction for HLA with python",
46+
description="ARD reduction for HLA with Python",
4747
long_description=readme + '\n\n' + history,
4848
author="CIBMTR",
4949
author_email='[email protected]',
5050
url='https://github.com/nmdp-bioinformatics/py-ard',
5151
packages=[
5252
'pyard',
5353
],
54-
package_dir={'pyard': 'pyard'},
54+
provides=['pyard'],
55+
scripts=[
56+
'scripts/pyard',
57+
'scripts/pyard-import',
58+
],
5559
install_requires=requirements,
5660
license="LGPL 3.0",
5761
zip_safe=False,

0 commit comments

Comments
 (0)