Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)