Data I/O (sdq.io)#

sdq.io.read_h5ad
scdiffeq.io._data._read_h5ad.read_h5ad(h5ad_path: str, silent: bool = False, annotate_path: bool = True) AnnData[source]

Read an AnnData object from a path to a .h5ad file.

Parameters:
  • h5ad_path (str) – Path to .h5ad file.

  • silent (bool) – If True, the AnnData object is not printed.

  • annotate_path (bool) – If True, adds the h5ad_path to the read AnnData object in adata.uns[‘h5ad_path’].

Returns:

anndata.AnnData

The (annotated) single-cell data matrix of shape n_obs × n_vars. Rows correspond to cells and columns to genes.

For more information, visit: https://anndata.readthedocs.io/en/latest/.

Notes

Documentation for AnnData: https://anndata.readthedocs.io/en/stable/

More: sdq.io.read_h5ad

sdq.io.read_pickle
scdiffeq.io._data._pickle_io.read_pickle(path: str | Path, mode: str | None = 'rb')[source]

Read the contents of a pickle file into memory.

Parameters:
  • path (Union[str, Path]) – pickle file path.

  • mode (Optional[str]) – read mode. Default = “rb”

Returns:

Object, usually a dictionary contained in pickle file.

Return type:

obj (Dict[Any,Any])

More: sdq.io.read_pickle

sdq.io.write_pickle
scdiffeq.io._data._pickle_io.write_pickle(obj: Dict[Any, Any], path: str | Path, mode: str | None = 'wb', protocol: int | None = 5) None[source]

Save an object to a pickle file.

Parameters:
  • obj (Dict[Any, Any]) – Object, usually a dictionary to write to pickle file.

  • path (Union[str, Path]) – Path to which pickle file should be written.

  • mode (Optional[str]) – Write mode. Default = “wb”

  • protocol (Optional[int]) – Pickling protocol. Default = pickle.HIGHEST_PROTOCOL

Returns:

None

More: sdq.io.write_pickle

sdq.io.Project
class scdiffeq.io.Project(path: str | Path = PosixPath('/home/runner/work/scDiffEq/scDiffEq/docs/source'), metrics_groupby: str = 'epoch', *args, **kwargs)[source]

Object container for an scDiffEq project

path

Path to the project, created by scDiffeq.

Type:

Union[str, Path]

metrics_groupby

Grouping method for metrics, default is “epoch”.

Type:

str

Initialize the project object by providing a path.

Parameters:
  • path (Union[str, Path], optional) – Path to the project, created by scDiffeq, by default pathlib.Path(“./”).absolute()

  • metrics_groupby (str, optional) – Grouping method for metrics, by default “epoch”

Returns:

None

__init__(path: str | Path = PosixPath('/home/runner/work/scDiffEq/scDiffEq/docs/source'), metrics_groupby: str = 'epoch', *args, **kwargs) None[source]

Initialize the project object by providing a path.

Parameters:
  • path (Union[str, Path], optional) – Path to the project, created by scDiffeq, by default pathlib.Path(“./”).absolute()

  • metrics_groupby (str, optional) – Grouping method for metrics, by default “epoch”

Returns:

None

_set_version_path_attributes() None[source]

Sets the name of each version as a class attribute, pointing to the path of the version.

__getitem__(version: int) Path[source]

Format version key and return version

Parameters:

version (int) – Version number

Returns:

pathlib.Path Path to the specified version

More: sdq.io.Project

sdq.io.Version
class scdiffeq.io.Version(path: Path | str = None, groupby: str = 'epoch', *args, **kwargs)[source]

scDiffEq Version object container

_path

Path to the version within an scDiffEq project.

Type:

Union[Path, str]

_groupby

Grouping method for metrics, default is “epoch”.

Type:

str

Instantiate Version by providing a path

Parameters:
  • path (Union[Path, str], optional) – Path to the version within an scDiffEq project, by default None.

  • groupby (str, optional) – Grouping method for metrics, by default “epoch”

Return type:

None

__init__(path: Path | str = None, groupby: str = 'epoch', *args, **kwargs)[source]

Instantiate Version by providing a path

Parameters:
  • path (Union[Path, str], optional) – Path to the version within an scDiffEq project, by default None.

  • groupby (str, optional) – Grouping method for metrics, by default “epoch”

Return type:

None

property hparams

Check if the .yaml exists and instantiate the HParams class each time

Returns:

Instance of HParams class if hparams.yaml exists

Return type:

HParams

property metrics_df: DataFrame

Check if metrics.csv path exists and read it

Returns:

DataFrame containing the metrics if metrics.csv exists

Return type:

pd.DataFrame

property per_epoch_metrics

Group metrics by the specified groupby attribute

Returns:

Instance of GroupedMetrics class

Return type:

GroupedMetrics

property ckpts: Dict

Format and update available checkpoints for the version

Returns:

Dictionary of checkpoints

Return type:

Dict

__repr__() str[source]

Return the name of the object

Returns:

Name of the object

Return type:

str

More: sdq.io.Version

sdq.io.Checkpoint
class scdiffeq.io.Checkpoint(path: Path | str, *args, **kwargs)[source]

Instantiates checkpoint object.

Parameters:

path (Union[Path, str]) – Path to saved checkpoint.

__init__(path: Path | str, *args, **kwargs) None[source]

Instantiates checkpoint object.

Parameters:

path (Union[Path, str]) – Path to saved checkpoint.

property path: Path

Returns: pathlib.Path The path to the checkpoint.

property version

Returns: str Version of the checkpoint.

property F_hat

Returns: pd.DataFrame or None DataFrame containing F_hat data if the path exists, otherwise None.

property epoch: int | str

Returns: Union[int, str] Epoch number if not ‘last’, otherwise ‘last’.

property ckpt: Dict[str, LightningCheckpoint]

Returns: Dict[str, “LightningCheckpoint”] State dictionary created by PyTorch Lightning.

__repr__() str[source]
Returns:

str Object description of checkpoint at epoch.

More: sdq.io.Checkpoint

sdq.io.HParams
class scdiffeq.io.HParams(yaml_path: Path | str)[source]

scDiffEq container for HyperParams

_yaml_path

Path to the hparams file created by Lightning.

Type:

Union[Path, str]

_yaml_file

Dictionary containing the contents of the yaml file.

Type:

dict

_attrs

Formatted attribute dictionary from hparams.yaml.

Type:

Dict[str, Any]

Initialize the HParams object by providing a path to thecorresponding yaml file (created by Lightning)

Parameters:

yaml_path (Union[Path, str]) – Path to the hparams file created by Lightning.

Returns:

None

__init__(yaml_path: Path | str) None[source]

Initialize the HParams object by providing a path to thecorresponding yaml file (created by Lightning)

Parameters:

yaml_path (Union[Path, str]) – Path to the hparams file created by Lightning.

Returns:

None

_read() None[source]

Read path to yaml file and set as class attribute

Returns:

None

__configure__(kwargs, private=['yaml_path']) None[source]

Set hparams as class attributes

Parameters:
  • kwargs (dict) – Dictionary of keyword arguments.

  • private (list, optional) – List of private attributes, by default [“yaml_path”]

Returns:

None

__getitem__(attr: str) Any[source]

Format version key and return path

Parameters:

attr (str) – Attribute name.

Returns:

Any Attribute value.

__repr__() str[source]

Return a readable representation of the discovered hyperparameters

Returns:

str Readable representation of the hyperparameters.

__call__() Dict[str, Any][source]

Return formatted dictionary of attributes from the hparams.yaml

Returns:

Dict[str, Any] Dictionary of attributes.

More: sdq.io.HParams