Regress Out Tutorial

Author: Yiming Yang
Date: 2021-06-24
Notebook Source: regress_out.ipynb

This tutorial shows how to regress out cell cycle using Pegasus. To benchmark the work analogous to Seurat's tutorial and SCANPY's tutorial, we use the same dataset of murine hematopoietic progenitors from [Nestorowa et al., Blood 2016], which can be downloaded here.

Cell-Cycle Scores

First, load the data:

We need to do some preprocessing work before calculating the cell-cycle scores:

To be consistent with Seurat's tutorial, the filtration threshold on number of genes is set to be large enough to avoid removing any cell barcode, and a normalization of TP10k (transcripts per 10k) is performed.

Now calculate cell-cycle scores using calc_signature_score (see here for its documentation):

By setting cell_cycle_human, Pegasus uses the cell cycle genes defined in [Tirosh et al. 2015] for calculation. We can fetch these genes from Pegasus pre-stored file (https://raw.githubusercontent.com/klarman-cell-observatory/pegasus/master/pegasus/data_files/cell_cycle_human.gmt), as we'll need them in the following sections:

Moreover, the predicted phases of cells are stored in data.obs field with key predicted_phase:

And the corresponding scores are in data.obs['G1/S'] and data.obs['G2/M'].

Cell Cycle Effects

The presence of cell cycle effects can be shown in terms of Principal Components (PC), which are calculated from gene-count matrix with respect to cell cycle genes:

After achieving PCA result, we can generate a scatter plot of first two PCs with predicted phase being the colors for cells:

In this plot, we can see that cells are quite separated due to their phases when cell cycle genes are considered.

Regress Out Cell Cycle Effects

This section shows how to regress out cell cycle effects.

Pegasus performs this regressing out on PCs. After getting the original PCA matrix, it uses the cell-cycle scores for this operation:

When regress_out is finished, the resulting new PCA embedding matrix is stored in data.obsm['X_pca_regressed'], with the representation key 'pca_regressed' returned to variable pca_key.

Now let's see how PC scatter plot looks on the regressed-out components:

You can see that after regressing out cell-cycle scores, no evident cell-cycle effects are observed in the first 2 PCs.

Alternate Workflow

The alternative in this section simply mimics Seurat's way of regressing out the difference between the G2/M and G1/S phase scores. As stated in Seurat tutorial, in this way, we'll have differences in cell cycle phases regressed out, while the differences between non-cycling cells and cycling cells are maintained.

Summary

You can use the immediate result of regress_out function (i.e. data.obsm['X_pca_regressed']) for the downstream analysis (e.g. pg.neighbors(data, rep='pca_regressed'); pg.louvain(data, rep='pca_regressed')). Just remember to set the basis argument of the Pegasus functions whenever applicable.

The major difference between Pegasus' method and conventional method is that Pegasus performs regressing out on PCs, rather than all the features. For example, in this case, Pegasus only considers $50$ PCs, instead of all the $24,158$ features. Therefore, Pegasus method can be more efficient on large-scale datasets which contains many more cell barcodes.

Matching with Seurat and SCANPY Tutorials

In sections above, we only show the scatter plots of first two of the regressed-out components. In order to match with the corresponding tutorials in Seurat and SCANPY, we further perform PCA on these components, and show the PC scatter plots in the newly computed PCs.

First is the result after regressing out the cell cycle effects based on G2/M and G1/S phase scores:

So indeed, no evident cell-cycle effects are observed after regressing out.

Then the result of the alternative workflow, i.e. regressing out the difference between the G2/M and G1/S phase scores:

In the plot above, cells in G2/M and G1/S phases have a better mixture, while their difference from those in G0 phase is maintained.