-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from pbashyal-nmdp/drbx_blender
Support DRBX Blending
- Loading branch information
Showing
11 changed files
with
358 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
# drbx blender | ||
|
||
|
||
def blender(drb1, drb3="", drb4="", drb5=""): | ||
try: | ||
drb1_1, drb1_2 = drb1.split("+") | ||
drb1_allele_1 = drb1_1.split("*")[1] | ||
drb1_allele_2 = drb1_2.split("*")[1] | ||
drb1_fam_1 = drb1_allele_1.split(":")[0] | ||
drb1_fam_2 = drb1_allele_2.split(":")[0] | ||
except Exception: | ||
return "" | ||
x1 = expdrbx(drb1_fam_1) | ||
x2 = expdrbx(drb1_fam_2) | ||
xx = "".join(sorted([x1, x2])) | ||
|
||
if xx == "00": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
return "" | ||
|
||
# handle 03 | ||
if xx == "03": | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
if drb3 != "": | ||
# if 2 copies | ||
drb3_g = drb3.split("+") | ||
if len(drb3_g) == 2: | ||
# homozygous, return one copy | ||
if drb3_g[1] == drb3_g[0]: | ||
return drb3_g[0] | ||
else: | ||
raise DRBXBlenderError("DRB3 het", "hom") | ||
else: | ||
return drb3 | ||
return "" | ||
|
||
# handle 04 | ||
if xx == "04": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
if drb4 != "": | ||
# if 2 copies | ||
drb4_g = drb4.split("+") | ||
if len(drb4_g) == 2: | ||
# homozygous, return one copy | ||
if drb4_g[1] == drb4_g[0]: | ||
return drb4_g[0] | ||
else: | ||
raise DRBXBlenderError("DRB4 het", "hom") | ||
else: | ||
return drb4 | ||
return "" | ||
|
||
# handle 05 | ||
if xx == "05": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
if drb5 != "": | ||
# if 2 copies | ||
drb5_g = drb5.split("+") | ||
if len(drb5_g) == 2: | ||
# homozygous, return one copy | ||
if drb5_g[1] == drb5_g[0]: | ||
return drb5_g[0] | ||
else: | ||
raise DRBXBlenderError("DRB5 het", "hom") | ||
else: | ||
return drb5 | ||
return "" | ||
# handle 33 | ||
if xx == "33": | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
if drb3 != "": | ||
return drb3 | ||
return "" | ||
|
||
# handle 44 | ||
if xx == "44": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
if drb4 != "": | ||
return drb4 | ||
return "" | ||
|
||
# handle 55 | ||
if xx == "55": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
if drb5 != "": | ||
return drb5 | ||
return "" | ||
|
||
# handle 34 | ||
if xx == "34": | ||
if drb5 != "": | ||
raise DRBXBlenderError("DRB5", "none") | ||
retg = [] | ||
|
||
if drb3 != "": | ||
# if 2 copies | ||
drb3_g = drb3.split("+") | ||
if len(drb3_g) == 2: | ||
# homozygous, return one copy | ||
if drb3_g[1] == drb3_g[0]: | ||
retg.append(drb3_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB3 het", "hom") | ||
elif len(drb3_g) == 1: | ||
retg.append(drb3_g[0]) | ||
if drb4 != "": | ||
# if 2 copies | ||
drb4_g = drb4.split("+") | ||
if len(drb4_g) == 2: | ||
# homozygous, return one copy | ||
if drb4_g[1] == drb4_g[0]: | ||
retg.append(drb4_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB4 het", "hom") | ||
elif len(drb4_g) == 1: | ||
retg.append(drb4_g[0]) | ||
|
||
return "+".join(retg) | ||
|
||
# handle 35 | ||
if xx == "35": | ||
if drb4 != "": | ||
raise DRBXBlenderError("DRB4", "none") | ||
retg = [] | ||
|
||
if drb3 != "": | ||
# if 2 copies | ||
drb3_g = drb3.split("+") | ||
if len(drb3_g) == 2: | ||
# homozygous, return one copy | ||
if drb3_g[1] == drb3_g[0]: | ||
retg.append(drb3_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB3 het", "hom") | ||
elif len(drb3_g) == 1: | ||
retg.append(drb3_g[0]) | ||
if drb5 != "": | ||
# if 2 copies | ||
drb5_g = drb5.split("+") | ||
if len(drb5_g) == 2: | ||
# homozygous, return one copy | ||
if drb5_g[1] == drb5_g[0]: | ||
retg.append(drb5_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB5 het", "hom") | ||
elif len(drb5_g) == 1: | ||
retg.append(drb5_g[0]) | ||
|
||
return "+".join(retg) | ||
|
||
# handle 45 | ||
if xx == "45": | ||
if drb3 != "": | ||
raise DRBXBlenderError("DRB3", "none") | ||
retg = [] | ||
|
||
if drb4 != "": | ||
# if 2 copies | ||
drb4_g = drb4.split("+") | ||
if len(drb4_g) == 2: | ||
# homozygous, return one copy | ||
if drb4_g[1] == drb4_g[0]: | ||
retg.append(drb4_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB4 het", "hom") | ||
elif len(drb4_g) == 1: | ||
retg.append(drb4_g[0]) | ||
if drb5 != "": | ||
# if 2 copies | ||
drb5_g = drb5.split("+") | ||
if len(drb5_g) == 2: | ||
# homozygous, return one copy | ||
if drb5_g[1] == drb5_g[0]: | ||
retg.append(drb5_g[0]) | ||
else: | ||
raise DRBXBlenderError("DRB5 het", "hom") | ||
elif len(drb5_g) == 1: | ||
retg.append(drb5_g[0]) | ||
|
||
return "+".join(retg) | ||
|
||
print("blender fail", xx, drb1_fam_1, drb1_fam_2) | ||
return "" | ||
|
||
|
||
def expdrbx(drb1_fam): | ||
if drb1_fam in ["03", "05", "06", "11", "12", "13", "14"]: | ||
return "3" | ||
if drb1_fam in ["04", "07", "09"]: | ||
return "4" | ||
if drb1_fam in ["02", "15", "16"]: | ||
return "5" | ||
return "0" | ||
|
||
|
||
class DRBXBlenderError(Exception): | ||
def __init__(self, found, expected): | ||
self.found = found | ||
self.expected = expected | ||
|
||
def __str__(self): | ||
return f"{self.found} where {self.expected} expected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Feature: DRB1 blends with DRB3, DRB4, DRB5 | ||
|
||
Scenario Outline: DRB1 blends | ||
|
||
Given a subject has <DRB1_SLUG> DRB1 SLUG | ||
And a subject has <DRB3> DRB3 allele | ||
And a subject has <DRB4> DRB4 allele | ||
And a subject has <DRB5> DRB5 allele | ||
When I blend the DRBX alleles with DRB1 allele | ||
Then it should blend as <DRBX_BLEND> | ||
|
||
Examples: All blends with DRB1 | ||
| DRB1_SLUG | DRB3 | DRB4 | DRB5 | DRBX_BLEND | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:01 | DRB4*01:03 | no | DRB3*01:01+DRB4*01:03 | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:01 | DRB4*01:03 | no | DRB3*01:01+DRB4*01:03 | | ||
| HLA-DRB1*03:01+DRB1*04:01 | no | DRB4*01:03 | no | DRB4*01:03 | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:03 | no | no | DRB3*01:03 | | ||
| HLA-DRB1*01:01+DRB1*08:01 | no | no | no | nothing | | ||
| HLA-DRB1*01:01+DRB1*03:01 | no | no | no | nothing | | ||
| HLA-DRB1*01:01+DRB1*04:01 | no | no | no | nothing | | ||
| HLA-DRB1*03:01+DRB1*13:01 | DRB3*01:01 | no | no | DRB3*01:01 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | no | no | DRB5*01:03 | DRB5*01:03 | | ||
|
||
Scenario Outline: DRB1 doesn't blend | ||
|
||
Given a subject has <DRB1_SLUG> DRB1 SLUG | ||
And a subject has <DRB3> DRB3 allele | ||
And a subject has <DRB4> DRB4 allele | ||
And a subject has <DRB5> DRB5 allele | ||
When I blend the DRBX alleles with DRB1 allele, it shouldn't blend | ||
Then <Expected> was expected, but found <Found> | ||
|
||
Examples: Doesn't blend with DRB1 | ||
| DRB1_SLUG | DRB3 | DRB4 | DRB5 | Expected | Found | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:01 | DRB4*01:03 | DRB5*01:05 | none | DRB5 | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:01+DRB3*02:01 | DRB4*01:03 | no | hom | DRB3 het | | ||
| HLA-DRB1*03:01+DRB1*04:01 | DRB3*01:01 | DRB4*01:03+DRB4*01:05 | no | hom | DRB4 het | | ||
| HLA-DRB1*01:01+DRB1*08:01 | DRB3*01:01 | no | no | none | DRB3 | | ||
| HLA-DRB1*01:01+DRB1*08:01 | no | DRB4*01:01 | no | none | DRB4 | | ||
| HLA-DRB1*01:01+DRB1*08:01 | no | no | DRB5*01:01 | none | DRB5 | | ||
| HLA-DRB1*01:01+DRB1*03:01 | DRB3*01:01 | DRB4*01:03 | no | none | DRB4 | | ||
| HLA-DRB1*01:01+DRB1*03:01 | DRB3*01:01 | no | DRB5*01:03 | none | DRB5 | | ||
| HLA-DRB1*01:01+DRB1*04:01 | no | DRB4*01:01+DRB4*01:03 | no | hom | DRB4 het | | ||
| HLA-DRB1*01:01+DRB1*04:01 | DRB3*01:01 | DRB4*01:03 | no | none | DRB3 | | ||
| HLA-DRB1*01:01+DRB1*04:01 | no | DRB4*01:01 | DRB5*01:03 | none | DRB5 | | ||
| HLA-DRB1*03:01+DRB1*13:01 | DRB3*01:01 | DRB4*01:03 | no | none | DRB4 | | ||
| HLA-DRB1*03:01+DRB1*13:01 | DRB3*01:01 | no | DRB5*01:03 | none | DRB5 | | ||
| HLA-DRB1*03:01+DRB1*13:01 | no | DRB4*01:01 | DRB5*01:03 | none | DRB4 | | ||
| HLA-DRB1*04:01+DRB1*09:01 | DRB3*01:01 | no | no | none | DRB3 | | ||
| HLA-DRB1*04:01+DRB1*09:01 | DRB3*01:01 | DRB4*01:03 | no | none | DRB3 | | ||
| HLA-DRB1*04:01+DRB1*09:01 | DRB3*01:01 | no | DRB5*01:03 | none | DRB3 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | no | DRB4*01:01 | DRB5*01:03 | none | DRB4 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | DRB3*01:01 | no | no | none | DRB3 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | DRB3*01:01 | DRB4*01:03 | no | none | DRB3 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | DRB3*01:01 | no | DRB5*01:03 | none | DRB3 | | ||
| HLA-DRB1*15:01+DRB1*16:01 | no | DRB4*01:01 | DRB5*01:03 | none | DRB4 | |
Oops, something went wrong.