Skip to content

Commit dd5c07d

Browse files
authored
Merge pull request #128 from pbashyal-nmdp/0.6.x-fix
Fix Batch Reduce
2 parents db73cf1 + e329e5e commit dd5c07d

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

extras/reduce_conf.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"apply_compression": "gzip",
3131
"reduce_serology": false,
3232
"reduce_v2": true,
33+
"convert_v2_to_v3": false,
3334
"reduce_3field": true,
3435
"reduce_P": true,
3536
"reduce_XX": false,

pyard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
from .pyard import ARD
2525

2626
__author__ = """NMDP Bioinformatics"""
27-
__version__ = '0.6.9'
27+
__version__ = '0.6.10'

scripts/pyard-reduce-csv

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ import pyard.drbx as drbx
4040

4141

4242
def is_serology(allele: str) -> bool:
43-
if len(allele.split(':')) == 1:
44-
return True
43+
return ard.is_serology(allele)
4544

4645

4746
def is_3field(allele: str) -> bool:
@@ -52,7 +51,11 @@ def is_P(allele: str) -> bool:
5251
if allele.endswith('P'):
5352
fields = allele.split(':')
5453
if len(fields) == 2: # Ps are 2 fields
55-
return fields[0].isdigit() and fields[0].isdigit()
54+
# Check both fields are digits only
55+
# Eg: A*02:01P
56+
# Check last 2 digits of first field: 02 is numeric
57+
# Check digits of seconds field: 01 is numeric
58+
return fields[0][-2:].isdigit() and fields[1][:-1].isdigit()
5659
return False
5760

5861

@@ -83,6 +86,11 @@ def should_be_reduced(allele, locus_allele):
8386
return False
8487

8588

89+
def remove_locus_name(reduced_allele):
90+
return "/".join(map(lambda a: a.split('*')[1],
91+
reduced_allele.split('/')))
92+
93+
8694
def reduce(allele, locus, column_name):
8795
# Does the allele name have the locus in it ?
8896
if allele == '':
@@ -111,16 +119,23 @@ def reduce(allele, locus, column_name):
111119
if ard_config["keep_locus_in_allele_name"]:
112120
allele = reduced_allele
113121
else:
114-
allele = "/".join(map(lambda a: a.split('*')[1],
115-
reduced_allele.split('/')))
122+
allele = remove_locus_name(reduced_allele)
116123
else:
117124
if verbose:
118125
print(f"Failed to reduce {locus_allele}")
119-
120126
if verbose:
121127
print(f"\t{locus_allele} => {allele}")
122128
else:
123-
if ard_config["keep_locus_in_allele_name"]:
129+
if ard_config['convert_v2_to_v3']:
130+
if ard.is_v2(locus_allele):
131+
v3_allele = ard.v2_to_v3(locus_allele)
132+
if not ard_config["keep_locus_in_allele_name"]:
133+
allele = remove_locus_name(v3_allele)
134+
else:
135+
allele = v3_allele
136+
if verbose:
137+
print(f"\t{locus_allele} => {allele}")
138+
elif ard_config["keep_locus_in_allele_name"]:
124139
allele = locus_allele
125140

126141
return allele
@@ -170,7 +185,7 @@ if __name__ == '__main__':
170185
sys.exit(1)
171186

172187
# Instantiate py-ard object with the latest
173-
ard = pyard.ARD(remove_invalid=False)
188+
ard = pyard.ARD()
174189

175190
# Read the Input File
176191
# Read only the columns to be saved.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.6.9
2+
current_version = 0.6.10
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
setup(
4444
name='py-ard',
45-
version='0.6.9',
45+
version='0.6.10',
4646
description="ARD reduction for HLA with Python",
4747
long_description=readme + '\n\n' + history,
4848
author="CIBMTR",

0 commit comments

Comments
 (0)