# Path: onecodex/auth.py
# def login_required(fn):
#     """Require login before proceeding, but does not prompt the user to login.
# 
#     Decorator should be used only on Click CLI commands.
# 
#     Notes
#     -----
#     Different means of authentication will be attempted in this order:
#         1. An API key present in the Click context object from a previous successful authentication.
#         2. A bearer token (ONE_CODEX_BEARER_TOKEN) in the environment.
#         3. An API key (ONE_CODEX_API_KEY) in the environment.
#         4. An API key in the credentials file (~/.onecodex).
#     """
# 
#     @wraps(fn)
#     def login_wrapper(ctx, *args, **kwargs):
#         base_url = os.environ.get("ONE_CODEX_API_BASE", "https://app.onecodex.com")
# 
#         api_kwargs = {"telemetry": ctx.obj["TELEMETRY"], "load_extensions": False}
# 
#         api_key_prior_login = ctx.obj.get("API_KEY")
#         bearer_token_env = os.environ.get("ONE_CODEX_BEARER_TOKEN")
#         api_key_env = os.environ.get("ONE_CODEX_API_KEY")
#         api_key_creds_file = _login(base_url, silent=True)
# 
#         if api_key_prior_login is not None:
#             api_kwargs["api_key"] = api_key_prior_login
#         elif bearer_token_env is not None:
#             api_kwargs["bearer_token"] = bearer_token_env
#         elif api_key_env is not None:
#             api_kwargs["api_key"] = api_key_env
#         elif api_key_creds_file is not None:
#             api_kwargs["api_key"] = api_key_creds_file
#         else:
#             click.echo(
#                 "The command you specified requires authentication. Please login first.\n", err=True
#             )
#             ctx.exit(1)
# 
#         ctx.obj["API"] = Api(**api_kwargs)
# 
#         return fn(ctx, *args, **kwargs)
# 
#     return login_wrapper
# 
# Path: onecodex/exceptions.py
# class OneCodexException(Exception):
#     pass
# 
# class ValidationError(OneCodexException):
#     pass
# 
# Path: onecodex/utils.py
# def download_file_helper(url, input_path):
#     """Manage the chunked downloading of a file given an url."""
#     r = requests.get(url, stream=True)
#     if r.status_code != 200:
#         log.error("Failed to download file: %s" % r.json()["message"])
#     local_full_path = get_download_dest(input_path, r.url)
#     original_filename = os.path.split(local_full_path)[-1]
#     with open(local_full_path, "wb") as f:
#         click.echo("Downloading {}".format(original_filename), err=True)
#         for chunk in r.iter_content(chunk_size=1024):
#             if chunk:  # filter out keep-alive new chunks
#                 f.write(chunk)
#                 f.flush()
#     pprint("Successfully downloaded %s to %s" % (original_filename, local_full_path), True)  # noqa
# 
# def get_download_dest(input_path, url):
#     original_filename = urlparse(url).path.split("/")[-1]
#     if os.path.isdir(input_path):
#         local_full_path = os.path.join(input_path, original_filename)
#     else:
#         local_full_path = input_path
#     return local_full_path
# 
# def pretty_errors(fn):
#     """Decorate CLI functions, catching errors and then calling sys.exit(1).
# 
#     This is intended for use with the CLI and scripts where we only use OneCodexException and its
#     subclasses, e.g. ValidationError or UploadException.
#     """
# 
#     @wraps(fn)
#     def pretty_errors_wrapper(*args, **kwargs):
#         try:
#             fn(*args, **kwargs)
#         except (OneCodexException, UploadException) as e:
#             sys.stderr.write("\nERROR: {}".format(e))
#             sys.stderr.write("\nPlease feel free to contact us for help at help@onecodex.com\n\n")
#             sys.exit(1)
# 
#     return pretty_errors_wrapper


import click
import bz2
import csv
import gzip
import io
import os
import warnings
    import skbio
from onecodex.auth import login_required
from onecodex.exceptions import OneCodexException, ValidationError
from onecodex.utils import download_file_helper, get_download_dest, pretty_errors

        tax_ids = new_tax_ids

    tax_ids = set(tax_ids)

    # pull the classification result TSV
    tsv_url = classification._readlevel()["url"]
    readlevel_path = get_download_dest("./", tsv_url)
    if not os.path.exists(readlevel_path):
        download_file_helper(tsv_url, "./")
    else:
        click.echo("Using cached read-level results: {}".format(readlevel_path), err=True)

    # count the number of rows in the TSV file
    with gzip.open(readlevel_path, "rt") as tsv:
        try:
            tsv_row_count = 0
            for _ in tsv:
                tsv_row_count += 1
            tsv_row_count -= 1  # discount header line
        except EOFError:
            click.echo(
                "\nWe encountered an error while processing the read "
                "level results. Please delete {} and try again.".format(readlevel_path),
                err=True,
            )
            raise

    if reverse:
        if tsv_row_count % 2 != 0:

# Path: onecodex/auth.py
# def login_required(fn):
#     """Require login before proceeding, but does not prompt the user to login.
# 
#     Decorator should be used only on Click CLI commands.
# 
#     Notes
#     -----
#     Different means of authentication will be attempted in this order:
#         1. An API key present in the Click context object from a previous successful authentication.
#         2. A bearer token (ONE_CODEX_BEARER_TOKEN) in the environment.
#         3. An API key (ONE_CODEX_API_KEY) in the environment.
#         4. An API key in the credentials file (~/.onecodex).
#     """
# 
#     @wraps(fn)
#     def login_wrapper(ctx, *args, **kwargs):
#         base_url = os.environ.get("ONE_CODEX_API_BASE", "https://app.onecodex.com")
# 
#         api_kwargs = {"telemetry": ctx.obj["TELEMETRY"], "load_extensions": False}
# 
#         api_key_prior_login = ctx.obj.get("API_KEY")
#         bearer_token_env = os.environ.get("ONE_CODEX_BEARER_TOKEN")
#         api_key_env = os.environ.get("ONE_CODEX_API_KEY")
#         api_key_creds_file = _login(base_url, silent=True)
# 
#         if api_key_prior_login is not None:
#             api_kwargs["api_key"] = api_key_prior_login
#         elif bearer_token_env is not None:
#             api_kwargs["bearer_token"] = bearer_token_env
#         elif api_key_env is not None:
#             api_kwargs["api_key"] = api_key_env
#         elif api_key_creds_file is not None:
#             api_kwargs["api_key"] = api_key_creds_file
#         else:
#             click.echo(
#                 "The command you specified requires authentication. Please login first.\n", err=True
#             )
#             ctx.exit(1)
# 
#         ctx.obj["API"] = Api(**api_kwargs)
# 
#         return fn(ctx, *args, **kwargs)
# 
#     return login_wrapper
# 
# Path: onecodex/exceptions.py
# class OneCodexException(Exception):
#     pass
# 
# class ValidationError(OneCodexException):
#     pass
# 
# Path: onecodex/utils.py
# def download_file_helper(url, input_path):
#     """Manage the chunked downloading of a file given an url."""
#     r = requests.get(url, stream=True)
#     if r.status_code != 200:
#         log.error("Failed to download file: %s" % r.json()["message"])
#     local_full_path = get_download_dest(input_path, r.url)
#     original_filename = os.path.split(local_full_path)[-1]
#     with open(local_full_path, "wb") as f:
#         click.echo("Downloading {}".format(original_filename), err=True)
#         for chunk in r.iter_content(chunk_size=1024):
#             if chunk:  # filter out keep-alive new chunks
#                 f.write(chunk)
#                 f.flush()
#     pprint("Successfully downloaded %s to %s" % (original_filename, local_full_path), True)  # noqa
# 
# def get_download_dest(input_path, url):
#     original_filename = urlparse(url).path.split("/")[-1]
#     if os.path.isdir(input_path):
#         local_full_path = os.path.join(input_path, original_filename)
#     else:
#         local_full_path = input_path
#     return local_full_path
# 
# def pretty_errors(fn):
#     """Decorate CLI functions, catching errors and then calling sys.exit(1).
# 
#     This is intended for use with the CLI and scripts where we only use OneCodexException and its
#     subclasses, e.g. ValidationError or UploadException.
#     """
# 
#     @wraps(fn)
#     def pretty_errors_wrapper(*args, **kwargs):
#         try:
#             fn(*args, **kwargs)
#         except (OneCodexException, UploadException) as e:
#             sys.stderr.write("\nERROR: {}".format(e))
#             sys.stderr.write("\nPlease feel free to contact us for help at help@onecodex.com\n\n")
#             sys.exit(1)
# 
#     return pretty_errors_wrapper


# Path: onecodex/scripts/subset_reads.py
import click
import bz2
import csv
import gzip
import io
import os
import warnings
    import skbio
from onecodex.auth import login_required
from onecodex.exceptions import OneCodexException, ValidationError
from onecodex.utils import download_file_helper, get_download_dest, pretty_errors


        tax_ids = new_tax_ids

    tax_ids = set(tax_ids)

    # pull the classification result TSV
    tsv_url = classification._readlevel()["url"]
    readlevel_path = get_download_dest("./", tsv_url)
    if not os.path.exists(readlevel_path):
        download_file_helper(tsv_url, "./")
    else:
        click.echo("Using cached read-level results: {}".format(readlevel_path), err=True)

    # count the number of rows in the TSV file
    with gzip.open(readlevel_path, "rt") as tsv:
        try:
            tsv_row_count = 0
            for _ in tsv:
                tsv_row_count += 1
            tsv_row_count -= 1  # discount header line
        except EOFError:
            click.echo(
                "\nWe encountered an error while processing the read "
                "level results. Please delete {} and try again.".format(readlevel_path),
                err=True,
            )
            raise

    if reverse:
        if tsv_row_count % 2 != 0:

            raise ValidationError(