Example #1
0
def test_genesyn_calc_ratio3c():
    # syn = nonsyn = 0
    gs = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    assert numpy.isnan(gs.calc_ratio())
Example #2
0
def test_genesyn_calc_ratio2():
    # syn = nonsyn = 0, haplotypes=True
    gs = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    assert gs.calc_ratio(haplotypes=True) == 0.0
Example #3
0
def test_genesyn_calc_ratio4c():
    # nonsyn = 0, syn > 0
    # flag_value=True
    gs = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    assert gs.calc_ratio_flag() == -3
Example #4
0
def test_genesyn_calc_ratio4b():
    # nonsyn = 0, syn > 0
    # flag_value=True
    gs = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    gs.add_snp(1, 'A', SNPType.syn)
    assert gs.calc_ratio_flag() == -2
Example #5
0
def test_genesyn_add1():
    # checks if the conserved gene_id and taxon_id is from the first instance
    gs1 = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6
    )
    gs2 = GeneSNP(
        exp_syn=4,
        exp_nonsyn=6,
        coverage=4
    )
    gs1.add(gs2)
    assert (gs1.gene_id, gs1.taxon_id) == ('A', 1)
Example #6
0
def test_genesyn_calc_ratio1():
    # syn and nonsyn > 0
    gs = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    gs.add_snp(1, 'A', SNPType.syn)
    gs.add_snp(1, 'A', SNPType.syn)
    gs.add_snp(1, 'A', SNPType.nonsyn)
    gs.add_snp(1, 'A', SNPType.nonsyn)
    gs.add_snp(1, 'A', SNPType.nonsyn)
    assert gs.calc_ratio() == 1.0
Example #7
0
def test_snps_gene_id1():
    gene_syn = GeneSNP(gene_id='K01201')
    gene_list = ['K01201', 'K02201', 'K01251']

    assert filter_genesyn_by_gene_id(
        gene_syn,
        gene_list,
        id_func=lambda x: x.gene_id
    )
Example #8
0
def test_snps_taxon2_rev(ncbi_taxonomy):
    # will find it
    filter_list = [
        taxon.taxon_id
        for taxon in ncbi_taxonomy
        if 'clostridium' in taxon.s_name
    ]
    taxon_id = ncbi_taxonomy.find_by_name('methanobrevibacter')[0]
    gene_syn = GeneSNP(taxon_id=taxon_id)

    assert filter_genesyn_by_taxon_id(
        gene_syn,
        ncbi_taxonomy,
        filter_list=filter_list,
        exclude=True
    )
Example #9
0
def test_snps_taxon1(ncbi_taxonomy):
    # will find it
    filter_list = [
        taxon.taxon_id
        for taxon in ncbi_taxonomy
        if 'methanobrevibacter' in taxon.s_name.lower()
    ]
    taxon_id = ncbi_taxonomy.find_by_name('methanobrevibacter')[0]
    gene_syn = GeneSNP(taxon_id=taxon_id)


    assert filter_genesyn_by_taxon_id(
        gene_syn,
        ncbi_taxonomy,
        filter_list=filter_list,
        exclude=False
    )
Example #10
0
def test_snps_taxon3(ncbi_taxonomy):
    # will find it
    filter_list = [
        taxon.taxon_id
        for taxon in ncbi_taxonomy
        if 'clostridium' in taxon.s_name
    ]
    taxon_id = ncbi_taxonomy.find_by_name('methanobrevibacter')[0]
    gene_syn = GeneSNP(taxon_id=taxon_id)

    assert not filter_genesyn_by_taxon_id(
        gene_syn,
        ncbi_taxonomy,
        filter_list=filter_list,
        exclude=False,
        func=mgkit.taxon.is_ancestor
    )
Example #11
0
def test_snps_gene_coverage_exc():
    gene_syn = GeneSNP(gene_id='K01201')
    min_cov = None
    with pytest.raises(FilterFails):
        filter_genesyn_by_coverage(gene_syn, min_cov=min_cov)
Example #12
0
def test_snps_gene_coverage2():
    gene_syn = GeneSNP(gene_id='K01201', coverage=3)
    min_cov = 4

    assert not filter_genesyn_by_coverage(gene_syn, min_cov=min_cov)
Example #13
0
def test_snps_gene_id_exc():
    gene_syn = GeneSNP(gene_id='K01201')
    gene_list = None
    with pytest.raises(FilterFails):
        filter_genesyn_by_gene_id(gene_syn, gene_ids=gene_list)
Example #14
0
def test_snps_taxon4_exc2():
    gene_syn = GeneSNP()
    with pytest.raises(FilterFails):
        filter_genesyn_by_taxon_id(
            gene_syn, filter_list=None
        )
Example #15
0
def test_genesyn_add2():
    # checks if the values (syn, nonsyn, exp_syn, exp_nonsyn) are added
    gs1 = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6
    )
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.nonsyn)
    gs2 = GeneSNP(
        exp_syn=3,
        exp_nonsyn=5,
        coverage=4
    )
    gs2.add_snp(1, 'A', SNPType.syn)
    gs2.add_snp(1, 'A', SNPType.nonsyn)
    gs2.add_snp(1, 'A', SNPType.nonsyn)

    gs1.add(gs2)
    assert (gs1.exp_syn, gs1.exp_nonsyn, gs1.syn, gs1.nonsyn) == (7, 11, 4, 3)
Example #16
0
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6,
    )
    assert gs.calc_ratio_flag() == -3


SNP_DATA = {
    'sample1': {
        'gene1': GeneSNP(
            gene_id='gene1',
            taxon_id=839,  # prevotella ruminicola
            exp_syn=6,
            exp_nonsyn=4,
            snps=[
                (1, 'A', SNPType.syn),
                (1, 'A', SNPType.syn),
                (1, 'A', SNPType.syn),
                (1, 'A', SNPType.nonsyn),
                (1, 'A', SNPType.nonsyn),
            ]
        ),  # pN/pS = 1.0
        'gene2': GeneSNP(
            gene_id='gene2',
            taxon_id=838,  # prevotella genus
            exp_syn=3,
            exp_nonsyn=4,
            snps=[
                (1, 'A', SNPType.syn),
                (1, 'A', SNPType.syn),
                (1, 'A', SNPType.syn),
Example #17
0
def test_genesyn_add3():
    # checks if the values if coverage is correctly added
    # coverage in gs2 is not None, in gs1 is None
    gs1 = GeneSNP(
        gene_id='A',
        taxon_id=1,
        exp_syn=4,
        exp_nonsyn=6
    )
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.syn)
    gs1.add_snp(1, 'A', SNPType.nonsyn)
    gs2 = GeneSNP(
        exp_syn=3,
        exp_nonsyn=5,
        coverage=5
    )
    gs2.add_snp(1, 'A', SNPType.syn)
    gs2.add_snp(1, 'A', SNPType.nonsyn)
    gs2.add_snp(1, 'A', SNPType.nonsyn)

    gs1.add(gs2)
    assert gs1.coverage == 5
Example #18
0
def test_snps_taxon4_exc1():
    gene_syn = GeneSNP()
    with pytest.raises(FilterFails):
        filter_genesyn_by_taxon_id(
            gene_syn, filter_list=range(10), taxonomy=None, func=filter
        )