Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
custom
Squadrito_LiverTumor2022
Squadrito_LiverTumor2022_scRNAseqTRC
Commits
2fd8c621
Commit
2fd8c621
authored
Jul 26, 2023
by
Stefano Beretta
Browse files
Upload New File
parent
185b7a65
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/2_SubsetAnalysis_Annoations.R
0 → 100644
View file @
2fd8c621
library
(
Rcpp
)
library
(
SeuratObject
)
library
(
Seurat
)
library
(
harmony
)
library
(
ggplot2
)
library
(
patchwork
)
library
(
RColorBrewer
)
library
(
DoubletFinder
)
library
(
grid
)
library
(
cowplot
)
library
(
gridExtra
)
library
(
openxlsx
)
library
(
dplyr
)
########################
### General Settings ###
########################
# Working dir
wdir
<-
"squadrito_livertumor2022_scrnaseq"
# Raw data dir (download from GEO)
raw_dir
<-
"GEO_data"
# Results dir
out_dir
<-
paste
(
wdir
,
"results"
,
sep
=
"/"
)
dir.create
(
path
=
out_dir
,
showWarnings
=
F
)
################################
###Processing and annotattion###
################################
# Load Full object
Full_obj
<-
readRDS
(
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_final_DBR_labeled.rds"
,
sep
=
"/"
))
reg_vars
<-
c
(
"CC.Difference"
,
"percent.mt"
,
"nCount_RNA"
)
# Assign group
Full_obj
@
meta.data
$
RNA_Group
<-
"Undefined"
Full_obj
@
meta.data
$
RNA_Group
[
Full_obj
@
meta.data
$
orig.ident
==
"GG-11"
]
<-
"Control"
Full_obj
@
meta.data
$
RNA_Group
[
Full_obj
@
meta.data
$
orig.ident
==
"GG-18"
]
<-
"IFNa"
Full_obj
@
meta.data
$
RNA_Group
[
Full_obj
@
meta.data
$
orig.ident
==
"GG-22"
]
<-
"IFNa+aCTLA4"
Full_obj
@
meta.data
$
RNA_Group
[
Full_obj
@
meta.data
$
orig.ident
==
"GG-23"
]
<-
"IFNa"
Full_obj
@
meta.data
$
RNA_Group
[
Full_obj
@
meta.data
$
orig.ident
==
"GG-25"
]
<-
"Control"
# Annotation Newlabels in Full_obj based on computed markers
Full_obj
@
meta.data
$
CellID
<-
Full_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
Full_obj
@
meta.data
$
Newlabels
<-
rep
(
"Undefined"
,
length
(
Full_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"0"
]
<-
"B cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"1"
]
<-
"B cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"2"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"3"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"4"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"5"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"6"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"7"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"8"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"9"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"10"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"11"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"12"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"13"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"14"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"15"
]
<-
"B cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"16"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"17"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"18"
]
<-
"Cancer cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"19"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"20"
]
<-
"Neutrophils"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"21"
]
<-
"T and NK cells"
# !!!
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"22"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"23"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"24"
]
<-
"B1a-like"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"25"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"26"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"27"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"28"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"29"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"30"
]
<-
"APCs"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"31"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"32"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"33"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"34"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"35"
]
<-
"Cancer cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"36"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"37"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"38"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"39"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"40"
]
<-
"T and NK cells"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"41"
]
<-
"Undefined"
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
SCT_snn_res.1.2
==
"42"
]
<-
"T and NK cells"
# Split cluster 21 into "T and NK cells" and "APCs"
# Subset cluster 21 (res.1.2) which is split between APCs and T and NK cells
Full_obj
<-
SetIdent
(
object
=
Full_obj
,
value
=
"SCT_snn_res.1.2"
)
sub_obj
<-
subset
(
Full_obj
,
idents
=
c
(
"21"
))
# Process sub_obj of cluster 21
sub_obj
@
meta.data
$
CellID
<-
sub_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
DefaultAssay
(
object
=
sub_obj
)
<-
"RNA"
sub_obj
<-
NormalizeData
(
object
=
sub_obj
)
sub_obj
<-
SCTransform
(
sub_obj
,
vars.to.regress
=
reg_vars
,
verbose
=
TRUE
)
DefaultAssay
(
object
=
sub_obj
)
<-
"SCT"
sub_obj
@
misc
$
analysis_params
$
max_pca
<-
50
sub_obj
<-
RunPCA
(
object
=
sub_obj
,
npcs
=
sub_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
sub_obj
,
ndims
=
TNK_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
sub_obj
@
misc
$
analysis_params
$
num_pc
<-
25
sub_obj
<-
RunUMAP
(
sub_obj
,
dims
=
1
:
sub_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
sub_obj
<-
FindNeighbors
(
sub_obj
,
reduction
=
"pca"
,
dims
=
1
:
sub_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
sub_obj
<-
FindClusters
(
sub_obj
,
resolution
=
1.2
)
#relable clusers identified in sub_obj
FeaturePlot
(
sub_obj
,
reduction
=
"umap"
,
features
=
c
(
"Cd3e"
,
"Itgam"
),
pt.size
=
2
)
sub_obj
@
meta.data
$
CellID
<-
sub_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
sub_obj
@
meta.data
$
sublabels
<-
rep
(
"Undefined"
,
length
(
sub_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
sub_obj
@
meta.data
$
sublabels
[
sub_obj
@
meta.data
$
SCT_snn_res.1.2
==
"0"
]
<-
"T and NK cells"
sub_obj
@
meta.data
$
sublabels
[
sub_obj
@
meta.data
$
SCT_snn_res.1.2
==
"1"
]
<-
"T and NK cells"
sub_obj
@
meta.data
$
sublabels
[
sub_obj
@
meta.data
$
SCT_snn_res.1.2
==
"2"
]
<-
"APCs"
sub_obj
@
meta.data
$
sublabels
[
sub_obj
@
meta.data
$
SCT_snn_res.1.2
==
"3"
]
<-
"APCs"
#extract labels from sub_obj
labels_subobj
<-
data.frame
(
ToSelect
=
sub_obj
@
meta.data
$
CellID
,
Classification
=
sub_obj
@
meta.data
$
sublabels
)
#reintegrate sub_obj labels into full_object
alllabels
<-
labels_subobj
orderDF
<-
data.frame
(
allIDs
=
Full_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
Full_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
Full_obj
@
meta.data
$
Newlabels
[
Full_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
# Save final object
saveRDS
(
object
=
Full_obj
,
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_final_DBR_labeled.rds"
,
sep
=
"/"
))
#############################
# subcluster T and NK cells #
#############################
# Subset T and NK cells
Full_obj
<-
SetIdent
(
object
=
Full_obj
,
value
=
"Newlabels"
)
TNK_obj
<-
subset
(
Full_obj
,
idents
=
c
(
"T and NK cells"
))
# Processing of the subset T cells, (Normalization, SCTransform, PCA and UMAP)
TNK_obj
@
meta.data
$
CellID
<-
TNK_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
DefaultAssay
(
object
=
TNK_obj
)
<-
"RNA"
TNK_obj
<-
NormalizeData
(
object
=
TNK_obj
)
TNK_obj
<-
SCTransform
(
TNK_obj
,
vars.to.regress
=
reg_vars
,
verbose
=
TRUE
)
DefaultAssay
(
object
=
TNK_obj
)
<-
"SCT"
TNK_obj
@
misc
$
analysis_params
$
max_pca
<-
50
TNK_obj
<-
RunPCA
(
object
=
TNK_obj
,
npcs
=
TNK_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
TNK_obj
,
ndims
=
TNK_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
TNK_obj
@
misc
$
analysis_params
$
num_pc
<-
40
TNK_obj
<-
RunUMAP
(
TNK_obj
,
dims
=
1
:
TNK_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
TNK_obj
<-
FindNeighbors
(
TNK_obj
,
reduction
=
"pca"
,
dims
=
1
:
TNK_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
TNK_obj
<-
FindClusters
(
TNK_obj
,
resolution
=
1.2
)
# Annotate Newlabels_rough into TNK_obj
TNK_obj
@
meta.data
$
Newlabels_rough
<-
rep
(
"Undefined"
,
length
(
TNK_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"0"
]
<-
"NK"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"1"
]
<-
"NKT"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"2"
]
<-
"CD4 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"3"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"4"
]
<-
"CD4 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"5"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"6"
]
<-
"CD4 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"7"
]
<-
"CD4 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"8"
]
<-
"ILCs"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"9"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"10"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"11"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"12"
]
<-
"CD8 T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"13"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"14"
]
<-
"T prol"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"15"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"16"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"17"
]
<-
"gd T cells"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"18"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"19"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"20"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"21"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"22"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"23"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"24"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"25"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"26"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"27"
]
<-
"Undefined"
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
SCT_snn_res.1.2
==
"28"
]
<-
"Undefined"
# Detailed annotation NKT cells
# Subset NK and NKT cells to TNKonly_obj
TNK_obj
<-
SetIdent
(
object
=
TNK_obj
,
value
=
"Newlabels_rough"
)
TNKonly_obj
<-
subset
(
TNK_obj
,
idents
=
c
(
"NKT"
))
# Process TNKonly_obj
DefaultAssay
(
object
=
TNKonly_obj
)
<-
"SCT"
TNKonly_obj
@
misc
$
analysis_params
$
max_pca
<-
50
TNKonly_obj
<-
RunPCA
(
object
=
TNKonly_obj
,
npcs
=
TNKonly_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
TNKonly_obj
,
ndims
=
TNKonly_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
TNKonly_obj
@
misc
$
analysis_params
$
num_pc
<-
30
TNKonly_obj
<-
RunUMAP
(
TNKonly_obj
,
dims
=
1
:
TNKonly_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
TNKonly_obj
<-
FindNeighbors
(
TNKonly_obj
,
reduction
=
"pca"
,
dims
=
1
:
TNKonly_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
TNKonly_obj
<-
FindClusters
(
TNKonly_obj
,
resolution
=
1.4
)
# Detailed annotation Newlabels_detailed of TNKonly_obj
TNKonly_obj
@
meta.data
$
Newlabels_detailed
<-
rep
(
"Undefined"
,
length
(
TNKonly_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"0"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"1"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"2"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"3"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"4"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"5"
]
<-
"gd NKT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"6"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"7"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"8"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"9"
]
<-
"MAIT"
TNKonly_obj
@
meta.data
$
Newlabels_detailed
[
TNKonly_obj
@
meta.data
$
SCT_snn_res.1.4
==
"10"
]
<-
"MAIT"
# Extract labels from NKT cells
labels_NKT
<-
data.frame
(
ToSelect
=
TNKonly_obj
@
meta.data
$
CellID
,
Classification
=
TNKonly_obj
@
meta.data
$
Newlabels_detailed
)
# Integrate Newlabels_detailed annotation from TNKonly_obj into TNK_obj
TNK_obj
@
meta.data
$
Newlabels_detailed
<-
TNK_obj
@
meta.data
$
Newlabels_rough
alllabels
<-
labels_NKT
TNK_obj
@
meta.data
$
Newlabels_detailed
<-
TNK_obj
@
meta.data
$
Newlabels_rough
orderDF
<-
data.frame
(
allIDs
=
TNK_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
TNK_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
TNK_obj
@
meta.data
$
Newlabels_detailed
[
TNK_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
## Detailed annotation CD4 T cells ##
# Generate CD4 T cell subset
TNK_obj
<-
SetIdent
(
object
=
TNK_obj
,
value
=
"Newlabels_rough"
)
CD4_obj
<-
subset
(
TNK_obj
,
idents
=
c
(
"CD4 T cells"
))
# Process CD4_obj
DefaultAssay
(
object
=
CD4_obj
)
<-
"SCT"
CD4_obj
@
misc
$
analysis_params
$
max_pca
<-
50
CD4_obj
<-
RunPCA
(
object
=
CD4_obj
,
npcs
=
CD4_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
CD4_obj
,
ndims
=
CD4_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
CD4_obj
@
misc
$
analysis_params
$
num_pc
<-
35
CD4_obj
<-
RunUMAP
(
CD4_obj
,
dims
=
1
:
CD4_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
CD4_obj
<-
FindNeighbors
(
CD4_obj
,
reduction
=
"pca"
,
dims
=
1
:
CD4_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
CD4_obj
<-
FindClusters
(
CD4_obj
,
resolution
=
0.5
)
# Detailed annotation Newlabels_detailed of CD4_obj
CD4_obj
@
meta.data
$
Newlabels_detailed
<-
rep
(
"Undefined"
,
length
(
CD8_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
CD4_obj
@
meta.data
$
Newlabels_detailed
[
CD4_obj
@
meta.data
$
SCT_snn_res.0.5
==
"0"
]
<-
"CD4 Treg cells"
CD4_obj
@
meta.data
$
Newlabels_detailed
[
CD4_obj
@
meta.data
$
SCT_snn_res.0.5
==
"1"
]
<-
"CD4 Teff cells"
CD4_obj
@
meta.data
$
Newlabels_detailed
[
CD4_obj
@
meta.data
$
SCT_snn_res.0.5
==
"2"
]
<-
"CD4 Tex cells"
CD4_obj
@
meta.data
$
Newlabels_detailed
[
CD4_obj
@
meta.data
$
SCT_snn_res.0.5
==
"3"
]
<-
"CD4 Tsm-like cells"
CD4_obj
@
meta.data
$
Newlabels_detailed
[
CD4_obj
@
meta.data
$
SCT_snn_res.0.5
==
"4"
]
<-
"CD8 T cells"
# Extract labels from CD4 T cells
labels_CD4
<-
data.frame
(
ToSelect
=
CD4_obj
@
meta.data
$
CellID
,
Classification
=
CD4_obj
@
meta.data
$
Newlabels_detailed
)
# Integrate Newlabels_detailed annotation from CD4_obj into TNK_obj
alllabels
<-
labels_CD4
orderDF
<-
data.frame
(
allIDs
=
TNK_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
TNK_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
TNK_obj
@
meta.data
$
Newlabels_detailed
[
TNK_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
# Annotate newly identified CD8 T cells in CD4_obj as CD8 T cells in Newlabels_rough slot in TNK_obj
TNK_obj
@
meta.data
$
Newlabels_rough
[
TNK_obj
@
meta.data
$
Newlabels_detailed
==
"CD8 T cells"
]
<-
"CD8 T cells"
## Detailed annotation CD8 T cells ##
# Generate CD8 T cell subset
TNK_obj
<-
SetIdent
(
object
=
TNK_obj
,
value
=
"Newlabels_rough"
)
CD8_obj
<-
subset
(
TNK_obj
,
idents
=
c
(
"CD8 T cells"
))
# Process CD8_obj
DefaultAssay
(
object
=
CD8_obj
)
<-
"SCT"
CD8_obj
@
misc
$
analysis_params
$
max_pca
<-
50
CD8_obj
<-
RunPCA
(
object
=
CD8_obj
,
npcs
=
CD8_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
CD8_obj
,
ndims
=
CD8_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
CD8_obj
@
misc
$
analysis_params
$
num_pc
<-
35
CD8_obj
<-
RunUMAP
(
CD8_obj
,
dims
=
1
:
CD8_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
CD8_obj
<-
FindNeighbors
(
CD8_obj
,
reduction
=
"pca"
,
dims
=
1
:
CD8_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
CD8_obj
<-
FindClusters
(
CD8_obj
,
resolution
=
0.9
)
# Detailed annotation Newlabels_detailed of CD8_obj
CD8_obj
@
meta.data
$
Newlabels_detailed
<-
rep
(
"Undefined"
,
length
(
CD8_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"0"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"1"
]
<-
"CD8 Tm cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"2"
]
<-
"CD8 Tsm-like cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"3"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"4"
]
<-
"CD8 Tsm-like cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"5"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"6"
]
<-
"Undefined"
#CD8a low
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"7"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"8"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"9"
]
<-
"CD8 Teff_ex cells"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"10"
]
<-
"Undefined"
CD8_obj
@
meta.data
$
Newlabels_detailed
[
CD8_obj
@
meta.data
$
SCT_snn_res.0.9
==
"11"
]
<-
"Undefined"
# Extract labels from CD8 T cells
labels_CD8
<-
data.frame
(
ToSelect
=
CD8_obj
@
meta.data
$
CellID
,
Classification
=
CD8_obj
@
meta.data
$
Newlabels_detailed
)
# Integrate Newlabels_detailed annotation from CD8_obj into TNK_obj
alllabels
<-
labels_CD8
orderDF
<-
data.frame
(
allIDs
=
TNK_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
TNK_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
TNK_obj
@
meta.data
$
Newlabels_detailed
[
TNK_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
## Remove undefined cells
TNK_obj
<-
SetIdent
(
object
=
TNK_obj
,
value
=
"Newlabels_detailed"
)
TNK_obj
<-
subset
(
TNK_obj
,
idents
=
c
(
"Undefined"
),
invert
=
T
)
# Add analysis of clonotype -> cathegorize T cells into expansion levels
a1
<-
25
a2
<-
15
a3
<-
5
a4
<-
1
TNK_obj
@
meta.data
$
cloneType
<-
"NA"
TNK_obj
@
meta.data
$
cloneType
[
TNK_obj
@
meta.data
$
ClonoFreq2
>
a1
]
<-
paste0
(
"Hyperexpanded (x>"
,
a1
,
")"
)
TNK_obj
@
meta.data
$
cloneType
[
TNK_obj
@
meta.data
$
ClonoFreq2
>
a2
&
TNK_obj
@
meta.data
$
ClonoFreq2
<=
a1
]
<-
paste0
(
"Large ("
,
a2
,
"< x <="
,
a1
,
")"
)
TNK_obj
@
meta.data
$
cloneType
[
TNK_obj
@
meta.data
$
ClonoFreq2
>
a3
&
TNK_obj
@
meta.data
$
ClonoFreq2
<=
a2
]
<-
paste0
(
"Medium ("
,
a3
,
"< x <="
,
a2
,
")"
)
TNK_obj
@
meta.data
$
cloneType
[
TNK_obj
@
meta.data
$
ClonoFreq2
>
a4
&
TNK_obj
@
meta.data
$
ClonoFreq2
<=
a3
]
<-
paste0
(
"Small("
,
a4
,
"< x <="
,
a3
,
")"
)
TNK_obj
@
meta.data
$
cloneType
[
TNK_obj
@
meta.data
$
ClonoFreq2
==
a4
]
<-
paste0
(
"Unique(x="
,
a4
,
")"
)
# Save TNK_obj
dir.create
(
paste
(
out_dir
,
"TNK"
,
sep
=
"/"
))
saveRDS
(
TNK_obj
,
file
=
paste
(
out_dir
,
"TNK"
,
"TNK_DBR_final.rds"
,
sep
=
"/"
))
#####################
## Subcluster APCs ##
#####################
Full_obj
<-
SetIdent
(
object
=
Full_obj
,
value
=
"Newlabels"
)
APC_obj
<-
subset
(
Full_obj
,
idents
=
c
(
"APCs"
))
# Processing of the APC_obj, (Normalization, SCTransform, PCA and UMAP)
APC_obj
@
meta.data
$
CellID
<-
APC_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
DefaultAssay
(
object
=
APC_obj
)
<-
"RNA"
APC_obj
<-
NormalizeData
(
object
=
APC_obj
)
APC_obj
<-
SCTransform
(
APC_obj
,
vars.to.regress
=
reg_vars
,
verbose
=
TRUE
)
DefaultAssay
(
object
=
APC_obj
)
<-
"SCT"
APC_obj
@
misc
$
analysis_params
$
max_pca
<-
50
APC_obj
<-
RunPCA
(
object
=
APC_obj
,
npcs
=
APC_obj
@
misc
$
analysis_params
$
max_pca
)
ElbowPlot
(
APC_obj
,
ndims
=
APC_obj
@
misc
$
analysis_params
$
max_pca
,
reduction
=
"pca"
)
APC_obj
@
misc
$
analysis_params
$
num_pc
<-
35
APC_obj
<-
RunUMAP
(
APC_obj
,
dims
=
1
:
APC_obj
@
misc
$
analysis_params
$
num_pc
,
seed.use
=
1
,
reduction
=
"pca"
)
APC_obj
<-
FindNeighbors
(
APC_obj
,
reduction
=
"pca"
,
dims
=
1
:
APC_obj
@
misc
$
analysis_params
$
num_pc
,
force.recalc
=
T
)
APC_obj
<-
FindClusters
(
APC_obj
,
resolution
=
1.2
)
# Annotate Newlabels_rough on macrophages
APC_obj
@
meta.data
$
Newlabels_rough
<-
rep
(
"Undefined"
,
length
(
APC_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
APC_obj
@
meta.data
$
CellID
<-
APC_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"0"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"1"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"2"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"3"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"4"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"5"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"6"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"7"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"8"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"9"
]
<-
"DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"10"
]
<-
"DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"11"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"12"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"13"
]
<-
"DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"14"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"15"
]
<-
"DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"16"
]
<-
"Monocyte & Macrophages"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"17"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"18"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"19"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"20"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"21"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_rough
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"22"
]
<-
"Undefined"
# Annotate Newlabels_detailed on Macrophages
APC_obj
@
meta.data
$
Newlabels_detailed
<-
rep
(
"Undefined"
,
length
(
APC_obj
@
meta.data
$
SingleR_ImmGenData_labels
))
APC_obj
@
meta.data
$
CellID
<-
APC_obj
@
assays
$
RNA
@
counts
@
Dimnames
[[
2
]]
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"0"
]
<-
"TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"1"
]
<-
"KCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"2"
]
<-
"IFNa TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"3"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"4"
]
<-
"IFNa TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"5"
]
<-
"IFNa TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"6"
]
<-
"IFNa TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"7"
]
<-
"TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"8"
]
<-
"IFNa TAMs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"9"
]
<-
"CDPs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"10"
]
<-
"cDC1"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"11"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"12"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"13"
]
<-
"pDCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"14"
]
<-
"Monocytes"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"15"
]
<-
"Ccr7 DCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"16"
]
<-
"KCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"17"
]
<-
"Mo DCs"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"18"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"19"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"20"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"21"
]
<-
"Undefined"
APC_obj
@
meta.data
$
Newlabels_detailed
[
APC_obj
@
meta.data
$
SCT_snn_res.1.2
==
"22"
]
<-
"Undefined"
# Remove undefined cells
APC_obj
<-
SetIdent
(
object
=
APC_obj
,
value
=
"Newlabels_detailed"
)
APC_obj
<-
subset
(
APC_obj
,
idents
=
c
(
"Undefined"
),
invert
=
T
)
# save APCs object
dir.create
(
paste
(
out_dir
,
"APCs"
,
sep
=
"/"
))
saveRDS
(
APC_obj
,
file
=
paste
(
out_dir
,
"APCs"
,
"APCs_DBR_final.rds"
,
sep
=
"/"
))
## Reintegrate all labeles into Full object
# Reintegrate lables from TNK_obj into Full_obj
# Newlables_rough
labels_TNK_rough
<-
data.frame
(
ToSelect
=
TNK_obj
@
meta.data
$
CellID
,
Classification
=
TNK_obj
@
meta.data
$
Newlabels_rough
)
alllabels
<-
labels_TNK_rough
orderDF
<-
data.frame
(
allIDs
=
TNK_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
TNK_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
Full_obj
@
meta.data
$
Newlabels_rough
<-
Full_obj
@
meta.data
$
Newlabels
Full_obj
@
meta.data
$
Newlabels_rough
[
Full_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
DimPlot
(
object
=
Full_obj
,
reduction
=
"umap"
,
group.by
=
"Newlabels_rough"
,
pt.size
=
1
,
label
=
T
,
label.size
=
10
)
# Newlabels_detailed
labels_TNK_detailed
<-
data.frame
(
ToSelect
=
TNK_obj
@
meta.data
$
CellID
,
Classification
=
TNK_obj
@
meta.data
$
Newlabels_detailed
)
alllabels
<-
labels_TNK_detailed
orderDF
<-
data.frame
(
allIDs
=
TNK_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
TNK_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
Full_obj
@
meta.data
$
Newlabels_detailed
<-
Full_obj
@
meta.data
$
Newlabels
Full_obj
@
meta.data
$
Newlabels_detailed
[
Full_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
DimPlot
(
object
=
Full_obj
,
reduction
=
"umap"
,
group.by
=
"Newlabels_detailed"
,
pt.size
=
1
,
label
=
T
,
label.size
=
4
)
# Reintegrate lables from APC_obj into Full_obj
# Newlables_rough
labels_APC_rough
<-
data.frame
(
ToSelect
=
APC_obj
@
meta.data
$
CellID
,
Classification
=
APC_obj
@
meta.data
$
Newlabels_rough
)
alllabels
<-
labels_APC_rough
orderDF
<-
data.frame
(
allIDs
=
APC_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
APC_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
Full_obj
@
meta.data
$
Newlabels_rough
[
Full_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
DimPlot
(
object
=
Full_obj
,
reduction
=
"umap"
,
group.by
=
"Newlabels_rough"
,
pt.size
=
1
,
label
=
T
,
label.size
=
10
)
# Newlabels_detailed
labels_APC_detailed
<-
data.frame
(
ToSelect
=
APC_obj
@
meta.data
$
CellID
,
Classification
=
APC_obj
@
meta.data
$
Newlabels_detailed
)
alllabels
<-
labels_APC_detailed
orderDF
<-
data.frame
(
allIDs
=
APC_obj
@
meta.data
$
CellID
,
order
=
c
(
1
:
length
(
APC_obj
@
meta.data
$
CellID
)))
alllabels
<-
merge
(
alllabels
,
orderDF
,
by
=
1
)
alllabels
<-
alllabels
[
order
(
alllabels
$
order
),]
Full_obj
@
meta.data
$
Newlabels_detailed
[
Full_obj
@
meta.data
$
CellID
%in%
alllabels
$
ToSelect
]
<-
alllabels
$
Classification
DimPlot
(
object
=
Full_obj
,
reduction
=
"umap"
,
group.by
=
"Newlabels_detailed"
,
pt.size
=
1
,
label
=
T
,
label.size
=
4
)
# Remove undefined cells (cells annotated as undefined or cells that were removed in TNK_obj and APC_obj analysis)
Full_obj
<-
SetIdent
(
object
=
Full_obj
,
value
=
"Newlabels_detailed"
)
Full_obj
<-
subset
(
Full_obj
,
idents
=
c
(
"Undefined"
,
"T and NK cells"
),
invert
=
T
)
# Save Full_obj
saveRDS
(
object
=
Full_obj
,
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_final_DBR_labeled.rds"
,
sep
=
"/"
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment