GSForge.utils.R_interface module

This module contains functions for preparing data for transfer to and from the R programming language.

Such functionality is powered by the rpy2 library.

No conversion function is needed for preparing labels, as one can use the builtin pandas.DataFrame function to_dataframe.:

label_df = labels.to_dataframe()
GSForge.utils.R_interface.Py_counts_to_R(counts: xarray.core.dataarray.DataArray)

Prepare a count xarray.DataArray as a pandas.DataFrame for transfer to the R programming language.

This function transposes the data to have genes as rows and samples as columns. It then converts to a pandas.DataFrame and removes extraneous index levels.

The inverse of this function is R_counts_to_Py_counts.

Parameters

counts – An xr.DataArray count matrix.

Returns count_df

A pandas.DataFrame ready to transfer to an R environment.

GSForge.utils.R_interface.R_counts_to_Py(r_count_array, original_count_array)

Prepares a numpy array (count matrix) for use in GSForge.

This function transposes the data (so that it has samples as rows and genes as columns).

Inverts the conversion provided by Py_counts_to_R.

Parameters
  • r_count_array – A numpy array of count values. Presumed to be oriented with genes as rows, and samples as columns.

  • original_count_array – A copy of the original count array from which coordinates will be drawn.

Returns

An xarray.DataArray of the count values.

GSForge.utils.R_interface.Py_labels_to_R(label_ds)