This is the R script used to reproduce Figure 6 of the MSC manuscript to analyze breast cancer scRNA-seq from Wu et al. 2021. The pre-processed data by Seurat workflow (integrated_data.seurat_wt_celltype.RDS), SNN-based results (SNN.clusters.RDS), MSC results (Flu.MSC_results.RDS) and codes for evaluation metric (evaluation_functions.R) can be downloaded from Synpase with DOI, https://doi.org/10.7303/syn52966803, under ‘Wu_et_al_2021’ folder. Placing these files under the working directory will run the codes below.
rm(list = ls())
library(Seurat)
## Loading required package: SeuratObject
## Loading required package: sp
##
## Attaching package: 'SeuratObject'
## The following objects are masked from 'package:base':
##
## intersect, t
library(Matrix.utils)
## Loading required package: Matrix
library(Matrix)
library(doParallel)
## Loading required package: foreach
## Loading required package: iterators
## Loading required package: parallel
library(igraph)
##
## Attaching package: 'igraph'
## The following object is masked from 'package:Seurat':
##
## components
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(ggraph)
## Loading required package: ggplot2
##
## Attaching package: 'ggraph'
## The following object is masked from 'package:sp':
##
## geometry
library(MSC)
library(cowplot)
root.dir = "/media/won-min/My Passport1/SingleCell/Cancer/Breast/Wu_et_al_2021"
setwd(root.dir)
# load functions
if (file.exists("evaluation_functions.R")) source("evaluation_functions.R")
if (file.exists("enrichment_functions.v3.R")) source("enrichment_functions.v3.R")
seu = readRDS(file = "Breast_Wu.NG.2021.Singlet.RPCA_CCA_updated_wt_SCT.rds")
## Loading required package: RColorBrewer
## Loading required package: grid
## Warning: ggrepel: 12 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
##
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
##
## align_plots
## Loading required package: reshape
##
## Attaching package: 'reshape'
## The following object is masked from 'package:cowplot':
##
## stamp
## The following object is masked from 'package:Matrix':
##
## expand
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.4' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=0.8' in 'mbcsToSbcs': dot substituted for <b3>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <ce>
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## conversion failure on 'SNN γ=1.2' in 'mbcsToSbcs': dot substituted for <b3>
## Section 4. Pie chart visualization of MSC
clusters
## Loading required package: reshape2
##
## Attaching package: 'reshape2'
## The following objects are masked from 'package:reshape':
##
## colsplit, melt, recast
## $M227
##
## T_cells_c0_CD4+_CCR7 T_cells_c1_CD4+_IL7R
## 320 447
## T_cells_c2_CD4+_T-regs_FOXP3 T_cells_c3_CD4+_Tfh_CXCL13
## 2 3
## T_cells_c4_CD8+_ZFP36 T_cells_c5_CD8+_GZMK
## 12 3
## T_cells_c6_IFIT1 T_cells_c9_NK_cells_AREG
## 39 1
##
## $M180
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 20 25 159 341
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 111 1 61
##
## $M226
##
## Cancer Basal SC T_cells_c0_CD4+_CCR7
## 1 133
## T_cells_c1_CD4+_IL7R T_cells_c11_MKI67
## 346 2
## T_cells_c2_CD4+_T-regs_FOXP3 T_cells_c3_CD4+_Tfh_CXCL13
## 32 65
## T_cells_c4_CD8+_ZFP36 T_cells_c5_CD8+_GZMK
## 10 2
## T_cells_c6_IFIT1 T_cells_c7_CD8+_IFNG
## 30 5
## T_cells_c8_CD8+_LAG3
## 2
##
## $M235
##
## B cells Memory CAFs MSC iCAF-like s2
## 1 1
## Cancer Basal SC Cancer Cycling
## 126 40
## Cancer Her2 SC Cancer LumA SC
## 86 168
## Cancer LumB SC Endothelial Lymphatic LYVE1
## 134 1
## Luminal Progenitors Mature Luminal
## 13 7
## Myoepithelial PVL Differentiated s3
## 1 3
##
## $M237
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 57 22 84 224
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 162 16 8
##
## $M234
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 195 89 118 47
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 43 4 9
##
## $M196
##
## T_cells_c0_CD4+_CCR7 T_cells_c1_CD4+_IL7R
## 2 29
## T_cells_c10_NKT_cells_FCGR3A T_cells_c11_MKI67
## 22 24
## T_cells_c3_CD4+_Tfh_CXCL13 T_cells_c4_CD8+_ZFP36
## 1 93
## T_cells_c5_CD8+_GZMK T_cells_c6_IFIT1
## 9 18
## T_cells_c7_CD8+_IFNG T_cells_c8_CD8+_LAG3
## 242 56
## T_cells_c9_NK_cells_AREG
## 3
##
## $M240
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 12 19 83 216
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 41 1 42
##
## $M181
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 40 26 78 186
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 70 1 12
##
## $M103
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 121 140 44 17
## Cancer LumB SC Luminal Progenitors Mature Luminal
## 13 10 5
##
## $M203
##
## Endothelial ACKR1
## 323
##
## $M144
##
## CAFs MSC iCAF-like s2 Cancer Basal SC Cancer LumA SC
## 1 2 1
## Cycling PVL PVL Differentiated s3 PVL Immature s1
## 2 274 3
## PVL_Immature s2
## 1
##
## $M121
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 209 13 9
## CAFs myCAF like s5 CAFs Transitioning s3
## 3 23
##
## $M145
##
## Cycling PVL PVL Differentiated s3 PVL Immature s1
## 2 243 9
## PVL_Immature s2
## 3
##
## $M102
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 2 4 22
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 4 1 88
## Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 40 25 6
## Cancer LumB SC Cycling PVL Luminal Progenitors
## 2 1 4
## Mature Luminal Myoepithelial PVL Differentiated s3
## 2 41 10
## PVL Immature s1 PVL_Immature s2
## 2 2
##
## $M146
##
## CAFs MSC iCAF-like s2 Cancer Basal SC Cycling PVL
## 2 2 1
## PVL Differentiated s3
## 248
##
## $M188
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 5 9 25
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 185 13 13
## Cancer Cycling
## 1
##
## $M133
##
## Cancer LumB SC Endothelial ACKR1
## 1 87
## Endothelial CXCL12 Endothelial Lymphatic LYVE1
## 75 3
## Endothelial RGS5
## 79
##
## $M244
##
## B cells Memory Myeloid_c1_LAM1_FABP5
## 2 58
## Myeloid_c10_Macrophage_1_EGR1 Myeloid_c12_Monocyte_1_IL1B
## 140 37
## Myeloid_c2_LAM2_APOE Myeloid_c9_Macrophage_2_CXCL10
## 2 3
##
## $M119
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 2 14 64
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 55 4 69
## Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 21 1 1
## PVL Differentiated s3 PVL Immature s1
## 2 2
##
## $M212
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 1 24 39
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 5 1 12
## Cancer Cycling Cycling PVL PVL Differentiated s3
## 3 1 7
## PVL Immature s1 PVL_Immature s2
## 70 72
##
## $M108
##
## Cancer Cycling T_cells_c11_MKI67 T_cells_c8_CD8+_LAG3
## 189 29 1
##
## $M252
##
## B cells Memory Myeloid_c1_LAM1_FABP5
## 1 88
## Myeloid_c10_Macrophage_1_EGR1 Myeloid_c12_Monocyte_1_IL1B
## 98 12
## Myeloid_c2_LAM2_APOE Myeloid_c9_Macrophage_2_CXCL10
## 6 2
##
## $M222
##
## Cycling_Myeloid Myeloid_c0_DC_LAMP3
## 2 2
## Myeloid_c1_LAM1_FABP5 Myeloid_c10_Macrophage_1_EGR1
## 47 45
## Myeloid_c11_cDC2_CD1C Myeloid_c12_Monocyte_1_IL1B
## 1 56
## Myeloid_c2_LAM2_APOE Myeloid_c9_Macrophage_2_CXCL10
## 8 42
##
## $M241
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC Cancer LumB SC
## 8 4 28 81 62
## Mature Luminal
## 15
##
## $M142
##
## PVL Differentiated s3
## 194
##
## $M138
##
## Endothelial ACKR1 Endothelial CXCL12 Endothelial RGS5
## 77 72 38
##
## $M192
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 10 2 1
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 131 38 3
##
## $M246
##
## Cycling_Myeloid Myeloid_c1_LAM1_FABP5
## 24 37
## Myeloid_c10_Macrophage_1_EGR1 Myeloid_c11_cDC2_CD1C
## 19 2
## Myeloid_c12_Monocyte_1_IL1B Myeloid_c2_LAM2_APOE
## 39 50
## Myeloid_c3_cDC1_CLEC9A Myeloid_c4_DCs_pDC_IRF7
## 1 1
## Myeloid_c9_Macrophage_2_CXCL10
## 11
##
## $M214
##
## CAFs MSC iCAF-like s2 Cancer Basal SC Cycling PVL
## 1 2 1
## PVL Differentiated s3
## 176
##
## $M190
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 7 18 40
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 73 27 10
## Cancer LumB SC
## 1
##
## $M230
##
## T_cells_c1_CD4+_IL7R T_cells_c11_MKI67
## 2 19
## T_cells_c3_CD4+_Tfh_CXCL13 T_cells_c8_CD8+_LAG3
## 144 3
##
## $M191
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 59 2 3
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 32 55 1
##
## $M150
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 54 71 3 1
## Luminal Progenitors Mature Luminal Myoepithelial
## 4 1 17
##
## $M187
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 38 14 23
## CAFs myCAF like s5 CAFs Transitioning s3
## 45 31
##
## $M162
##
## B cells Memory Cycling_Myeloid
## 2 3
## Myeloid_c1_LAM1_FABP5 Myeloid_c10_Macrophage_1_EGR1
## 25 8
## Myeloid_c11_cDC2_CD1C Myeloid_c12_Monocyte_1_IL1B
## 7 58
## Myeloid_c2_LAM2_APOE Myeloid_c7_Monocyte_3_FCGR3A
## 16 1
## Myeloid_c8_Monocyte_2_S100A9 Myeloid_c9_Macrophage_2_CXCL10
## 29 1
##
## $M143
##
## CAFs MSC iCAF-like s2 Cancer Basal SC Cancer Her2 SC
## 1 1 1
## PVL Differentiated s3 PVL Immature s1 PVL_Immature s2
## 126 11 3
##
## $M233
##
## T_cells_c11_MKI67 T_cells_c3_CD4+_Tfh_CXCL13
## 1 140
## T_cells_c8_CD8+_LAG3
## 1
##
## $M111
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC
## 1 128 2 2
## Cycling_Myeloid T_cells_c11_MKI67
## 1 5
##
## $M152
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumB SC Myoepithelial
## 87 37 1 1 11
##
## $M149
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Myoepithelial
## 84 34 1 14
##
## $M243
##
## CAFs MSC iCAF-like s2 CAFs myCAF like s4 CAFs myCAF like s5
## 6 12 97
## CAFs Transitioning s3 Cancer Basal SC Cancer Cycling
## 3 11 1
##
## $M189
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 11 6 30
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 58 15 6
##
## $M242
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 5 3 13
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 88 10 2
##
## $M251
##
## Myeloid_c1_LAM1_FABP5 Myeloid_c10_Macrophage_1_EGR1
## 25 54
## Myeloid_c12_Monocyte_1_IL1B Myeloid_c2_LAM2_APOE
## 7 20
## Myeloid_c9_Macrophage_2_CXCL10
## 12
##
## $M231
##
## T_cells_c11_MKI67 T_cells_c2_CD4+_T-regs_FOXP3
## 3 36
## T_cells_c3_CD4+_Tfh_CXCL13
## 74
##
## $M253
##
## Cycling_Myeloid Myeloid_c1_LAM1_FABP5
## 1 39
## Myeloid_c10_Macrophage_1_EGR1 Myeloid_c12_Monocyte_1_IL1B
## 55 6
## Myeloid_c2_LAM2_APOE Myeloid_c9_Macrophage_2_CXCL10
## 2 6
##
## $M239
##
## Cancer Cycling Cancer Her2 SC Cancer LumA SC Cancer LumB SC Mature Luminal
## 2 48 44 8 4
##
## $M153
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Myoepithelial
## 77 16 1 6
##
## $M201
##
## Cancer Her2 SC T_cells_c1_CD4+_IL7R
## 1 1
## T_cells_c10_NKT_cells_FCGR3A T_cells_c4_CD8+_ZFP36
## 48 1
## T_cells_c7_CD8+_IFNG T_cells_c9_NK_cells_AREG
## 2 44
##
## $M98
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC Cancer LumB SC
## 32 7 16 9 24
##
## $M249
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 4 3 9
## CAFs myCAF like s5 CAFs Transitioning s3 Cancer Basal SC
## 56 10 2
##
## $M77
##
## Cancer Cycling
## 81
##
## $M157
##
## Myoepithelial
## 78
##
## $M213
##
## CAFs MSC iCAF-like s2 PVL Differentiated s3
## 1 72
##
## $M206
##
## Endothelial CXCL12 Endothelial RGS5
## 67 1
##
## $M96
##
## Plasmablasts
## 63
##
## $M175
##
## Cancer Basal SC Cancer Cycling Cancer Her2 SC Cancer LumA SC Plasmablasts
## 42 16 1 1 1
##
## $M186
##
## CAFs MSC iCAF-like s1 CAFs MSC iCAF-like s2 CAFs myCAF like s4
## 10 9 6
## CAFs myCAF like s5 CAFs Transitioning s3
## 18 12
##
## $M151
##
## Cancer Basal SC Cancer Cycling Luminal Progenitors Myoepithelial
## 27 21 3 3
##
## $M198
##
## Cancer Cycling T_cells_c1_CD4+_IL7R T_cells_c11_MKI67
## 1 1 42
## T_cells_c4_CD8+_ZFP36 T_cells_c9_NK_cells_AREG
## 1 8
## Warning: `graph.data.frame()` was deprecated in igraph 2.0.0.
## ℹ Please use `graph_from_data_frame()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
##
## Attaching package: 'scatterpie'
## The following object is masked from 'package:sp':
##
## recenter
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: ggrepel: 22 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## [Section 5. Visualize M138, a endothelial subset uniquely identified
by MSC]
## Minimum UMI unchanged. Skipping re-correction.
## Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
## To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
## This message will be shown once per session
## 23:04:04 UMAP embedding parameters a = 0.9922 b = 1.112
## 23:04:04 Read 6360 rows and found 8 numeric columns
## 23:04:04 Using Annoy for neighbor search, n_neighbors = 30
## 23:04:04 Building Annoy index with metric = cosine, n_trees = 50
## 0% 10 20 30 40 50 60 70 80 90 100%
## [----|----|----|----|----|----|----|----|----|----|
## **************************************************|
## 23:04:04 Writing NN index file to temp file /tmp/RtmpmNCmpJ/file323ee7e850
## 23:04:04 Searching Annoy index using 1 thread, search_k = 3000
## 23:04:06 Annoy recall = 100%
## 23:04:06 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30
## 23:04:07 Initializing from normalized Laplacian + noise (using RSpectra)
## 23:04:07 Commencing optimization for 500 epochs, with 267976 positive edges
## 23:04:12 Optimization finished
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.Scale for size is already present.
## Adding another scale for size, which will replace the existing scale.