Exemple #1
0
def test_mouse_class1_alleles_H2_Db():
    # H2-Db
    eq_(parse_allele_name("H2-Db"), AlleleName("H-2", "D", "", "b"))
    eq_(normalize_allele_name("H2-Db"), "H-2-Db")
    eq_(compact_allele_name("H2-Db"), "Db")

    # with hyphen in "H-2"
    eq_(parse_allele_name("H-2-Db"), AlleleName("H-2", "D", "", "b"))
    eq_(normalize_allele_name("H-2-Db"), "H-2-Db")
    eq_(compact_allele_name("H-2-Db"), "Db")
def test_mouse_class2_alleles():
    # H2-IAb
    eq_(parse_allele_name("H2-IAb"), AlleleName("H-2", "IA", "", "b"))
    eq_(normalize_allele_name("H2-IAb"), "H-2-IAb")
    eq_(compact_allele_name("H2-IAb"), "IAb")

    # with hyphen in "H-2"
    eq_(parse_allele_name("H-2-IAb"), AlleleName("H-2", "IA", "", "b"))
    eq_(normalize_allele_name("H-2-IAb"), "H-2-IAb")
    eq_(compact_allele_name("H-2-IAb"), "IAb")
Exemple #3
0
def test_mouse_class1_alleles_H2_Kk():
    # H2-Kk
    eq_(parse_allele_name("H2-Kk"), AlleleName("H-2", "K", "", "k"))
    eq_(normalize_allele_name("H2-Kk"), "H-2-Kk")
    eq_(compact_allele_name("H-2-Kk"), "Kk")

    # with a hyphen in "H-2"
    eq_(parse_allele_name("H-2-Kk"), AlleleName("H-2", "K", "", "k"))
    eq_(normalize_allele_name("H-2-Kk"), "H-2-Kk")
    eq_(compact_allele_name("H-2-Kk"), "Kk")
def test_mouse_class1_alleles_H2_Kk():
    # H2-Kk
    eq_(parse_allele_name("H2-Kk"),
        AlleleName("H-2", "K", "", "k"))
    eq_(normalize_allele_name("H2-Kk"), "H-2-Kk")
    eq_(compact_allele_name("H-2-Kk"), "Kk")

    # with a hyphen in "H-2"
    eq_(parse_allele_name("H-2-Kk"),
        AlleleName("H-2", "K", "", "k"))
    eq_(normalize_allele_name("H-2-Kk"), "H-2-Kk")
    eq_(compact_allele_name("H-2-Kk"), "Kk")
def test_mouse_class1_alleles_H2_Db():
    # H2-Db
    eq_(parse_allele_name("H2-Db"),
        AlleleName("H-2", "D", "", "b"))
    eq_(normalize_allele_name("H2-Db"), "H-2-Db")
    eq_(compact_allele_name("H2-Db"), "Db")

    # with hyphen in "H-2"
    eq_(parse_allele_name("H-2-Db"),
        AlleleName("H-2", "D", "", "b"))
    eq_(normalize_allele_name("H-2-Db"), "H-2-Db")
    eq_(compact_allele_name("H-2-Db"), "Db")
def test_mouse_class2_alleles():
    # H2-IAb
    eq_(parse_allele_name("H2-IAb"),
        AlleleName("H-2", "IA", "", "b"))
    eq_(normalize_allele_name("H2-IAb"), "H-2-IAb")
    eq_(compact_allele_name("H2-IAb"), "IAb")

    # with hyphen in "H-2"
    eq_(parse_allele_name("H-2-IAb"),
        AlleleName("H-2", "IA", "", "b"))
    eq_(normalize_allele_name("H-2-IAb"), "H-2-IAb")
    eq_(compact_allele_name("H-2-IAb"), "IAb")
Exemple #7
0
 def __init__(self, name: str) -> HLAChain:
     """Create an HLAChain instance. 
     :param name: the allele name 
     :type name: str
     :return: an HLAChain instance 
     :rtype: HLAChain
     """
     self._name = name
     name = mhcnames.parse_allele_name(name)
     # extract fields from the name
     self._hla_class = self.get_chain_class(name.gene)
     self._gene = name.gene
     self._allele_group = name.allele_family
     self._protein_group = name.allele_code
Exemple #8
0
    def get_peptides_bound_by_allele(self,allele_name:str)->pd.DataFrame:
        """ returns a subtable contain all info associated with the provided allele_name

        :param allele_name: the allele name written in the standard notation 
        :type allele_name: str
        :raises ValueError: incase the provided allele is not in the database 
        :return: a subtable contain all the experiments associated with the provided allele_name
        :rtype: pd.DataFrame
        """
        s_allele_name=mhcnames.parse_allele_name(allele_name)
        s_allele_name=s_allele_name.gene+'*'+s_allele_name.allele_family+':'+s_allele_name.allele_code
        current_alleles=self.get_all_unique_alleles_in_db()
        if s_allele_name not in current_alleles:
            raise ValueError(f"The provided allele is not currently defined in the database, currently the following is defined: {' ,'.join(current_alleles)}")
        return  self._database.loc[self._database.allele.contains(s_allele_name),]
Exemple #9
0
    def get_frequency_of(self,allele_name:str)->pd.DataFrame:
        """The worker function of the class, Queries AFND for the frequency of the provided allele in different populations

        :param allele_name: the allele name in standard notation, for example, A*01:01 or DRB1*15:01
        :type allele_name: string
        :return: a tuples of two columns, the first contain the country name and the second contains the frequency
        :rtype: pd.DataFrame
        """
        try:
            allele_name=mhcnames.parse_allele_name(allele_name)
        except mhcnames.AlleleParseError as exp: 
            raise ValueError(f'While parsing the provided name: {allele_name} the following error was encountered: {str(exp)}')
        q_name = allele_name.gene+'*'+allele_name.allele_family+':'+allele_name.allele_code
        try: 
            print(f'sending the query to the server ....')
            response=self._http.request('GET',self._base+q_name) 
            print(f'response received')
        except Exception as exp: 
            raise RuntimeError(f'While querying the server the following error was encountered: {str(exp)}')
        # check that the response is valid 
        if response.status==404:
            raise RuntimeError(f'The provided allele list is not defined in the database, server returned 404 ')        
        # get the frequency table from the HTML page 
        html_soup=BeautifulSoup(response.data.decode('utf-8',errors='ignore'),'html.parser')
        html_table=html_soup.body.find_all("table")[3].find_all("tr")[1:]
        ## extract the data from all elements of the table 
        rows=[]
        for row in html_table:
            columns=[]
            for elem in row:
                try:
                    columns.append(elem.get_text())
                except AttributeError:
                    continue
            rows.append(columns)
        ## create the table 
        temp_table=pd.DataFrame(data=rows)
        freq_table=pd.concat([temp_table.iloc[:,1],temp_table.iloc[:,3]],axis=1)
        freq_table.columns=['Country','Frequency']
        return freq_table
Exemple #10
0
def test_H2_Kd_without_seps():
    eq_(parse_allele_name("H2Kd"), AlleleName("H-2", "K", "", "d"))
def test_H2_Kd_without_seps():
    eq_(parse_allele_name("H2Kd"),
        AlleleName("H-2", "K", "", "d"))
Exemple #12
0
def test_SLA_1_0101_no_seps():
    eq_(
        parse_allele_name("SLA-10101"),
        AlleleName("SLA", "1", "01", "01"))
Exemple #13
0
def test_SLA_1_HB01():
    eq_(
        parse_allele_name("SLA-1-HB01"),
        AlleleName("SLA", "1", "HB", "01"))
Exemple #14
0
def test_sheep_class1_allele():
    eq_(parse_allele_name("Ovar-N*50001"), AlleleName("Ovar", "N", "500",
                                                      "01"))
Exemple #15
0
def test_SLA_2_07we01():
    eq_(parse_allele_name("SLA-2*07we01"),
        AlleleName("SLA", "2", "07we", "01"))
Exemple #16
0
def test_dog_class2_allele():
    eq_(parse_allele_name("DLA-DQA1*00101"),
        AlleleName("DLA", "DQA1", "01", "01"))
Exemple #17
0
def test_SLA_2_w09pt22():
    eq_(parse_allele_name("SLA-2*w09pt22"),
        AlleleName("SLA", "2", "w09pt", "22"))
Exemple #18
0
def test_SLA_2_jh01():
    eq_(parse_allele_name("SLA-2*jh01"),
        AlleleName("SLA", "2", "jh", "01"))
Exemple #19
0
def test_sheep_class2_allele():
    eq_(parse_allele_name("Ovar-DRB1*0804"),
        AlleleName("Ovar", "DRB1", "08", "04"))
Exemple #20
0
def test_dog_class2_allele():
    eq_(parse_allele_name("DLA-DQA1*00101"),
        AlleleName("DLA", "DQA1", "01", "01"))