Пример #1
0
def test_kaiju(mocker):
    p = mocker.patch('tools.kaiju.Kaiju.classify')
    args = [
        'input.bam',
        'db.fmi',
        'tax_db',
        'output.report',
        '--outReads', 'output.reads',
    ]
    args = metagenomics.parser_kaiju(argparse.ArgumentParser()).parse_args(args)
    args.func_main(args)
    p.assert_called_with('db.fmi', 'tax_db', 'input.bam', output_report='output.report', num_threads=mock.ANY, output_reads='output.reads')
Пример #2
0
def test_kaiju(mocker):
    p = mocker.patch('tools.kaiju.Kaiju.classify')
    args = [
        'input.bam',
        'db.fmi',
        'tax_db',
        'output.report',
        '--outReads', 'output.reads',
    ]
    args = metagenomics.parser_kaiju(argparse.ArgumentParser()).parse_args(args)
    args.func_main(args)
    p.assert_called_with('db.fmi', 'tax_db', 'input.bam', output_report='output.report', num_threads=mock.ANY, output_reads='output.reads')
Пример #3
0
def test_kaiju(kaiju_db, krona_db, taxonomy_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads')
    cmd = [
        input_bam, kaiju_db, taxonomy_db, out_report, '--outReads', out_reads
    ]
    parser = metagenomics.parser_kaiju(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    assert os.path.getsize(out_report) > 0
    assert os.path.getsize(out_reads) > 0

    with util.file.open_or_gzopen(out_report) as inf:
        report_lines = [x.strip().split('\t') for x in inf.readlines()]
        report_lines = [x for x in report_lines if x]

    assert is_gz_file(out_reads)
    assert os.path.getsize(out_report) > 0

    if 'TestMetagenomicsSimple' in kaiju_db:
        zaire_found = False
        tai_found = False
        for line in report_lines:
            if len(line) < 2:
                continue
            if 'Zaire ebolavirus' in line[-2] and float(line[0]) > 40:
                zaire_found = True
            elif 'Tai Forest' in line[-2]:
                tai_found = True
        assert zaire_found
        assert not tai_found

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args(
        ['--inputType', 'kaiju', out_report, krona_db, out_html])
    args.func_main(args)

    if 'TestMetagenomicsSimple' in kaiju_db:
        ebola_found = False
        cleaner = lxml.html.clean.Cleaner(remove_unknown_tags=False,
                                          page_structure=False)
        tree = cleaner.clean_html(lxml.html.parse(out_html))
        root_node = tree.xpath('//krona/node')[0]
        for n in root_node.iterdescendants():
            if n.get('name') == 'Zaire ebolavirus':
                if int(n.xpath('magnitude/val')[0].text) > 0:
                    ebola_found = True
        assert ebola_found
Пример #4
0
def test_kaiju(kaiju_db, krona_db, taxonomy_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads')
    cmd = [input_bam, kaiju_db, taxonomy_db, out_report, '--outReads', out_reads]
    parser = metagenomics.parser_kaiju(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    assert os.path.getsize(out_report) > 0
    assert os.path.getsize(out_reads) > 0

    with util.file.open_or_gzopen(out_report) as inf:
        report_lines = [x.strip().split('\t') for x in inf.readlines()]
        report_lines = [x for x in report_lines if x]

    assert is_gz_file(out_reads)
    assert os.path.getsize(out_report) > 0

    if 'TestMetagenomicsSimple' in kaiju_db:
        zaire_found = False
        tai_found = False
        for line in report_lines:
            if len(line) < 2:
                continue
            if 'Zaire ebolavirus' in line[-2] and float(line[0]) > 40:
                zaire_found = True
            elif 'Tai Forest' in line[-2]:
                tai_found = True
        assert zaire_found
        assert not tai_found

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args(['--inputType', 'kaiju', out_report, krona_db, out_html])
    args.func_main(args)

    if 'TestMetagenomicsSimple' in kaiju_db:
      ebola_found = False
      cleaner = lxml.html.clean.Cleaner(remove_unknown_tags=False, page_structure=False)
      tree = cleaner.clean_html(lxml.html.parse(out_html))
      root_node = tree.xpath('//krona/node')[0]
      for n in root_node.iterdescendants():
          if n.get('name') == 'Zaire ebolavirus':
              if int(n.xpath('magnitude/val')[0].text) > 0:
                  ebola_found = True
      assert ebola_found
def test_kaiju(kaiju_db, krona_db, taxonomy_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads')
    cmd = [
        input_bam, kaiju_db, taxonomy_db, out_report, '--outReads', out_reads
    ]
    parser = metagenomics.parser_kaiju(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    assert os.path.getsize(out_report) > 0
    assert os.path.getsize(out_reads) > 0

    with util.file.open_or_gzopen(out_report) as inf:
        report_lines = [x.strip().split('\t') for x in inf.readlines()]
        report_lines = [x for x in report_lines if x]

    assert is_gz_file(out_reads)
    assert os.path.getsize(out_report) > 0

    if 'TestMetagenomicsSimple' in kaiju_db:
        zaire_found = False
        tai_found = False
        for line in report_lines:
            if len(line) < 2:
                continue
            if 'Zaire ebolavirus' in line[-2] and float(line[0]) > 40:
                zaire_found = True
            elif 'Tai Forest' in line[-2]:
                tai_found = True
        assert zaire_found
        assert not tai_found

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args(
        ['--inputType', 'kaiju', out_report, krona_db, out_html])
    args.func_main(args)
    ''' well... this doesn't actually find Zaire ebolavirus!