示例#1
0
def test_save():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        isolate = 'tests'
        amr_obj.logger = logging.getLogger(__name__)
        summary_drugs = pandas.DataFrame(
            {
                "Isolate": isolate,
                'ESBL': 'blaCTX-M-15',
                "Beta-lactamase (not ESBL or carbapenemase)": 'blaSHV-11'
            },
            index=[0])
        summary_partial = pandas.DataFrame(
            {
                "Isolate": isolate,
                'ESBL': 'blaCTX-M-15'
            }, index=[0])
        virulence = pandas.DataFrame({
            "Isolate": isolate,
            'METAL': 'qnrB1'
        },
                                     index=[0])
        assert amr_obj.save_files('', summary_drugs, summary_partial,
                                  virulence)
示例#2
0
def test_get_per_isolate():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        reftab = reftab.fillna('-')

        df = pandas.read_csv('tests/amrfinder.out', sep='\t')
        isolate = 'tests'
        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.get_per_isolate(
            reftab=reftab, df=df, isolate=isolate) == ({
                "Isolate":
                isolate,
                "Beta-lactamase (not ESBL or carbapenemase)":
                'blaSHV-11',
                'ESBL':
                'blaCTX-M-15'
            }, {
                "Isolate": isolate,
                'ESBL': 'blaCTX-M-15'
            }, {
                "Isolate": isolate,
                'Metal': 'qnrB1'
            })
示例#3
0
def run_pipeline(args):
    P = SetupAMR(args)
    input_data = P.setup()
    A = RunFinder(input_data)
    amr_data = A.run()
    C = Collate(amr_data)
    collated_data = C.run()
示例#4
0
def test_extract_gene_name_1():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        protein = 'WP_004176269.1'
        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.extract_gene_name(protein, reftab) == 'blaSHV-11'
示例#5
0
def test_extract_gene_name_2():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        reftab = reftab.fillna('-')
        protein = 'WP_063839881.1'
        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.extract_gene_name(protein, reftab) == "aac(2')-IIa"
示例#6
0
def test_save_merge_both_empty():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        isolate = 'tests'
        amr_obj.logger = logging.getLogger(__name__)
        summary_drugs = pandas.DataFrame({"Isolate": isolate}, index=[0])
        summary_partial = pandas.DataFrame({"Isolate": isolate}, index=[0])
        virulence = pandas.DataFrame()
        assert not amr_obj._merge(summary_drugs, summary_partial).empty
示例#7
0
def test_get_cols_empty():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        isolate = 'tests'
        amr_obj.logger = logging.getLogger(__name__)
        summary_drugs = pandas.DataFrame()
        # summary_partial = pandas.DataFrame({"Isolate":isolate,'ESBL':'blaCTX-M-15'}, index = [0])
        # virulence = pandas.DataFrame({"Isolate":isolate,'METAL':'qnrB1'}, index = [0])
        assert amr_obj._get_cols(df=summary_drugs) == []
示例#8
0
def test_commbine_all_empty():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        isolate = 'tests'
        amr_obj.logger = logging.getLogger(__name__)
        summary_drugs = pandas.DataFrame()
        summary_partial = pandas.DataFrame()
        virulence = pandas.DataFrame()
        assert amr_obj._combine_dfs(summary_drugs, summary_partial,
                                    virulence).empty
示例#9
0
def test_get_drugclass_allele_1():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        df = pandas.read_csv('tests/amrfinder.out', sep='\t')
        for i in df.iterrows():
            if i[1]['Gene symbol'] == 'blaSHV-11':
                row = i
        colname = 'allele'
        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.get_drugclass(
            reftab, row,
            colname) == "Beta-lactamase (not ESBL or carbapenemase)"
示例#10
0
def test_setup_dict():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        reftab = reftab.fillna('-')
        drugclass_dict = {}
        df = pandas.read_csv('tests/amrfinder.out', sep='\t')
        for i in df.iterrows():
            if i[1]['Gene symbol'] == 'blaSHV-11':
                row = i
        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.setup_dict(drugclass_dict, reftab, row) == {
            "Beta-lactamase (not ESBL or carbapenemase)": ['blaSHV-11']
        }
示例#11
0
def test_collate():
    """
    assert True when non-empty string is given
    """
    with patch.object(Collate, "__init__", lambda x: None):
        args = Colls("assembly", 'tests/contigs.fa', '')
        amr_obj = Collate()
        reftab = pandas.read_csv(REFGENES)
        reftab = reftab.fillna('-')
        isolate = 'tests'
        drugs = pandas.DataFrame(
            {
                "Isolate": isolate,
                'ESBL': 'blaCTX-M-15',
                "Beta-lactamase (not ESBL or carbapenemase)": 'blaSHV-11'
            },
            index=[0])
        partial = pandas.DataFrame({
            "Isolate": isolate,
            'ESBL': 'blaCTX-M-15'
        },
                                   index=[0])
        virulence = pandas.DataFrame({
            "Isolate": isolate,
            'Metal': 'qnrB1'
        },
                                     index=[0])
        # print(drugs)

        amr_obj.logger = logging.getLogger(__name__)
        assert amr_obj.collate(isolate)[0].equals(drugs)
        assert amr_obj.collate(isolate)[1].equals(partial)
        assert amr_obj.collate(isolate)[2].equals(virulence)