generated from sib-swiss/course_website_template
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb44472
commit e4d0841
Showing
12 changed files
with
50 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,20 @@ | |
"section": "Exercises", | ||
"text": "Exercises\nLoad the following packages:\n\nlibrary(celldex)\nlibrary(SingleR)\n\nIn the last exercise we saw that probably clustering at a resolution of 0.3 gave the most sensible results. Let’s therefore set the default identity of each cell based on this clustering:\n\nseu <- Seurat::SetIdent(seu, value = seu$RNA_snn_res.0.3)\n\n\n\n\n\n\n\nNote\n\n\n\nFrom now on, grouping (e.g. for plotting) is done by the active identity (set at @active.ident) by default.\n\n\nDuring cell annotation we will use the original count data (not the integrated data):\n\nDefaultAssay(seu) <- \"RNA\"\n\nBased on the UMAP we have generated, we can visualize expression for a gene in each cluster:\n\nSeurat::FeaturePlot(seu, \"HBA1\")\n\n\n\n\nBased on expression of sets of genes you can do a manual cell type annotation. If you know the marker genes for some cell types, you can check whether they are up-regulated in one or the other cluster. Here we have some marker genes for two different cell types:\n\ntcell_genes <- c(\"IL7R\", \"LTB\", \"TRAC\", \"CD3D\")\nmonocyte_genes <- c(\"CD14\", \"CST3\", \"CD68\", \"CTSS\")\n\nLet’s have a look at the expression of the four T cell genes:\n\nSeurat::FeaturePlot(seu, tcell_genes, ncol=2)\n\n\n\n\nThese cells are almost all in cluster 0 and 8. Which becomes clearer when looking at the violin plot:\n\nSeurat::VlnPlot(seu,\n features = tcell_genes,\n ncol = 2)\n\n\n\n\n\n\n\n\n\n\nExercise\n\n\n\nHave a look at the monocyte genes as well. Which clusters contain probably monocytes?\n\n\n\n\n\n\n\n\nAnswer\n\n\n\n\n\n\nSeurat::FeaturePlot(seu, monocyte_genes, ncol=2)\n\n\n\n\n\nSeurat::VlnPlot(seu,\n features = monocyte_genes,\n ncol = 2)\n\n\n\n\n\n\n\nWe can also automate this with the function AddModuleScore. For each cell, an expression score for a group of genes is calculated:\n\nseu <- Seurat::AddModuleScore(seu,\n features = list(tcell_genes),\n name = \"tcell_genes\")\n\n\n\n\n\n\n\nExercise\n\n\n\nAfter running AddModuleScore, a column was added to [email protected].\nA. What is the name of that column? What kind of data is in there?\nB. Generate a UMAP with color accoding to this column and a violinplot grouped by cluster. Is this according to what we saw in the previous exercise?\n\n\n\n\n\n\n\n\nAnswer\n\n\n\n\n\nA. The new column is called tcell_genes1. It contains the module score for each cell (which is basically the average expression of the set of genes).\nB. You can plot the UMAP with\n\nSeurat::FeaturePlot(seu, \"tcell_genes1\")\n\n\n\n\nWhich indeed shows these genes are mainly expressed in clusters 0 and 8:\n\nSeurat::VlnPlot(seu,\n \"tcell_genes1\")\n\n\n\n\n\n\n\nAnnotating cells according to cycling phase\nBased on the same principle, we can also annotate cell cycling state. The function CellCycleScore uses AddModuleScore to get a score for the G2/M and S phase (the mitotic phases in which cell is cycling). In addition, CellCycleScore assigns each cell to either the G2/M, S or G1 phase.\nFirst we extract the built-in genes for cell cycling:\n\ns.genes <- Seurat::cc.genes.updated.2019$s.genes\ng2m.genes <- Seurat::cc.genes.updated.2019$g2m.genes\n\nNow we run the function:\n\nseu <- Seurat::CellCycleScoring(seu,\n s.features = s.genes,\n g2m.features = g2m.genes)\n\nAnd we can visualize the annotations:\n\nSeurat::DimPlot(seu, group.by = \"Phase\")\n\n\n\n\nBased on your application, you can try to regress out the cell cycling scores at the step of scaling. Reasons for doing that could be:\n\nMerging cycling and non-cycling cells of the same type in one cluster\nMerging G2/M and S phase in one cluster\n\n\n\n\n\n\n\nNote\n\n\n\nNote that correcting for cell cycling is performed at the scaling step. It will therefore only influence analyses that use scaled data, like dimensionality reduction and clustering. For e.g. differential gene expression testing, we use the raw original counts (not scaled).\n\n\nHere, we choose not to regress out either of them. Because we are looking at developing cells, we might be interested to keep cycling cells seperated. In addition, the G2/M and S phases seem to be in the same clusters. More info on correcting for cell cycling here.\nCell type annotation using SingleR\n\nTo do a fully automated annoation, we need a reference dataset of primary cells. Any reference could be used. The package scRNAseq in Bioconductor includes several scRNAseq datasets that can be used as reference to SingleR. One could also use a reference made of bulk RNA seq data. Here we are using the a hematopoietic reference dataset from celldex. Check out what’s in there:\n\nref <- celldex::NovershternHematopoieticData()\nclass(ref)\ntable(ref$label.main)\n\n\n\n\n\n\n\nNote\n\n\n\nYou will be asked whether to create the directory /home/rstudio/.cache/R/ExperimentHub. Type yes as a response.\n\n\n\n\n\n\n\n\nNote\n\n\n\nYou can find more information on different reference datasets at the celldex documentation\n\n\nNow SingleR compares our normalized count data to a reference set, and finds the most probable annation:\n\nseu_SingleR <- SingleR::SingleR(test = Seurat::GetAssayData(seu),\n ref = ref,\n labels = ref$label.main)\n\nSee what’s in there by using head:\n\nhead(seu_SingleR)\n\nDataFrame with 6 rows and 4 columns\n scores labels\n <matrix> <character>\nPBMMC-1_AAACCTGCAGACGCAA-1 0.216202:0.197296:0.086435:... B cells\nPBMMC-1_AAACCTGTCATCACCC-1 0.143005:0.129582:0.170521:... CD8+ T cells\nPBMMC-1_AAAGATGCATAAAGGT-1 0.113423:0.196264:0.111341:... Monocytes\nPBMMC-1_AAAGCAAAGCAGCGTA-1 0.166749:0.168504:0.239303:... CD4+ T cells\nPBMMC-1_AAAGCAACAATAACGA-1 0.102549:0.103979:0.178762:... CD8+ T cells\nPBMMC-1_AAAGCAACATCAGTCA-1 0.181526:0.147693:0.115841:... Erythroid cells\n delta.next pruned.labels\n <numeric> <character>\nPBMMC-1_AAACCTGCAGACGCAA-1 0.1471065 B cells\nPBMMC-1_AAACCTGTCATCACCC-1 0.0753696 CD8+ T cells\nPBMMC-1_AAAGATGCATAAAGGT-1 0.1274524 Monocytes\nPBMMC-1_AAAGCAAAGCAGCGTA-1 0.0845267 CD4+ T cells\nPBMMC-1_AAAGCAACAATAACGA-1 0.0607683 CD8+ T cells\nPBMMC-1_AAAGCAACATCAGTCA-1 0.1057135 Erythroid cells\n\n\nVisualize singleR score quality scores:\n\nSingleR::plotScoreHeatmap(seu_SingleR)\n\n\n\n\n\nSingleR::plotDeltaDistribution(seu_SingleR)\n\nWarning: Groups with fewer than two data points have been dropped.\n\n\nWarning in max(data$density): no non-missing arguments to max; returning -Inf\n\n\nWarning: Computation failed in `stat_ydensity()`\nCaused by error in `$<-.data.frame`:\n! replacement has 1 row, data has 0\n\n\n\n\n\nThere are some annotations that contain only a few cells. They are usually not of interest, and they clogg our plots. Therefore we remove them from the annotation:\n\nsingleR_labels <- seu_SingleR$labels\nt <- table(singleR_labels)\nother <- names(t)[t < 10]\nsingleR_labels[singleR_labels %in% other] <- \"none\"\n\nIn order to visualize it in our UMAP, we have to add the annotation to [email protected]:\n\nseu$SingleR_annot <- singleR_labels\n\nWe can plot the annotations in the UMAP. Here, we use a different package for plotting (dittoSeq) as it has a bit better default coloring, and some other plotting functionality we will use later on.\n\ndittoSeq::dittoDimPlot(seu, \"SingleR_annot\", size = 0.7)\n\n\n\n\nWe can check out how many cells per sample we have for each annotated cell type:\n\ndittoSeq::dittoBarPlot(seu, var = \"SingleR_annot\", group.by = \"orig.ident\")\n\n\n\n\n\n\n\n\n\n\nExercise\n\n\n\nCompare our manual annotation (based on the set of T cell genes) to the annotation with SingleR. Do they correspond?\n\n\n\nYou can for example use the plotting function dittoBarPlot to visualize the cell types according to cluster (use RNA_snn_res.0.3 in stead of orig.ident))\n\n\n\n\n\n\n\nAnswer\n\n\n\n\n\nWe can have a look at the mean module score for each SingleR annotation like this:\n\ndittoSeq::dittoBarPlot(seu, \n var = \"SingleR_annot\", \n group.by = \"RNA_snn_res.0.3\")\n\n\n\n\nHere, you can see that cluster 0 and 8 contain cells annotated as T cells (CD4+ and CD8+).\n\n\n\nSave the dataset and clear environment\nNow, save the dataset so you can use it tomorrow:\n\nsaveRDS(seu, \"seu_day2-4.rds\")\n\nClear your environment:\n\nrm(list = ls())\ngc()\n.rs.restartR()" | ||
}, | ||
{ | ||
"objectID": "day2/day2-2_integration.html", | ||
"href": "day2/day2-2_integration.html", | ||
"title": "Integration", | ||
"section": "", | ||
"text": "Download the presentation" | ||
}, | ||
{ | ||
"objectID": "day2/day2-2_integration.html#material", | ||
"href": "day2/day2-2_integration.html#material", | ||
"title": "Integration", | ||
"section": "", | ||
"text": "Download the presentation" | ||
}, | ||
{ | ||
"objectID": "day2/day2-2_integration.html#exercises", | ||
"href": "day2/day2-2_integration.html#exercises", | ||
|