When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
library(Seurat)
Loading required package: SeuratObject
Loading required package: sp
Attaching package: ‘SeuratObject’
The following objects are masked from ‘package:base’:
intersect, t
library(SeuratData)
── Installed datasets ─────────────────────────────────────────────────────────────────────────────────── SeuratData v0.2.2.9001 ──
✔ ifnb 3.1.0
─────────────────────────────────────────────────────────────── Key ───────────────────────────────────────────────────────────────
✔ Dataset loaded successfully
❯ Dataset built with a newer version of Seurat than installed
❓ Unknown version of Seurat installed
library(ggplot2)
library(patchwork)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
SeuratData::InstallData("pbmc3k")
trying URL 'http://seurat.nygenome.org/src/contrib/pbmc3k.SeuratData_3.1.4.tar.gz'
Content type 'application/octet-stream' length 93780025 bytes (89.4 MB)
downloaded 89.4 MB
* installing *source* package 'pbmc3k.SeuratData' ...
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (pbmc3k.SeuratData)
The downloaded source packages are in
‘C:\Users\evrajadh\AppData\Local\Temp\1\Rtmp0KPR8d\downloaded_packages’
pbmc3k.final <- LoadData("pbmc3k", type = "pbmc3k.final")
Validating object structure
Updating object slots
Ensuring keys are in the proper structure
Updating matrix keys for DimReduc ‘pca’
Updating matrix keys for DimReduc ‘umap’
Warning: Assay RNA changing from Assay to Assay
Warning: Graph RNA_nn changing from Graph to Graph
Warning: Graph RNA_snn changing from Graph to Graph
Warning: DimReduc pca changing from DimReduc to DimReduc
Warning: DimReduc umap changing from DimReduc to DimReduc
Ensuring keys are in the proper structure
Ensuring feature names don't have underscores or pipes
Updating slots in RNA
Updating slots in RNA_nn
Setting default assay of RNA_nn to RNA
Updating slots in RNA_snn
Setting default assay of RNA_snn to RNA
Updating slots in pca
Updating slots in umap
Setting umap DimReduc to global
Setting assay used for NormalizeData.RNA to RNA
Setting assay used for FindVariableFeatures.RNA to RNA
Setting assay used for ScaleData.RNA to RNA
Setting assay used for RunPCA.RNA to RNA
Setting assay used for JackStraw.RNA.pca to RNA
No assay information could be found for ScoreJackStraw
Warning: Adding a command log without an assay associated with it
Setting assay used for FindNeighbors.RNA.pca to RNA
No assay information could be found for FindClusters
Warning: Adding a command log without an assay associated with it
Setting assay used for RunUMAP.RNA.pca to RNA
Validating object structure for Assay ‘RNA’
Validating object structure for Graph ‘RNA_nn’
Validating object structure for Graph ‘RNA_snn’
Validating object structure for DimReduc ‘pca’
Validating object structure for DimReduc ‘umap’
Object representation is consistent with the most current Seurat version
Warning: Assay RNA changing from Assay to Assay5
pbmc3k.final$groups <- sample(c("group1", "group2"), size = ncol(pbmc3k.final), replace = T)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
pbmc3k.final
An object of class Seurat
13714 features across 2638 samples within 1 assay
Active assay: RNA (13714 features, 2000 variable features)
3 layers present: data, counts, scale.data
2 dimensional reductions calculated: pca, umap
head(pbmc3k.final)
NA
RidgePlot(pbmc3k.final, features, ncol=2)
Picking joint bandwidth of 0.318
Picking joint bandwidth of 0.177
Picking joint bandwidth of 0.161
Picking joint bandwidth of 0.15
Picking joint bandwidth of 0.0894
Picking joint bandwidth of 0.0298
install.packages("svglite")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/svglite_2.1.3.zip'
Content type 'application/zip' length 685210 bytes (669 KB)
downloaded 669 KB
package ‘svglite’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\evrajadh\AppData\Local\Temp\1\Rtmp0KPR8d\downloaded_packages
library(svglite)
ggsave("ridge.svg", plot = last_plot())
Saving 7 x 7 in image
Picking joint bandwidth of 0.318
Picking joint bandwidth of 0.177
Picking joint bandwidth of 0.161
Picking joint bandwidth of 0.15
Picking joint bandwidth of 0.0894
Picking joint bandwidth of 0.0298
VlnPlot(pbmc3k.final, features)
NA
NA
FeaturePlot(pbmc3k.final, features)
DotPlot(pbmc3k.final, features) + RotatedAxis()
DoHeatmap(subset(pbmc3k.final, downsample=100), features, size=3, angle=0, hjust = 0.5)
#Adjust the contrast in the plot
FeaturePlot(pbmc3k.final, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)
#Calculate feature-specific contrast levels based on quantiles of non-zero expression (useful when plotting multiple markers)
FeaturePlot(pbmc3k.final, features = c("MS4A1", "PTPRCAP"), min.cutoff="q10", max.cutoff="q90")
FeaturePlot(pbmc3k.final, features, min.cutoff = "q50", max.cutoff = "q100")
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
Warning in SetQuantile(cutoff = max.cutoff[f], data = data.feature) :
NAs introduced by coercion
#Visualize co-expression of two features simultaneously
FeaturePlot(pbmc3k.final, features=c("MS4A1","CD79A"),blend = T, blend.threshold = 0.5)
#Split visualziation to view expression by groups (replace FeatureHeatmap)
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), split.by = "groups")
#Violin plots can also be split on some variable. Add splitting variable to object
#Metadata and pass it to the split.by argument
#Great way to show population differentiation!!!
VlnPlot(pbmc3k.final, features="CCL5", split.by = "groups", idents = "Platelet")
colors <- c("red", "blue", "green", "gray", "magenta", "turquoise", "pink", "aquamarine",
"red4")
#can also split.by in DotPlot
DotPlot(pbmc3k.final, features, split.by = "groups", ) + RotatedAxis()
pbmc3k.final.no.umap <- pbmc3k.final
pbmc3k.final.no.umap[["umap"]] <- NULL
DimPlot(pbmc3k.final.no.umap) + RotatedAxis()
DimPlot(pbmc3k.final)
DoHeatmap(pbmc3k.final, features = VariableFeatures(pbmc3k.final)[1:100], cells = 1:500, size=4, angle=90) + labs(title = "Heat Map of top 100 variable features")
#Adding features to blots
baseplot <- DimPlot(pbmc3k.final)
#Add custom labels and titles
baseplot + labs(title = "Clustering of 2,700 PBMCs")
remotes::install_github('sjessa/ggmin')
Downloading GitHub repo sjessa/ggmin@HEAD
── R CMD build ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ checking for file 'C:\Users\evrajadh\AppData\Local\Temp\1\Rtmp0KPR8d\remotes399849614ef\sjessa-ggmin-8ada274/DESCRIPTION' (792ms)
─ preparing 'ggmin':
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted 'LazyData' from DESCRIPTION
─ building 'ggmin_0.0.0.9000.tar.gz'
* installing *source* package 'ggmin' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggmin)
baseplot + ggmin::theme_powerpoint()
?SeuratTheme
baseplot + DarkTheme()
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()
#Include additional data to display alongside cell names by passing in a data frame of information
#works well when using fetchdata
plot <- FeaturePlot(pbmc3k.final, features="MS4A1")
HoverLocator(plot, information = FetchData(pbmc3k.final, vars = c("ident", "PC_1", "nFeatures_RNA")))
Warning: `error_y.color` does not currently support multiple values.
Warning: `error_x.color` does not currently support multiple values.
Warning: `line.color` does not currently support multiple values.
Warning: The titlefont attribute is deprecated. Use title = list(font = ...) instead.
Warning: `error_y.color` does not currently support multiple values.
Warning: `error_x.color` does not currently support multiple values.
Warning: `line.color` does not currently support multiple values.
Warning: The titlefont attribute is deprecated. Use title = list(font = ...) instead.
#can SELECT cells from DimPlot or FeaturePlot using CellSelector
#pbmc3k.final <- RenameIdents(pbmc3k.final, DC = "CD14+ Mono")
plot <- DimPlot(pbmc3k.final)
select.cells <- CellSelector(plot)
Listening on http://127.0.0.1:7576
head(select.cells)
[1] "AAGATTACCGCCTT" "AAGCCATGAACTGC" "AATTACGAATTCCT" "ACCCGTTGCTTCTA" "ACGAGGGACAGGAG" "ACGTGATGCCATGA"
Idents(pbmc3k.final, select.cells) <- "NewCells"
newcell.markers <- FindMarkers(pbmc3k.final, ident.1 = "NewCells", ident.2 = "CD14+ Mono", min.diff.pct = 0.3, only.pos=T)
| | 0 % ~calculating
|+ | 1 % ~02s
|++ | 2 % ~01s
|++ | 3 % ~01s
|+++ | 4 % ~00s
|+++ | 5 % ~01s
|++++ | 6 % ~00s
|++++ | 8 % ~00s
|+++++ | 9 % ~00s
|+++++ | 10% ~00s
|++++++ | 11% ~00s
|++++++ | 12% ~01s
|+++++++ | 13% ~00s
|+++++++ | 14% ~00s
|++++++++ | 15% ~00s
|+++++++++ | 16% ~00s
|+++++++++ | 17% ~00s
|++++++++++ | 18% ~00s
|++++++++++ | 19% ~00s
|+++++++++++ | 20% ~00s
|+++++++++++ | 22% ~00s
|++++++++++++ | 23% ~00s
|++++++++++++ | 24% ~00s
|+++++++++++++ | 25% ~00s
|+++++++++++++ | 26% ~00s
|++++++++++++++ | 27% ~00s
|++++++++++++++ | 28% ~00s
|+++++++++++++++ | 29% ~00s
|++++++++++++++++ | 30% ~00s
|++++++++++++++++ | 31% ~00s
|+++++++++++++++++ | 32% ~00s
|+++++++++++++++++ | 33% ~00s
|++++++++++++++++++ | 34% ~00s
|++++++++++++++++++ | 35% ~00s
|+++++++++++++++++++ | 37% ~00s
|+++++++++++++++++++ | 38% ~00s
|++++++++++++++++++++ | 39% ~00s
|++++++++++++++++++++ | 40% ~00s
|+++++++++++++++++++++ | 41% ~00s
|+++++++++++++++++++++ | 42% ~00s
|++++++++++++++++++++++ | 43% ~00s
|+++++++++++++++++++++++ | 44% ~00s
|+++++++++++++++++++++++ | 45% ~00s
|++++++++++++++++++++++++ | 46% ~00s
|++++++++++++++++++++++++ | 47% ~00s
|+++++++++++++++++++++++++ | 48% ~00s
|+++++++++++++++++++++++++ | 49% ~00s
|++++++++++++++++++++++++++ | 51% ~00s
|++++++++++++++++++++++++++ | 52% ~00s
|+++++++++++++++++++++++++++ | 53% ~00s
|+++++++++++++++++++++++++++ | 54% ~00s
|++++++++++++++++++++++++++++ | 55% ~00s
|++++++++++++++++++++++++++++ | 56% ~00s
|+++++++++++++++++++++++++++++ | 57% ~00s
|++++++++++++++++++++++++++++++ | 58% ~00s
|++++++++++++++++++++++++++++++ | 59% ~00s
|+++++++++++++++++++++++++++++++ | 60% ~00s
|+++++++++++++++++++++++++++++++ | 61% ~00s
|++++++++++++++++++++++++++++++++ | 62% ~00s
|++++++++++++++++++++++++++++++++ | 63% ~00s
|+++++++++++++++++++++++++++++++++ | 65% ~00s
|+++++++++++++++++++++++++++++++++ | 66% ~00s
|++++++++++++++++++++++++++++++++++ | 67% ~00s
|++++++++++++++++++++++++++++++++++ | 68% ~00s
|+++++++++++++++++++++++++++++++++++ | 69% ~00s
|+++++++++++++++++++++++++++++++++++ | 70% ~00s
|++++++++++++++++++++++++++++++++++++ | 71% ~00s
|+++++++++++++++++++++++++++++++++++++ | 72% ~00s
|+++++++++++++++++++++++++++++++++++++ | 73% ~00s
|++++++++++++++++++++++++++++++++++++++ | 74% ~00s
|++++++++++++++++++++++++++++++++++++++ | 75% ~00s
|+++++++++++++++++++++++++++++++++++++++ | 76% ~00s
|+++++++++++++++++++++++++++++++++++++++ | 77% ~00s
|++++++++++++++++++++++++++++++++++++++++ | 78% ~00s
|++++++++++++++++++++++++++++++++++++++++ | 80% ~00s
|+++++++++++++++++++++++++++++++++++++++++ | 81% ~00s
|+++++++++++++++++++++++++++++++++++++++++ | 82% ~00s
|++++++++++++++++++++++++++++++++++++++++++ | 83% ~00s
|++++++++++++++++++++++++++++++++++++++++++ | 84% ~00s
|+++++++++++++++++++++++++++++++++++++++++++ | 85% ~00s
|++++++++++++++++++++++++++++++++++++++++++++ | 86% ~00s
|++++++++++++++++++++++++++++++++++++++++++++ | 87% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++ | 88% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++ | 89% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++ | 90% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++ | 91% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 92% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 94% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 95% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 96% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 97% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 98% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 99% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s
head(newcell.markers)
pbmc3k.final <- CellSelector(plot, object = pbmc3k.final, ident = "selected")
Listening on http://127.0.0.1:7576
levels(pbmc3k.final)
[1] "selected" "CD14+ Mono" "Naive CD4 T" "Memory CD4 T" "B" "CD8 T" "FCGR3A+ Mono" "NK"
[9] "Platelet"
pbmc3k.subset <- CellSelector(plot, object = pbmc3k.final)
Listening on http://127.0.0.1:7576
plot <- DimPlot(pbmc3k.final, reduction = "pca") + NoLegend()
LabelClusters(plot, id="ident")
LabelPoints(plot = plot, points = TopCells(object = pbmc3k.final[["pca"]]), repel = TRUE)
When using repel, set xnudge and ynudge to 0 for optimal results
Warning: ggrepel: 19 unlabeled data points (too many overlaps). Consider increasing max.overlaps
plot1 <- DimPlot(pbmc3k.final)
#create scatter plot with the pearson correlation value as the title
plot2 <- FeatureScatter(pbmc3k.final, feature1 = "LYZ", feature2 = "CCL5")
plot1+plot2
#Remove the legend from all plots
plot1 + NoLegend() + plot2
install.packages('rsconnect')
Error in install.packages : Updating loaded packages
rsconnect::setAccountInfo(name='evanraj', token='CC71146761C229BBCA7B2EF7B80B4AB8', secret='98kxy5dxGc5Cb1q6LebrWHRKhllLcF26QIlYjwBV')