Example #1
0
def test_krakenuniq_krona(krakenuniq_db, krona_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads.gz')

    cmd = [
        krakenuniq_db, input_bam, '--outReport', out_report, '--outReads',
        out_reads
    ]
    parser = metagenomics.parser_krakenuniq(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

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

    if 'TestMetagenomicsSimple' in krakenuniq_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
Example #2
0
def test_kraken_krona(tmpdir, kraken_db, krona_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads.gz')

    cmd = [input_bam, kraken_db, '--outReport', out_report, '--outReads', out_reads]
    parser = metagenomics.parser_kraken(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args([out_reads, krona_db, out_html])
    args.func_main(args)
Example #3
0
def test_kraken_krona(kraken_db, krona_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads.gz')

    cmd = [input_bam, kraken_db, '--outReport', out_report, '--outReads', out_reads]
    parser = metagenomics.parser_kraken(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args([out_reads, krona_db, out_html])
    args.func_main(args)
Example #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
Example #5
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
Example #6
0
def test_kraken2_krona(kraken2_db, krona_db, input_bam):
    out_report = util.file.mkstempfname('.report')
    out_reads = util.file.mkstempfname('.reads.gz')

    cmd = [
        kraken2_db, input_bam, '--outReport', out_report, '--outReads',
        out_reads
    ]
    parser = metagenomics.parser_kraken2(argparse.ArgumentParser())
    args = parser.parse_args(cmd)
    args.func_main(args)

    out_html = util.file.mkstempfname('.krona.html')
    parser = metagenomics.parser_krona(argparse.ArgumentParser())
    args = parser.parse_args(
        ['--inputType', 'kraken2', out_report, krona_db, out_html])
    args.func_main(args)
    ''' well... this doesn't actually find Zaire ebolavirus!
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!