def test_get_summary(monkeypatch, req, tmpdir):
    """Test getting the assembly summary file."""
    cache_dir = tmpdir.mkdir('cache')
    monkeypatch.setattr(core, 'CACHE_DIR', str(cache_dir))
    cache_file = cache_dir.join('refseq_bacteria_assembly_summary.txt')
    req.get(
        'https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt',
        text='test')

    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'),
                           False)
    assert ret.read() == 'test'
    assert not cache_file.check()

    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'),
                           True)
    assert ret.read() == 'test'
    assert cache_file.check()

    req.get(
        'https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt',
        text='never read')
    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'),
                           True)
    assert ret.read() == 'test'
示例#2
0
def test_get_summary(monkeypatch, req, tmpdir):
    """Test getting the assembly summary file."""
    cache_dir = tmpdir.mkdir('cache')
    monkeypatch.setattr(core, 'CACHE_DIR', str(cache_dir))
    cache_file = cache_dir.join('refseq_bacteria_assembly_summary.txt')
    req.get('https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt', text='test')

    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'), False)
    assert ret.read() == 'test'
    assert not cache_file.check()

    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'), True)
    assert ret.read() == 'test'
    assert cache_file.check()

    req.get('https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt', text='never read')
    ret = core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'), True)
    assert ret.read() == 'test'
示例#3
0
def test_get_summary_error_handling(monkeypatch, mocker, req, tmpdir):
    """Test get_summary error handling."""
    cache_dir = tmpdir.join('cache')
    monkeypatch.setattr(core, 'CACHE_DIR', str(cache_dir))
    req.get('https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt', text='test')

    fake_makedirs = mocker.MagicMock(side_effect=OSError(13, "Permission denied"))
    monkeypatch.setattr(os, 'makedirs', fake_makedirs)
    with pytest.raises(OSError):
        core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'), True)
示例#4
0
def test_get_summary_error_handling(monkeypatch, mocker, req, tmpdir):
    """Test get_summary error handling."""
    cache_dir = tmpdir.join('cache')
    monkeypatch.setattr(core, 'CACHE_DIR', str(cache_dir))
    req.get('https://ftp.ncbi.nih.gov/genomes/refseq/bacteria/assembly_summary.txt', text='test')

    fake_makedirs = mocker.MagicMock(side_effect=OSError(13, "Permission denied"))
    monkeypatch.setattr(os, 'makedirs', fake_makedirs)
    with pytest.raises(OSError):
        core.get_summary('refseq', 'bacteria', NgdConfig.get_default('uri'), True)
示例#5
0
    "input the taxon id. It will retrieve all the genomes desceding to the provided taxon; to separate multiple "
)
@click.option(
    "-F",
    "formats",
    help='Which formats to download (default: %(default)s).'
    'A comma-separated list of formats is also possible. For example: "fasta,assembly-report". '
    'Choose from: {choices}'.format(
        choices=NgdConfig.get_choices('file_formats')),
    default='fasta')
@click.option(
    "-o",
    "odir",
    help=
    f"Create output hierarchy in specified folder (default: {NgdConfig.get_default('output')})",
    default=NgdConfig.get_default('output'))
@click.option("-size",
              "size_of_batch",
              help=f"The size of each batch.",
              default=20)
@click.option("-p",
              "parallel",
              help=f"Run N downloads in parallel (default: 10)",
              default=5)
@click.option("-id",
              "id_list",
              help=f" ',' separated assembly ids or a single file  ",
              default='')
@click.option("-C",
              "enable_check",
              help=f"use summary file or use the id input directly",
示例#6
0
文件: ngd.py 项目: manto32bit/evol_tk
@click.command(
    help=
    "It would split the list of assembly ids into batches. The size parameter would produce"
)
@click.option(
    "-n",
    "name",
    help="input the phylum name or other. use ; to separate multiple ")
@click.option(
    "-F",
    "formats",
    help='Which formats to download (default: %(default)s).'
    'A comma-separated list of formats is also possible. For example: "fasta,assembly-report". '
    'Choose from: {choices}'.format(
        choices=NgdConfig.get_choices('file_formats')),
    default=NgdConfig.get_default('file_formats'))
@click.option(
    "-o",
    "odir",
    help=
    f"Create output hierarchy in specified folder (default: {NgdConfig.get_default('output')})",
    default=NgdConfig.get_default('output'))
@click.option("-size",
              "size_of_batch",
              help=f"The size of each batch.",
              default=20)
@click.option("-p",
              "parallel",
              help=f"Run N downloads in parallel (default: 10)",
              default=5)
def cli(name, odir, formats, size_of_batch, parallel):