def test_krakenuniq(krakenuniq_db, input_bam): out_report = util.file.mkstempfname('.report') out_reads = util.file.mkstempfname('.reads.gz') cmd = [ krakenuniq_db, input_bam, '--outReports', out_report, '--outReads', out_reads ] parser = metagenomics.parser_krakenuniq(argparse.ArgumentParser()) args = parser.parse_args(cmd) args.func_main(args) with util.file.open_or_gzopen(out_reads, 'r') as inf: assert len(inf.read()) > 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 krakenuniq_db: zaire_found = False tai_found = False for line in report_lines: if 'Zaire ebolavirus' in line[-1] and float(line[0]) > 90: zaire_found = True elif 'Tai Forest' in line[-1]: tai_found = True assert zaire_found assert not tai_found
def test_krakenuniq_on_empty(krakenuniq_db, input_bam): if 'TestMetagenomicsViralMix' not in krakenuniq_db: return input_bam = join(util.file.get_test_input_path(), 'empty.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) with util.file.open_or_gzopen(out_reads, 'r') as inf: assert len(inf.read()) == 0 assert is_gz_file(out_reads) with open(out_report, 'rt') as inf: lines = [ line.strip() for line in inf.readlines() if not line.startswith('#') and not line.startswith('%') ] out_report_contents = [line for line in lines if line] assert len(out_report_contents) == 1 assert out_report_contents[0].split('\t') == [ '100.00', '0', '0', '0', '0', 'NA', '0', 'no rank', 'unclassified' ]
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
def test_krakenuniq(mocker): p = mocker.patch('tools.kraken.KrakenUniq.pipeline') args = [ 'db', 'input.bam', '--outReports', 'output.report', '--outReads', 'output.reads', ] args = metagenomics.parser_krakenuniq(argparse.ArgumentParser()).parse_args(args) args.func_main(args) p.assert_called_with('db', ['input.bam'], num_threads=mock.ANY, filter_threshold=mock.ANY, out_reports=['output.report'], out_reads=['output.reads'])
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) ''' well... this doesn't actually find Zaire ebolavirus!