Skip to content

Commit 941b545

Browse files
authored
implement multiple shortnulls for a single who group (#159)
1 parent c9876c2 commit 941b545

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

pyard/data_repository.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,23 @@ def generate_alleles_and_xx_codes_and_who(db_connection: sqlite3.Connection, img
325325
shortnulls = dict()
326326
for who in who_group:
327327
# e.g. DRB4*01:03
328-
expression_alleles=[]
329-
expression_chars_found = set()
328+
expression_alleles = dict()
330329
if who[-1] not in expression_chars and who[-1] not in ['G', 'P'] and ":" in who:
331330
for an_allele in who_group[who]:
332331
# if an allele in a who_group has an expression character but the group allele doesnt,
333332
# add it to shortnulls
334333
last_char = an_allele[-1]
335334
if last_char in expression_chars:
336335
# e.g. DRB4*01:03:01:02N
337-
expression_chars_found.add(last_char)
338-
# add this allele to the set that this short null exapands to
339-
expression_alleles.append(an_allele)
336+
a_shortnull = who + last_char
337+
if a_shortnull not in expression_alleles:
338+
expression_alleles[a_shortnull] = []
339+
expression_alleles[a_shortnull].append(an_allele)
340340
# only create a shortnull if there is one expression character in this who_group
341341
# there is nothing to be done for who_groups that have both Q and L for example
342-
if expression_alleles:
343-
if len(expression_chars_found) ==1:
344-
# e.g. DRB4*01:03N
345-
a_shortnull = who + list(expression_chars_found)[0]
346-
shortnulls[a_shortnull] = "/".join(expression_alleles)
342+
for a_shortnull in expression_alleles:
343+
# e.g. DRB4*01:03N
344+
shortnulls[a_shortnull] = "/".join(expression_alleles[a_shortnull])
347345

348346
db.save_dict(db_connection, 'shortnulls', shortnulls, ('shortnull', 'allele_list'))
349347
shortnulls = {k: v.split('/') for k, v in shortnulls.items()}

pyard/pyard.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ def redux_gl(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:
317317
# Handle shortnulls
318318
if self._config["reduce_shortnull"] and self.is_shortnull(glstring):
319319
return self.redux_gl("/".join(self.shortnulls[glstring]), redux_type)
320-
#return self.redux_gl(self.shortnulls[glstring], redux_type)
321320

322321
return self.redux(glstring, redux_type)
323322

tests/features/shortnulls.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: shortnull
2+
3+
Scenario Outline:
4+
5+
Given the allele as <Allele>
6+
When reducing on the <Level> level (ambiguous)
7+
Then the reduced allele is found to be <Redux Allele>
8+
9+
10+
Examples: shortnulls
11+
| Allele | Level | Redux Allele |
12+
| DRB4*01:03N | lgx | DRB4*01:01 |
13+
| DRB4*01:03N | exon | DRB4*01:03:01 |
14+
| DRB4*01:03N | W | DRB4*01:03:01:02N/DRB4*01:03:01:13N |
15+
| DRB4*01:03:01N | lgx | DRB4*01:01 |
16+
| DRB4*01:03:01N | exon | DRB4*01:03:01 |
17+
| DRB4*01:03:01N | W | DRB4*01:03:01:02N/DRB4*01:03:01:13N |
18+
| DRB5*01:08N | lgx | DRB5*01:02/DRB5*01:08 |
19+
| DRB5*01:08N | exon | DRB5*01:08:01N/DRB5*01:08:02N |
20+
| DRB5*01:08N | W | DRB5*01:08:01N/DRB5*01:08:02N |

0 commit comments

Comments
 (0)