Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion dpb1/tce.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,37 @@
#
import requests
import json
import pandas as pd

class TCE_map(object):

def __init__(self,
path='data/tce_assignments.txt', ard=None):
self.path = path
self.tce_assignments = self._get_tce_assignments()
print(self.tce_assignments)
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