示例#1
0
 def test_from_json(self):
     json_str = '{"hgvs_text": "NM_005228.3:c.2240_2257del18", "hgvs_n": ["NM_005228.3:n.2486_2503delTAAGAGAAGCAACATCTC"], "gene_name": "EGFR", "transcripts": ["NM_005228.3"], "hgvs_g": ["NC_000007.14:g.55174777_55174794delTAAGAGAAGCAACATCTC"], "hgvs_c": ["NM_005228.3:c.2240_2257del18"]}'
     lex = VariantLVG.from_json(json_str)
     assert lex.hgvs_text == 'NM_005228.3:c.2240_2257del18'
     assert lex.gene_name == 'EGFR'
     assert 'NC_000007.14:g.55174777_55174794delTAAGAGAAGCAACATCTC' in lex.hgvs_g
     assert 'NM_005228.3:n.2486_2503delTAAGAGAAGCAACATCTC' in lex.hgvs_n
示例#2
0
    def test_del_numeric_or_chars(self):
        hgvs_text = 'NM_005228.3:c.2240_2257del18'
        lex = VariantLVG(hgvs_text)

        expected_c = [
            "NM_005228.3:c.2240_2257del",
        ]
        expected_g = 'NC_000007.14:g.55174777_55174794del'  # same: 'NC_000007.14:g.55174777_55174794delTAAGAGAAGCAACATCTC'
        expected_p = 'NP_005219.2:p.(Leu747_Pro753delinsSer)'
        expected_n = 'NM_005228.3:n.2486_2503del'  # same: 'NM_005228.3:n.2486_2503delTAAGAGAAGCAACATCTC'

        for c_hgvs_text in expected_c:
            assert c_hgvs_text in lex.hgvs_c

        assert expected_g in lex.hgvs_g
        assert expected_p in lex.hgvs_p
        assert expected_n in lex.hgvs_n
示例#3
0
    def query(self, hgvs_text, skip_cache=False, force_granular=False):
        if not skip_cache:
            result = self.retrieve(hgvs_text, version=self.VERSION)
            if result:
                if force_granular:
                    self.store_granular(result)
                return result

        lexobj = VariantLVG(hgvs_text, seqvar_max_len=SEQVAR_MAX_LEN)
        if lexobj:
            self.store(hgvs_text, lexobj)
            if force_granular or self.granular:
                self.store_granular(lexobj)

            return lexobj
        else:
            raise Text2GeneError(
                'VariantLVG object could not be created from input hgvs_text %s'
                % hgvs_text)
示例#4
0
    def retrieve(self, hgvs_text, version=0):
        """ If cache contains a value for hgvs_text, retrieve it. Otherwise, return None.

        (Overrides default retrieve)

        If requested version number is GREATER THAN OR EQUAL TO version number of existing data, older version will be
        destroyed so that newer version can be created in its place.

        Thus, supplying version=0 allows returns from cache from *any* version of data that has ever been stored.

        :param hgvs_text: (str)
        :param version: (int) only return results from cache with greater than or equal version number [default: 0]
        :return: LVG object or None
        """
        row = self.get_row(hgvs_text)
        if row:
            if row['version'] >= version:
                return VariantLVG.from_json(
                    row['cache_value'])  #.decode('string_escape'))
            else:
                log.debug('Expiring obsolete entry at cache_key location %s.',
                          self.get_cache_key(hgvs_text))
                self.delete(hgvs_text)
        return None
示例#5
0
 def test_to_json(self):
     lex = VariantLVG('NM_000020.2(ACVRL1):c.1031G>A')
     json_result = lex.to_json()
     assert 'NM_000020.2:c.1031G>A' in json_result
     assert 'NM_001077401.1' in json_result
     assert 'ACVRL1' in json_result
示例#6
0
 def test_seqvar_max_len_255(self):
     lex = VariantLVG(SEQVAR_MAX_LEN_SAMPLE, seqvar_max_len=255)
     for seqvar in lex.seqvars:
         assert len('%s' % seqvar) <= 255
示例#7
0
 def test_gene_name(self):
     hgvs_text = 'NM_000548.3:c.826_827del'
     lex = VariantLVG(hgvs_text)
     assert lex.gene_name == 'TSC2'
示例#8
0
    def test_bad_hgvs_text_raises_CriticalHgvsError(self):
        bad_hgvs_text = 'NM_004628.4:c.621_622ins83'

        with self.assertRaises(CriticalHgvsError):
            VariantLVG(bad_hgvs_text)
示例#9
0
        for seqvar in lex.seqvars:
            assert len('%s' % seqvar) <= 100

    def test_seqvar_max_len_255(self):
        lex = VariantLVG(SEQVAR_MAX_LEN_SAMPLE, seqvar_max_len=255)
        for seqvar in lex.seqvars:
            assert len('%s' % seqvar) <= 255

    def test_to_json(self):
        lex = VariantLVG('NM_000020.2(ACVRL1):c.1031G>A')
        json_result = lex.to_json()
        assert 'NM_000020.2:c.1031G>A' in json_result
        assert 'NM_001077401.1' in json_result
        assert 'ACVRL1' in json_result

    def test_from_json(self):
        json_str = '{"hgvs_text": "NM_005228.3:c.2240_2257del18", "hgvs_n": ["NM_005228.3:n.2486_2503delTAAGAGAAGCAACATCTC"], "gene_name": "EGFR", "transcripts": ["NM_005228.3"], "hgvs_g": ["NC_000007.14:g.55174777_55174794delTAAGAGAAGCAACATCTC"], "hgvs_c": ["NM_005228.3:c.2240_2257del18"]}'
        lex = VariantLVG.from_json(json_str)
        assert lex.hgvs_text == 'NM_005228.3:c.2240_2257del18'
        assert lex.gene_name == 'EGFR'
        assert 'NC_000007.14:g.55174777_55174794delTAAGAGAAGCAACATCTC' in lex.hgvs_g
        assert 'NM_005228.3:n.2486_2503delTAAGAGAAGCAACATCTC' in lex.hgvs_n


lex = VariantLVG("NM_005228.3:c.2240_2257del18")

json_str = lex.to_json()
print(json_str)

lex = VariantLVG.from_json(json_str)