module

biopipen.utils.misc

Functions
  • read_table(path_or_buf, factor_levels_sep, **kwargs) (DataFrame) Read a table from a file or buffer.It works like pd.read_csv, but with factor levels (categories) restored. </>
  • require_package(package, version, python) Require a Python package to be installed with optional version check.</>
  • run_command(cmd, fg, wait, print_command, print_command_handler, **kwargs) (subprocess.popen | str) Run a command.</>
  • write_table(df, path_or_buf, factor_levels_sep, **kwargs) (str | none) Write a DataFrame to a file or buffer.If path_or_buf is None, returns the string representation of the DataFrame. It works like DataFrame.to_csv, but with factor levels (categories) saved. </>
function

biopipen.utils.misc.require_package(package, version=None, python=None)

Require a Python package to be installed with optional version check.

The version specifier should follow the format used by pip, e.g., '>=1.2.3'. Multiple version specifiers can be separated by commas, e.g., '>=1.2.3,<2.0.0'.

Parameters
  • package (str) The name of the package to check.
  • version (str | None) The version specifier string.
  • python (str | None) The Python interpreter to use.
function

biopipen.utils.misc.run_command(cmd, fg=False, wait=True, print_command=True, print_command_handler=<built-in function print>, **kwargs)

Run a command.

Parameters
  • cmd (Union) A string or list of strings representing the command to run.
  • fg (bool, optional) Whether to run the command in the foreground.Redirects stdout and stderr to the current process.
  • wait (bool, optional) Whether to wait for the command to finish.The command will be waited for if fg is True.
  • print_command (bool, optional) Whether to print the command before running it.
  • print_command_handler (Callable, optional) The function to use to print the command.
  • kwargs Keyword arguments to pass to subprocess.Popen.
Returns (subprocess.popen | str)

The Popen object, or str when stdout is RETURN or return.

function

biopipen.utils.misc.write_table(df, path_or_buf=None, factor_levels_sep='|', **kwargs) → str | none

Write a DataFrame to a file or buffer.If path_or_buf is None, returns the string representation of the DataFrame. It works like DataFrame.to_csv, but with factor levels (categories) saved.

Example
>>> import pandas as pd>>> df = pd.DataFrame({
...     'A': pd.Categorical(['a', 'b', 'a'], categories=['a', 'b', 'c']),
...     'B': [1, 2, 3]
... })
>>> write_table(df)
# factor-levels: A=a|b|c
A,B
a,1
b,2
a,3
Parameters
  • df (DataFrame) The DataFrame to write.
  • path_or_buf (optional) The file path or buffer to write to. If None, returns thestring representation of the DataFrame.
  • factor_levels_sep (str, optional) The separator used to join the factor levels.
  • **kwargs Additional keyword arguments to pass to DataFrame.to_csv.
function

biopipen.utils.misc.read_table(path_or_buf, factor_levels_sep='|', **kwargs) → DataFrame

Read a table from a file or buffer.It works like pd.read_csv, but with factor levels (categories) restored.

Parameters
  • path_or_buf The file path or buffer to read from.
  • factor_levels_sep (str, optional) The separator used to join the factor levels.
  • **kwargs Additional keyword arguments to pass to pd.read_csv.