Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scRNA_urethra
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Strand Lab
scRNA_urethra
Commits
19c00ea7
Commit
19c00ea7
authored
6 months ago
by
John Lafin
Browse files
Options
Downloads
Patches
Plain Diff
Complete annotation script
parent
e72babe6
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/04_annotation.R
+67
-34
67 additions, 34 deletions
scripts/04_annotation.R
with
67 additions
and
34 deletions
scripts/04_annotation.R
+
67
−
34
View file @
19c00ea7
# Annotation and stress score filtering
# Author: John T Lafin
# Updated: 2024-10-1
5
# Updated: 2024-10-1
6
print
(
"Script begin at: "
)
Sys.time
()
...
...
@@ -70,12 +70,12 @@ dir.create(annotdir, showWarnings=FALSE)
## Create list of labels
annot.list
<-
list
()
annot.list
$
Endothelia
<-
c
(
"
V
enous endothelia"
,
"
V
enous endothelia"
,
"
C
apillary endothelia"
,
"
C
apillary endothelia"
,
"
A
rterial endothelia"
,
"
L
ymphatic endothelia"
)
annot.list
$
Endothelia
<-
c
(
"
v
enous endothelia"
,
"
v
enous endothelia"
,
"
c
apillary endothelia"
,
"
c
apillary endothelia"
,
"
a
rterial endothelia"
,
"
l
ymphatic endothelia"
)
annot.list
$
Epithelia
<-
c
(
"transitional basal epithelia of urethra"
,
"basal epithelia of prostate"
,
"transitional basal epithelia of urethra"
,
...
...
@@ -92,7 +92,7 @@ annot.list$Epithelia <- c("transitional basal epithelia of urethra",
"squamous intermediate epithelia of urethra"
,
"squamous intermediate epithelia of urethra"
,
"basal epithelia of prostate"
,
"
transitional
basal epithelia of urethra"
,
"
squamous
basal epithelia of urethra"
,
"basal epithelia of prostate"
,
"proliferative cells"
,
"squamous luminal epithelia of urethra"
,
...
...
@@ -100,15 +100,15 @@ annot.list$Epithelia <- c("transitional basal epithelia of urethra",
"transitional basal epithelia of urethra"
,
"basal epithelia of prostate"
)
annot.list
$
Leukocyte
<-
c
(
"T cell"
,
"
M
acrophage"
,
"
M
ast cell"
,
"
m
acrophage"
,
"
m
ast cell"
,
"T cell"
,
"T cell"
,
"NK cell"
,
"
P
roliferating leukocyte"
,
"
p
roliferating leukocyte"
,
"B cell"
,
"
D
endritic cell"
,
"
P
lasma cell"
)
"
d
endritic cell"
,
"
p
lasma cell"
)
annot.list
$
Stroma
<-
c
(
"pericyte"
,
"major interstitial fibroblast"
,
"smooth muscle"
,
...
...
@@ -150,7 +150,7 @@ VlnPlot(lin.list$Epithelia, "NE.score", group.by = "orig.ident") +
ggsave
(
paste0
(
annotdir
,
"NE_score_cutoff.png"
))
lin.list
$
Epithelia
@
meta.data
<-
lin.list
$
Epithelia
@
meta.data
%>%
mutate
(
cellannotation
=
if_else
(
NE.score
>
0.3
,
"
N
euroendocrine cell"
,
cellannotation
))
mutate
(
cellannotation
=
if_else
(
NE.score
>
0.3
,
"
n
euroendocrine cell"
,
cellannotation
))
## Add ionocytes
VlnPlot
(
lin.list
$
Epithelia
,
"FOXI1"
,
group.by
=
"orig.ident"
)
+
...
...
@@ -159,10 +159,7 @@ VlnPlot(lin.list$Epithelia, "FOXI1", group.by = "orig.ident") +
ggsave
(
paste0
(
annotdir
,
"FOXI1_score_cutoff.png"
))
ionocyte.barcodes
<-
WhichCells
(
lin.list
$
Epithelia
,
expression
=
FOXI1
>
0.3
)
lin.list
$
Epithelia
@
meta.data
[
ionocyte.barcodes
,
"cellannotation"
]
<-
"Ionocyte"
## Save updates to object
lin.list
$
Epithelia
<-
StashIdent
(
lin.list
$
Epithelia
,
"cellannotation"
)
lin.list
$
Epithelia
@
meta.data
[
ionocyte.barcodes
,
"cellannotation"
]
<-
"ionocyte"
## Split periepithelial fibroblasts by sex
fib_rename
<-
WhichCells
(
lin.list
$
Stroma
,
...
...
@@ -170,7 +167,10 @@ fib_rename <- WhichCells(lin.list$Stroma,
expression
=
Sex
==
"male"
)
levels
(
lin.list
$
Stroma
$
cellannotation
)
<-
c
(
levels
(
lin.list
$
Stroma
$
cellannotation
),
"periepithelial fibroblast of prostate"
)
lin.list
$
Stroma
@
meta.data
[
fib_rename
,
"cellannotation"
]
<-
"periepithelial fibroblast of prostate"
Idents
(
stroma
)
<-
"cellannotation"
## Reset idents
Idents
(
lin.list
$
Epithelia
)
<-
"cellannotation"
Idents
(
lin.list
$
Stroma
)
<-
"cellannotation"
## Save labeled UMAP plots
for
(
lin
in
lins
)
{
...
...
@@ -192,9 +192,7 @@ Idents(lin.list$Epithelia) <- "RNA_snn_res.1.5"
for
(
lin
in
names
(
lin.list
))
{
VlnPlot
(
lin.list
[[
lin
]],
"Stress.score"
,
pt.size
=
0
)
+
NoLegend
()
ggsave
(
paste0
(
stressdir
,
lin
,
"_pre-filter.png"
),
width
=
11
,
height
=
8.5
)
ggsave
(
paste0
(
stressdir
,
lin
,
"_pre-filter.png"
))
}
## Define stressed clusters based on violin plots
...
...
@@ -209,24 +207,59 @@ for (lin in names(lin.list)) {
lin.list
[[
lin
]]
<-
subset
(
lin.list
[[
lin
]],
idents
=
stressed.cells
[[
lin
]],
invert
=
TRUE
)
lin.list
[[
lin
]]
<-
preprocess
(
lin.list
[[
lin
]],
default.res
=
"cellannotation"
)
}
lin.list
<-
lapply
(
lin.list
,
preprocess
)
## Save violin plots after first round of filtering
for
(
lin
in
names
(
lin.list
))
{
VlnPlot
(
lin.list
[[
lin
]],
"Stress.score"
,
pt.size
=
0
,
group.by
=
"RNA_snn_res.1"
)
+
NoLegend
()
ggsave
(
paste0
(
stressdir
,
lin
,
"_first_filter.png"
))
}
### TO-DO
# Second round of stress filtering on stroma
# Revisit epithelia to relabel
# Make sure that ionocytes and NE cells are present in epi labels
## Second round of stressed cell removal in stroma
Idents
(
lin.list
$
Stroma
)
<-
"RNA_snn_res.1"
lin.list
$
Stroma
<-
subset
(
lin.list
$
Stroma
,
idents
=
8
,
invert
=
TRUE
)
%>%
preprocess
(
default.res
=
"cellannotation"
)
## Save violin plot
VlnPlot
(
lin.list
$
Stroma
,
"Stress.score"
,
pt.size
=
0
,
group.by
=
"RNA_snn_res.1"
)
+
NoLegend
()
ggsave
(
paste0
(
stressdir
,
lin
,
"_second_filter.png"
))
## Reannotate endothelia
lin.list
$
Endothelia
@
meta.data
<-
lin.list
$
Endothelia
@
meta.data
%>%
mutate
(
cellannotation
=
if_else
(
RNA_snn_res.1
==
7
,
"venous endothelia"
,
cellannotation
))
Idents
(
lin.list
$
Endothelia
)
<-
"cellannotation"
## Save labeled UMAP plots
for
(
lin
in
lins
)
{
DimPlot
(
lin.list
[[
lin
]])
ggsave
(
paste0
(
annotdir
,
lin
,
"_umap-2.png"
))
}
# Merge -------------------------------------------------------------------
# Produce post-filter stress plots
for
(
lin
in
names
(
lin.list
))
{
VlnPlot
(
lin.list
[[
lin
]],
"Stress.score"
,
pt.size
=
0
)
+
NoLegend
()
ggsave
(
paste0
(
stressdir
,
lin
,
"_first_filter.png"
),
width
=
11
,
height
=
8.5
)
seu
<-
merge
(
lin.list
[[
1
]],
lin.list
[
2
:
length
(
lin.list
)])
plan
(
sequential
)
seu
<-
preprocess
(
seu
,
default.res
=
"cellannotation"
)
## Save UMAP plot
DimPlot
(
seu
,
label
=
TRUE
,
repel
=
TRUE
,
label.size
=
3
)
+
NoLegend
()
ggsave
(
paste0
(
annotdir
,
"global_umap.png"
))
# Save outputs ------------------------------------------------------------
objdir
<-
paste0
(
outdir
,
"objects/"
)
dir.create
(
objdir
,
showWarnings
=
FALSE
)
saveRDS
(
seu
,
paste0
(
objdir
,
"global.rds"
))
for
(
lin
in
names
(
lin.list
)){
saveRDS
(
lin.list
[[
lin
]],
paste0
(
objdir
,
lin
,
".rds"
))
}
## Save session info
capture.output
(
sessionInfo
(),
file
=
paste0
(
outdir
,
"session_info.txt"
))
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment