Skip to content

Commit d863e8e

Browse files
author
Sean Wilson
committed
ready to go
0 parents  commit d863e8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1734
-0
lines changed

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
^DevKidCC\.Rproj$
2+
^\.Rproj\.user$
3+
^doc$
4+
^Meta$

.Rhistory

Lines changed: 512 additions & 0 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.Rproj.user
2+
inst/doc
3+
doc
4+
Meta
5+
backupdata
6+

DESCRIPTION

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Package: DevKidCC
2+
Title: Kidney Cell Classifier
3+
Version: 0.2.0
4+
Authors@R:
5+
person(given = "Sean",
6+
family = "Wilson",
7+
role = c("aut", "cre"),
8+
email = "[email protected]",
9+
comment = c(ORCID = "0000-0002-8994-0781"))
10+
Description: Thsi package takes a Seurat based single cell dataset and classifies the cells into their most likely kidney cell type.
11+
License: MIT + file LICENSE
12+
Encoding: UTF-8
13+
LazyData: true
14+
Roxygen: list(markdown = TRUE)
15+
RoxygenNote: 7.1.1
16+
Suggests:
17+
testthat (>= 2.1.0),
18+
knitr,
19+
rmarkdown
20+
Imports:
21+
ggplot2,
22+
dplyr,
23+
magrittr,
24+
purrr,
25+
networkD3,
26+
rlang,
27+
Seurat,
28+
patchwork,
29+
tibble,
30+
utils,
31+
formattable
32+
VignetteBuilder: knitr
33+
Depends:
34+
R (>= 2.10),
35+
scPred

DevKidCC.Rproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageRoxygenize: rd,collate,namespace

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2020
2+
COPYRIGHT HOLDER: Sean Wilson

NAMESPACE

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export("%>%")
4+
export(ComponentPlot)
5+
export(DevKidCC)
6+
export(DotPlotCompare)
7+
export(GeneSummary)
8+
export(SankeyPlot)
9+
importFrom(Seurat,"DefaultAssay<-")
10+
importFrom(Seurat,"Idents<-")
11+
importFrom(Seurat,CellsByIdentities)
12+
importFrom(Seurat,CreateSeuratObject)
13+
importFrom(Seurat,DimPlot)
14+
importFrom(Seurat,FetchData)
15+
importFrom(Seurat,Idents)
16+
importFrom(Seurat,MinMax)
17+
importFrom(Seurat,NoLegend)
18+
importFrom(Seurat,NormalizeData)
19+
importFrom(dplyr,arrange)
20+
importFrom(dplyr,bind_cols)
21+
importFrom(dplyr,bind_rows)
22+
importFrom(dplyr,filter)
23+
importFrom(dplyr,inner_join)
24+
importFrom(dplyr,left_join)
25+
importFrom(dplyr,mutate)
26+
importFrom(dplyr,select)
27+
importFrom(dplyr,transmute)
28+
importFrom(ggplot2,aes)
29+
importFrom(ggplot2,aes_string)
30+
importFrom(ggplot2,coord_flip)
31+
importFrom(ggplot2,element_blank)
32+
importFrom(ggplot2,element_line)
33+
importFrom(ggplot2,element_text)
34+
importFrom(ggplot2,facet_wrap)
35+
importFrom(ggplot2,geom_bar)
36+
importFrom(ggplot2,geom_point)
37+
importFrom(ggplot2,geom_text)
38+
importFrom(ggplot2,ggplot)
39+
importFrom(ggplot2,ggtitle)
40+
importFrom(ggplot2,guide_legend)
41+
importFrom(ggplot2,guides)
42+
importFrom(ggplot2,labs)
43+
importFrom(ggplot2,position_stack)
44+
importFrom(ggplot2,rel)
45+
importFrom(ggplot2,scale_colour_gradient2)
46+
importFrom(ggplot2,scale_colour_viridis_c)
47+
importFrom(ggplot2,scale_fill_gradient2)
48+
importFrom(ggplot2,scale_fill_manual)
49+
importFrom(ggplot2,scale_y_continuous)
50+
importFrom(ggplot2,theme)
51+
importFrom(ggplot2,theme_classic)
52+
importFrom(ggplot2,theme_void)
53+
importFrom(magrittr,"%>%")
54+
importFrom(networkD3,sankeyNetwork)
55+
importFrom(patchwork,plot_layout)
56+
importFrom(patchwork,wrap_plots)
57+
importFrom(purrr,map)
58+
importFrom(purrr,map2)
59+
importFrom(purrr,map_dbl)
60+
importFrom(rlang,.data)
61+
importFrom(scPred,scPredict)
62+
importFrom(tibble,column_to_rownames)
63+
importFrom(tibble,rownames_to_column)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DevKidCC 0.2.0
2+
3+
# DevKidCC 0.1.6
4+

R/DevKidCC-package.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#' @keywords internal
2+
"_PACKAGE"
3+
4+
#' @importFrom ggplot2 aes coord_flip element_text facet_wrap geom_bar geom_text ggplot ggtitle position_stack theme rel scale_fill_manual scale_colour_gradient2 scale_fill_gradient2
5+
#' @importFrom ggplot2 aes_string geom_point element_blank scale_colour_viridis_c element_line labs theme_classic theme_void guides guide_legend scale_y_continuous
6+
#' @importFrom dplyr bind_rows filter mutate left_join transmute inner_join select bind_cols inner_join arrange
7+
#' @importFrom tibble rownames_to_column column_to_rownames
8+
#' @importFrom scPred scPredict
9+
#' @importFrom patchwork plot_layout wrap_plots
10+
#' @importFrom Seurat DimPlot NoLegend FetchData CellsByIdentities Idents CreateSeuratObject DefaultAssay<- NormalizeData MinMax Idents<-
11+
#' @importFrom magrittr %>%
12+
#' @importFrom purrr map map2 map_dbl
13+
#' @importFrom rlang .data
14+
#'
15+
# The following block is used by usethis to automatically manage
16+
# roxygen namespace tags. Modify with care!
17+
## usethis namespace: start
18+
## usethis namespace: end
19+
NULL

R/DevKidCC.R

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#' DevKidCC
2+
#'
3+
#' @param seurat seurat object
4+
#' @param threshold minimum value for an identity to be assigned within the model call, default is 0.7
5+
#' @param max.iter Can ask scPred to run this number of integrations, set to 0 be default
6+
#'
7+
#' @return
8+
#' @export
9+
#'
10+
#' @examples
11+
DevKidCC <- function(seurat, threshold = 0.7, max.iter = 0) {
12+
if (("DKCC" %in% colnames(seurat@meta.data)) == FALSE){
13+
seurat@misc$old.meta <- seurat@meta.data
14+
} else {
15+
seurat@meta.data <- seurat@misc$old.meta
16+
}
17+
md <- seurat@meta.data
18+
#if ("cell" %in% colnames(md)) {
19+
# [email protected] %>% rownames_to_column("celltemp") %>% select(-cell) %>% column_to_rownames("celltemp")
20+
#}
21+
old.seurat <- seurat
22+
seurat <- CreateSeuratObject(old.seurat@assays$RNA@counts, meta.data = md)
23+
DefaultAssay(seurat) <- "RNA"
24+
seurat <- NormalizeData(seurat)
25+
kcc <- data.frame()
26+
27+
seurat <- scPred::scPredict(seurat, reference = model1.all, threshold = threshold, max.iter.harmony=max.iter)
28+
seurat$LineageID <- seurat$scpred_prediction
29+
30+
kcc <- seurat@meta.data %>% rownames_to_column("cell") %>% filter(LineageID %in% c("unassigned", "NPC", "Endothelial")) %>% transmute(cell = cell, kcc = LineageID)
31+
#kcc$kcc <- gsub("unassigned", "OffTarget", kcc$kcc)
32+
t1 <- seurat[, seurat$LineageID%in%c("unassigned", "NPC", "Endothelial")]
33+
34+
35+
36+
37+
if (nrow(seurat@meta.data %>% filter(LineageID=="Nephron")) > 2){
38+
nephronid <- scPred::scPredict(seurat[, seurat$LineageID=="Nephron"], reference = model2.nephron,
39+
threshold = 0.0, max.iter.harmony=max.iter)
40+
nephronid$NephronID <- nephronid$scpred_prediction
41+
nephronid$NephronID <- gsub("unassigned", "Nephron_NC", nephronid$NephronID)
42+
kcc <- bind_rows(kcc,
43+
nephronid@meta.data %>% rownames_to_column("cell") %>% filter(NephronID %in% c("CellCycle", "EarlyNephron", "unassigned")) %>% transmute(cell = cell, kcc = NephronID))
44+
45+
if (nrow(nephronid@meta.data %>% filter(NephronID %in% c("CellCycle", "EarlyNephron", "unassigned"))) > 0){
46+
neph <- nephronid[, nephronid$NephronID %in% c("CellCycle", "EarlyNephron", "unassigned")]
47+
t1 <- merge(t1, neph)
48+
}
49+
50+
51+
if (nrow(nephronid@meta.data %>% filter(NephronID=="ProximalNephron")) > 2){
52+
proximalid <- scPred::scPredict(nephronid[, nephronid$NephronID =="ProximalNephron"],
53+
reference = model3.pn, threshold = 0.0, max.iter.harmony=max.iter)
54+
proximalid$SegmentID <- proximalid$scpred_prediction
55+
56+
kcc <- bind_rows(kcc,
57+
proximalid@meta.data %>% rownames_to_column("cell") %>% transmute(cell = cell, kcc = SegmentID))
58+
t1 <- merge(t1, proximalid)
59+
}
60+
61+
62+
if (nrow(nephronid@meta.data %>% filter(NephronID=="DistalNephron")) > 2){
63+
distalid <- scPred::scPredict(nephronid[, nephronid$NephronID =="DistalNephron"],
64+
reference = model3.dn, threshold = 0.0, max.iter.harmony=max.iter)
65+
distalid$SegmentID <- distalid$scpred_prediction
66+
67+
kcc <- bind_rows(kcc,
68+
distalid@meta.data %>% rownames_to_column("cell") %>% transmute(cell = cell, kcc = SegmentID))
69+
t1 <- merge(t1, distalid)
70+
}
71+
72+
if (nrow(nephronid@meta.data %>% filter(NephronID=="RenalCorpuscle")) > 2){
73+
rcid <- scPred::scPredict(nephronid[, nephronid$NephronID =="RenalCorpuscle"], reference = model3.rc,
74+
threshold = 0.0, max.iter.harmony=max.iter)
75+
rcid$SegmentID <- rcid$scpred_prediction
76+
77+
kcc <- bind_rows(kcc,
78+
rcid@meta.data %>% rownames_to_column("cell") %>% transmute(cell = cell, kcc = SegmentID))
79+
t1 <- merge(t1, rcid)
80+
}
81+
}
82+
83+
if (nrow(seurat@meta.data %>% filter(LineageID=="Stroma")) > 2){
84+
stromaid <- scPred::scPredict(seurat[, seurat$LineageID=="Stroma"], reference = model2.stroma,
85+
threshold = 0.0, max.iter.harmony=max.iter)
86+
stromaid$StromaID<- stromaid$scpred_prediction
87+
88+
stromaid$StromaID <- gsub(pattern = "unassigned", replacement = "Stroma_NC", x = stromaid$StromaID)
89+
kcc <- bind_rows(kcc,
90+
stromaid@meta.data %>% rownames_to_column("cell") %>% transmute(cell = cell, kcc = StromaID))
91+
t1 <- merge(t1, stromaid)
92+
}
93+
94+
if (nrow(seurat@meta.data %>% filter(LineageID=="UrEp")) > 2){
95+
urepid <- scPred::scPredict(seurat[, seurat$LineageID=="UrEp"], reference = model2.urep,
96+
threshold = 0.0, max.iter.harmony = max.iter)
97+
urepid$UrEpID <- urepid$scpred_prediction
98+
urepid$UrEpID <- gsub(pattern = "unassigned", replacement = "UrEp", x = urepid$UrEpID)
99+
kcc <- bind_rows(kcc,
100+
urepid@meta.data %>% rownames_to_column("cell") %>% transmute(cell = cell, kcc = UrEpID))
101+
t1 <- merge(t1, urepid)
102+
}
103+
104+
if ("NephronID" %in% colnames(t1@meta.data)){
105+
t1$NephronID <- gsub("CellCycle", "CC", t1$NephronID)
106+
t1$NephronID <- gsub("EarlyNephron", "EN", t1$NephronID)
107+
t1$NephronID <- gsub("DistalNephron", "DN", t1$NephronID)
108+
t1$NephronID <- gsub("ProximalNephron", "PN", t1$NephronID)
109+
t1$NephronID <- gsub("RenalCorpuscle", "RC", t1$NephronID)
110+
t1$NephronID <- factor(t1$NephronID, levels = c("unassigned", "CC", "EN", "DN", "PN", "RC"))
111+
}
112+
113+
kcc$kcc <- gsub("CellCycle", "CC", kcc$kcc)
114+
kcc$kcc <- gsub("EarlyNephron", "EN", kcc$kcc)
115+
levels <- c("unassigned", "NPC", "Endothelial",
116+
"CC", "EN", "DN", "PN", "RC",
117+
"SPC", "Cortex", "Medullary", "Mesangial", "Stroma_NC",
118+
"Tip", "OuterStalk", "InnerStalk",
119+
"EDT_EMT", "DT", "LOH", "EPT", "PT", "PEC", "EPod", "Pod", "Nephron_NC")
120+
121+
t1$DKCC <- factor(kcc$kcc, levels = levels[levels %in% unique(kcc$kcc)])
122+
t1$LineageID <- factor(t1$LineageID, levels = c("unassigned", "Endothelial", "Stroma", "NPC", "Nephron", "UrEp"))
123+
124+
125+
126+
#
127+
128+
129+
old.seurat@meta.data <- left_join(md %>% rownames_to_column("cell") %>% select(cell),
130+
t1@meta.data %>% rownames_to_column("cell"), by = "cell") %>% column_to_rownames("cell")
131+
132+
return(old.seurat)
133+
}
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+

0 commit comments

Comments
 (0)