quipcell package

Module contents

quipcell.estimate_size_factors(X, n_reads, sample, **kwargs)[source]

Estimate cell-level size factors with Poisson regression to control for technical variation between samples.

Returns a vector of the size factor for each cell.

**kwargs are additional keyword arguments passed to

sklearn.linear_model.PoissonRegressor.

Parameters:
  • X (numpy.ndarray) – Single cell embedding. Rows=cells, columns=features.

  • n_reads (numpy.ndarray) – 1d vector of the number of reads per cell.

  • sample (numpy.ndarray) – 1d string vector for the sample that each cell came from.

Return type:

numpy.ndarray

quipcell.estimate_weights_multisample(X, mu_multisample, renormalize=True, alpha='pearson', use_dual_lbfgs=None, return_with_solver_info=False, mom_atol=0, mom_rtol=0, solve_kwargs=None)[source]

Estimate density weights for multiple samples on a single-cell reference.

Returns a numpy array with rows=cells, columns=samples.

Parameters:
  • X (numpy.ndarray) – Reference embedding. Rows=cells, columns=features.

  • mu_multisample (numpy.ndarray) – Sample moments. Either bulk gene counts or a linear transformation thereof. Rows=samples, columns=features.

  • renormalize (bool) – Correct for any solver inaccuracies by setting small negative numbers to 0, and renormalizing sums to 1.

  • alpha (float) – Value of alpha for alpha-divergence. Also accepts ‘pearson’ for alpha=2 (which is a quadratic program) or ‘kl’ for alpha=1 (which is same as maximum entropy).

  • use_dual_lbfgs (bool) – If True, solve via the dual problem with L-BFGS-B, instead of using cvxpy. Currently only implemented for alpha==1 or alpha==’kl’. Default is True when alpha==1 or ‘kl’, and False otherwise.

  • mom_atol (float) – For moment constraints, require X.T @ w = mu +/- eps, where eps = mom_atol + abs(mu) * mom_rtol.

  • mom_rtol (float) – For moment constraints, require X.T @ w = mu +/- eps, where eps = mom_atol + abs(mu) * mom_rtol.

  • solve_kwargs (dict) – Additional kwargs to pass to cvxpy.Problem.solve() or scipy.optimize.minimize() (depending on use_dual_lbfgs).

  • return_with_solver_info (bool) – If False, return a numpy array with the weights. If True, return a dict with the weights, the dual solution for the moment constraints, and the objective.

Return type:

Union[dict,numpy.ndarray]

quipcell.renormalize_weights(weights, size_factors)[source]

Renormalize weights to correct for cell-specific size factors.

This can be used to convert read-level probability weights to cell-level weights.

Parameters:
  • weights (numpy.ndarray) – Weights as returned by quipcell.estimate_weights_multisample. Rows=cells, columns=samples.

  • size_factors (numpy.ndarray) – Cell-level size factors. Should be 1 dimensional, with length equal to the number of rows in weights.

Return type:

numpy.ndarray