def test_from_kwargs():
    """Test NgdConfig initialises correctly from kwargs."""
    config = NgdConfig.from_kwargs(parallel=2)
    assert config.parallel == 2

    with pytest.raises(ValueError):
        NgdConfig.from_kwargs(garbage="wow")
def test_from_kwargs():
    """Test NgdConfig initialises correctly from kwargs."""
    config = NgdConfig.from_kwargs(parallel=2)
    assert config.parallel == 2

    with pytest.raises(ValueError):
        NgdConfig.from_kwargs(garbage="wow")
def test_get_choices():
    """Test NgdConfig.get_choices works."""
    assert NgdConfig.get_choices('refseq_categories') == ['all', 'reference', 'representative', 'na']

    with pytest.raises(KeyError):
        NgdConfig.get_choices('garbage')

    with pytest.raises(ValueError):
        NgdConfig.get_choices('uri')
def test_get_choices():
    """Test NgdConfig.get_choices works."""
    assert NgdConfig.get_choices('refseq_category') == ['all', 'reference', 'representative']

    with pytest.raises(KeyError):
        NgdConfig.get_choices('garbage')

    with pytest.raises(ValueError):
        NgdConfig.get_choices('uri')
def test_assembly_accessions():
    """Test NgdConfig.assembly_accessions getters/setters."""
    config = NgdConfig()

    assert config.assembly_accessions == []

    config.assembly_accessions = "GCF_000203835.1"
    assert config.assembly_accessions == ['GCF_000203835.1']

    config.assembly_accessions = "GCF_000203835.1,GCF_000444875.1"
    assert config.assembly_accessions == ['GCF_000203835.1', 'GCF_000444875.1']
def test_assembly_accessions():
    """Test NgdConfig.assembly_accessions getters/setters."""
    config = NgdConfig()

    assert config.assembly_accessions == []

    config.assembly_accessions = "GCF_000203835.1"
    assert config.assembly_accessions == ['GCF_000203835.1']

    config.assembly_accessions = "GCF_000203835.1,GCF_000444875.1"
    assert config.assembly_accessions == ['GCF_000203835.1', 'GCF_000444875.1']
def test_file_format():
    """Test NgdConfig.file_format getters/setters."""
    config = NgdConfig()

    assert config.file_format == ['genbank']

    config.file_format = ['genbank', 'fasta']
    assert config.file_format == ['genbank', 'fasta']

    config.file_format = "all"
    assert config.file_format == list(NgdConfig._FORMATS)

    with pytest.raises(ValueError):
        config.file_format = "garbage"
def test_group():
    """Test NgdConfig.group getters/setters."""
    config = NgdConfig()

    assert config.group == SUPPORTED_TAXONOMIC_GROUPS

    config.group = ['bacteria', 'fungi']
    assert config.group == ['bacteria', 'fungi']

    config.group = "all"
    assert config.group == SUPPORTED_TAXONOMIC_GROUPS

    with pytest.raises(ValueError):
        config.group = "garbage"
def test_file_formats():
    """Test NgdConfig.file_formats getters/setters."""
    config = NgdConfig()

    assert config.file_formats == ['genbank']

    config.file_formats = ['genbank', 'fasta']
    assert config.file_formats == ['genbank', 'fasta']

    config.file_formats = "all"
    assert config.file_formats == list(NgdConfig._FORMATS)

    with pytest.raises(ValueError):
        config.file_formats = "garbage"
def test_group():
    """Test NgdConfig.group getters/setters."""
    config = NgdConfig()

    assert config.group == SUPPORTED_TAXONOMIC_GROUPS

    config.group = ['bacteria', 'fungi']
    assert config.group == ['bacteria', 'fungi']

    config.group = "all"
    assert config.group == SUPPORTED_TAXONOMIC_GROUPS

    with pytest.raises(ValueError):
        config.group = "garbage"
Beispiel #11
0
def NCBI_get_info_GenbankID(data_folder,
                            acc_ID,
                            debug,
                            assembly_level_given='complete'):

    section_given = get_section(acc_ID, debug)

    if debug:
        debug_message("-----------------------------------------")
        debug_message("NCBI_get_info_GenbankID function call", color="yellow")

    ## import module and class
    import ncbi_genome_download
    from ncbi_genome_download.config import NgdConfig
    tries = ['bacteria', 'archaea']
    for entry_tried in tries:
        if debug:
            debug_message("Trying with: " + entry_tried, color="yellow")

        ngd_config = NgdConfig.from_kwargs(section=section_given,
                                           file_formats='genbank',
                                           assembly_accessions=acc_ID,
                                           output=data_folder,
                                           dry_run=True,
                                           groups=entry_tried)
        info = ncbi_genome_download.core.select_candidates(ngd_config)
        if info:
            if debug:
                debug_message("It worked!", color="yellow")
            return (entry_tried)

    raise "**** ERROR: Something happen while connecting to NCBI... ***"
    exit()
    return (False)
Beispiel #12
0
def NCBI_get_info(section_given,
                  data_folder,
                  tax_ID_list,
                  debug,
                  assembly_level_given='complete',
                  group_given='bacteria'):
    '''This function uses ncbi_genome_download to 
    create a dry run and return information of each entry provided
    '''
    ## import module and class
    import ncbi_genome_download
    from ncbi_genome_download.config import NgdConfig

    try:
        ngd_config = NgdConfig.from_kwargs(
            section=section_given,
            file_formats='genbank',
            taxids=tax_ID_list,
            output=data_folder,
            dry_run=True,
            assembly_levels=assembly_level_given,
            groups=group_given)
        info = ncbi_genome_download.core.select_candidates(ngd_config)

    except:
        raise "**** ERROR: Something happen while connecting to NCBI... ***"
        exit()
        return (False)

    ####
    if (len(info)) < 1:
        print(
            colored(
                "No entries matched your filter. Please check the input options provided",
                'yellow'))
        exit()

    ## fill dictionary to simplify
    dict_entries = {}
    for entry, _ in info:
        strain_name = ncbi_genome_download.core.get_strain(entry)
        ## debug messagess
        if debug:
            debug_message("", 'yellow')
            print(entry)
            string = entry['assembly_accession'] + '\t' + entry[
                'organism_name'] + '\t' + strain_name
            debug_message(string, 'yellow')
            debug_message(
                ".....................................................................\n",
                'yellow')

        ## fill dictionary
        dict_entries[entry['assembly_accession']] = (entry['organism_name'],
                                                     strain_name)

    ## return
    return (dict_entries)
def test_is_compatible_assembly_level():
    """Test NgdConfig.is_compatible_assembly_level."""
    config = NgdConfig()
    ncbi_string = "Complete Genome"

    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_levels = "complete"
    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_levels = "chromosome,complete"
    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_levels = "chromosome"
    assert not config.is_compatible_assembly_level(ncbi_string)
Beispiel #14
0
def test_is_compatible_assembly_accession():
    """Test NgdConfig.is_compatible_assembly_accession."""
    config = NgdConfig()

    assert config.is_compatible_assembly_accession("GCF_000444875.1")

    config.assembly_accessions = "GCF_000203835.1,GCF_000444875.1"
    assert config.is_compatible_assembly_accession("GCF_000444875.1")

    config.assembly_accessions = "GCF_000203835.1"
    assert not config.is_compatible_assembly_accession("GCF_000444875.1")
def test_is_compatible_assembly_level():
    """Test NgdConfig.is_compatible_assembly_level."""
    config = NgdConfig()
    ncbi_string = "Complete Genome"

    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_level = "complete"
    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_level = "chromosome,complete"
    assert config.is_compatible_assembly_level(ncbi_string)

    config.assembly_level = "chromosome"
    assert not config.is_compatible_assembly_level(ncbi_string)
def test_is_compatible_assembly_accession():
    """Test NgdConfig.is_compatible_assembly_accession."""
    config = NgdConfig()

    assert config.is_compatible_assembly_accession("GCF_000444875.1")

    config.assembly_accessions = "GCF_000203835.1,GCF_000444875.1"
    assert config.is_compatible_assembly_accession("GCF_000444875.1")

    config.assembly_accessions = "GCF_000203835.1"
    assert not config.is_compatible_assembly_accession("GCF_000444875.1")
def test_groups():
    """Test NgdConfig.groups getters/setters."""
    config = NgdConfig()

    assert config.groups == SUPPORTED_TAXONOMIC_GROUPS

    config.groups = ['bacteria', 'fungi']
    assert config.groups == ['bacteria', 'fungi']

    config.groups = "all"
    assert config.groups == SUPPORTED_TAXONOMIC_GROUPS

    with pytest.raises(ValueError):
        config.groups = "garbage"

    # No metagenomes in refseq
    with pytest.raises(ValueError):
        config.section = "refseq"
        config.groups = "metagenomes"

    # genbank has metagenomes
    config.section = "genbank"
    config.groups = "metagenomes"
def test_init():
    """Test NgdConfig initialises with the correct default values."""
    config = NgdConfig()

    for key in NgdConfig._DEFAULTS:
        expected = NgdConfig._DEFAULTS[key]
        if key in NgdConfig._LIST_TYPES:
            if expected:
                if expected[0] == 'all':
                    expected = expected[1:]
                else:
                    expected = expected[:1]
            if 'all' in expected:
                expected = expected[::].remove('all')
        elif isinstance(expected, list):
            expected = expected[0]

        assert getattr(config, key) == expected
def test_assembly_levels():
    """Test NgdConfig.assembly_levels getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.assembly_levels = 'garbage'
def test_section():
    """Test NgdConfig.section getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.section = 'garbage'
def test_refseq_category():
    """Test NgdConfig.refseq_category getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.refseq_category = 'garbage'
def test_from_namespace():
    """Test NgdConfig initialises correctly from a Namespace object."""
    args = Namespace(parallel=2)
    config = NgdConfig.from_namespace(args)
    assert config.parallel == 2
def test_from_namespace():
    """Test NgdConfig initialises correctly from a Namespace object."""
    args = Namespace(parallel=2)
    config = NgdConfig.from_namespace(args)
    assert config.parallel == 2
def test_type_materials():
    """Test NgdConfig.type_materials setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.type_materials = "invalid"
def test_refseq_categories():
    """Test NgdConfig.refseq_categories getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.refseq_categories = 'garbage'
def test_section():
    """Test NgdConfig.section getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.section = 'garbage'
def test_assembly_level():
    """Test NgdConfig.assembly_level getters/setters."""
    config = NgdConfig()

    with pytest.raises(ValueError):
        config.assembly_level = 'garbage'