# Path: picrust/util.py
# @contextmanager
# def atomic_write(file):
#     """
#     Yields an open temporary file and renames to ``file`` on exit
# 
#     This context manager aims to make it more convenient to write to a file
#     only when the write operation has completed (e.g. downloading a file from
#     the internet).
# 
#     The yielded file will be open in 'wb' mode.
#     """
#     dir_name, basename = split(file)
#     tmp_path = join(dir_name, '~{}'.format(basename))
# 
#     try:
#         with open(tmp_path, 'wb') as f:
#             yield f
#             f.flush()
#             fsync(f.fileno())
#     except:
#         remove(tmp_path)
#         raise
#     else:
#         rename(tmp_path, file)


from future.moves.urllib.parse import urljoin
from future.moves.urllib.request import urlopen, HTTPError
from cogent.util.option_parsing import (
    make_option,
    parse_command_line_parameters,
)
from picrust.util import atomic_write
import os
import picrust
            ci_files = [
                FILES[('16s_ci', gg_version)],
                FILES[(type_of_prediction + '_ci', gg_version)],
            ]
        except KeyError:
            msg = 'Error: CI files not available for {gg_version}'
            print(msg.format(gg_version=gg_version))
            exit(1)

        files_to_download.extend(ci_files)

    print('Downloading files to {path}...'.format(path=output_path))

    for filename in files_to_download:
        if 'variances' not in filename:
            url = urljoin(BASE_URL, gg_version + '/' + filename)
        else:
            url = urljoin(BASE_URL, gg_version + '/variances/' + filename)

        file_path = os.path.join(DATA_DIR, filename)

        if os.path.exists(file_path) and not force:
            msg = 'Skipping download of {filename}: file already exists.'
            print(msg.format(filename=filename))
            continue
        else:
            print('Downloading {filename}...'.format(filename=filename))

        try:
            response = urlopen(url)

# Path: picrust/util.py
# @contextmanager
# def atomic_write(file):
#     """
#     Yields an open temporary file and renames to ``file`` on exit
# 
#     This context manager aims to make it more convenient to write to a file
#     only when the write operation has completed (e.g. downloading a file from
#     the internet).
# 
#     The yielded file will be open in 'wb' mode.
#     """
#     dir_name, basename = split(file)
#     tmp_path = join(dir_name, '~{}'.format(basename))
# 
#     try:
#         with open(tmp_path, 'wb') as f:
#             yield f
#             f.flush()
#             fsync(f.fileno())
#     except:
#         remove(tmp_path)
#         raise
#     else:
#         rename(tmp_path, file)


# Path: scripts/download_picrust_files.py
from future.moves.urllib.parse import urljoin
from future.moves.urllib.request import urlopen, HTTPError
from cogent.util.option_parsing import (
    make_option,
    parse_command_line_parameters,
)
from picrust.util import atomic_write
import os
import picrust

            ci_files = [
                FILES[('16s_ci', gg_version)],
                FILES[(type_of_prediction + '_ci', gg_version)],
            ]
        except KeyError:
            msg = 'Error: CI files not available for {gg_version}'
            print(msg.format(gg_version=gg_version))
            exit(1)

        files_to_download.extend(ci_files)

    print('Downloading files to {path}...'.format(path=output_path))

    for filename in files_to_download:
        if 'variances' not in filename:
            url = urljoin(BASE_URL, gg_version + '/' + filename)
        else:
            url = urljoin(BASE_URL, gg_version + '/variances/' + filename)

        file_path = os.path.join(DATA_DIR, filename)

        if os.path.exists(file_path) and not force:
            msg = 'Skipping download of {filename}: file already exists.'
            print(msg.format(filename=filename))
            continue
        else:
            print('Downloading {filename}...'.format(filename=filename))

        try:
            response = urlopen(url)

            with atomic_write(file_path) as f: