Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dpb1/genotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class Genotype(object):
:param name: A list of two Haplotype objects or a genotype name (str)
"""

def __init__(self, haplotypes):
def __init__(self, haplotypes, index : int = None, prob : float = None):
self.index = index
self.prob = prob
self.SLUGs = None
if isinstance(haplotypes, str):
self.name = haplotypes
Expand Down
20 changes: 19 additions & 1 deletion dpb1/tce.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
import requests
import json
import pandas as pd

class TCE_map(object):

Expand All @@ -29,8 +30,25 @@ def __init__(self,
self.ard = ard

def _get_tce_assignments(self):
"""
Obtains TCE assignments from a hard-coded from IMGT.
:return: Dictionary of alleles to TCE groups (3, 2, 1, 0).
:rtype: Dict[str, str]
"""
with open(self.path, 'r') as f:
return json.loads(f.readline())
tce_map = json.loads(f.readline())

allele_header = 'Allele'
tce_header = 'V2_Assignment'
url = 'https://raw.githubusercontent.com/ANHIG/IMGTHLA/Latest/tce/dpb_tce.csv'
tce_df = pd.read_csv(url, comment='#')
tce_df.replace({'\$' : '', 'a' : ''}, regex=True, inplace=True)
tce_df = tce_df[[allele_header, tce_header]]
tce_df = tce_df[~tce_df[tce_header].isnull()]
tce_df.set_index(allele_header, inplace=True)
tce_map_updated = tce_df.to_dict()[tce_header]
tce_map.update(tce_map_updated)
return tce_map

def assign_tce(self, dpb1_allele):
if dpb1_allele not in self.tce_assignments:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ flask-restplus==0.13.0
behave==1.2.6
PyHamcrest==1.9.0
allure-behave==2.8.5
itsdangerous==2.0.1
matplotlib==3.1.3
mpmath==1.1.0
numpy==1.18.1
pandas==1.0.1
pandas>=1.1.4
requests==2.22.0
seaborn==0.10.0
toolz==0.11.1
Expand Down
25 changes: 19 additions & 6 deletions tests/features/algorithm/call_rest_service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,15 @@ Feature: Call REST Service
"dpb1_genotypes": [
{
"genotype": "DPB1*04:01+DPB1*04:01",
"tce_groups": "3+3",
"probability": 1
"tce_groups": "3+3"
},
{
"genotype": "DPB1*04:01+DPB1*677:01",
"tce_groups": "3+3"
},
{
"genotype": "DPB1*677:01+DPB1*677:01",
"tce_groups": "3+3"
}
]
}
Expand Down Expand Up @@ -813,13 +820,19 @@ Feature: Call REST Service
"dpb1_genotypes": [
{
"genotype": "DPB1*03:01+DPB1*04:01",
"tce_groups": "2+3",
"probability": 0.5035143163576772
"tce_groups": "2+3"
},
{
"genotype": "DPB1*03:01+DPB1*677:01",
"tce_groups": "2+3"
},
{
"genotype": "DPB1*04:01+DPB1*14:01",
"tce_groups": "2+3",
"probability": 0.4964856836423228
"tce_groups": "2+3"
},
{
"genotype": "DPB1*14:01+DPB1*677:01",
"tce_groups": "2+3"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/steps/dpb1_perm_freq_generation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from behave import *
from hamcrest import assert_that, is_
from validation.dpb1_validator.predicted import Predicted, PredictedPair
# from validation.dpb1_validator.predicted import Predicted, PredictedPair
import pandas as pd
from sigfig import round
import json
Expand Down
2 changes: 1 addition & 1 deletion tests/steps/match_tce_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dpb1.match import Matches, MatchGrade
from dpb1.dpb1 import DPB1_SLUG
from dpb1.tce import TCE_SLUG
from validation.dpb1_validator.observed import ObservedPair
# from validation.dpb1_validator.observed import ObservedPair

@given('these TCE group pairs and expected match categories')
def step_impl(context):
Expand Down