Download genbank files from NCBI using Biopython Entrez efetch.

    Args:
        list_of_NC_accessions (list): a list of strings, e.g ['NC_015758', 'NC_002695']
        email (string):  NCBI wants your email
        folder (string): Where the gb files download to, generally './genomes/'

def fetch_gbwithparts(list_of_NC_accessions, email, folder):

    '''Download genbank files from NCBI using Biopython Entrez efetch.

    Args:
        list_of_NC_accessions (list): a list of strings, e.g ['NC_015758', 'NC_002695']
        email (string):  NCBI wants your email
        folder (string): Where the gb files download to, generally './genomes/'
    '''

    from Bio import Entrez
    from time import sleep

    print 'downloading genomes... please wait'

    for item in list_of_NC_accessions:
        Entrez.email = email
        handle = Entrez.efetch(db="nuccore",
                               id=item,
                               retmode='full',
                               rettype='gbwithparts')
        data = handle.read()

        if not os.path.exists(folder):
            os.makedirs(folder)

        with open('%s/%s.gb' % (folder,item), 'w') as textfile:
            textfile.write(data)

        print 'done downloading %s' % item
        
        sleep(2)