Utilities#

General Utils#

qiime2.util.duplicate(src, dst)[source]#

Alternative to shutil.copyfile() this will use os.link() when possible.

See shutil.copyfile() for documention. Only src and dst are supported. Unlike copyfile, this will not overwrite the destination if it exists.

qiime2.util.redirected_stdio(stdout=None, stderr=None)[source]#

A context manager to redirect stdio to a new file (if provided).

Parameters:
  • stdout (file-like object or file-descriptor (int)) – The file to redirect stdout to. Does nothing to the process-table if not provided.

  • stderr (file-like object or file-descriptor (int)) – The file to redirect stderr to. Does nothing to the process-table if not provided.

Notes

The current sys.stdout/sys.stderr must be backed by a file descriptor (i.e they cannot be replaced with BytesIO).

Plugin Utils#

qiime2.plugin.util.transform(data, *, from_type=None, to_type)[source]#
qiime2.plugin.util.get_available_cores(n_less=0)[source]#

Finds the number of currently available (logical) cores. Useful for plugins that need to convert a 0 to a concrete number of cores when 0 is not supported by the underlying/called software.

Parameters:

n_less (int) – The number of cores less than the total number available to request. For example get_available_cores(n_less=2) with 10 available cores will return 8.

Returns:

The number of cores to be requested.

Return type:

int