Regress Out Tutorial

Author: Yiming Yang
Date: 2020-12-02
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 pc_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 new PCs:

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

More on Regress Out Result

The scatter plot above only shows the first 2 PCs after regressing out.

Since it's not possible to visualize all the 50 PCs in 2D plot, we need to perform another PCA step on them, and then plot the top 2 PCs from the generated new ones, which account for most variability of the PCs after regressing out:

So indeed, no evident cell-cycle effects are observed in all the 50 PCs after regressing out.

Summary

You can use the immediate result of pc_regress_out function (i.e. data.obsm['X_pca_regressed']) for the downstream analysis. 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.