-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.R
31 lines (27 loc) · 1.22 KB
/
start.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#' @export
#Creates a Seurat object from a list of files containing count matrices.
SeuratsList <- function(files, conditions, minCells = 10)
lapply(1:length(files), function(i){
message(str_c("Adding Seurat object: ", conditions[i])," from file: ", files[i], ".")
CreateSeuratObject(counts = readRDS(files[i]), project = conditions[i], min.cells = minCells)
})
CountCells <- function(seuratObj, type){
if (is.null(seuratObj))WriteMessage("0", type)
else{
grouped_cells <- aggregate(nFeature_RNA ~ orig.ident, data = [email protected], length)[, c(2,1)]
WriteMessage(paste(apply(grouped_cells, 1, paste,collapse=" "), collapse = " cells, "), type)
}
}
WriteMessage <- function(result, type){
message(ifelse (type == "in",
str_c("There are now ", result, " cells in this Seurat object."),
str_c(result, " cells were removed.")))
}
MergeSeurats <- function(files, conditions, ids, minCells = 10){
seurats <- SeuratsList(files, conditions, minCells)
seuratObj <- merge(seurats[[1]], seurats[c(2:length(files))], add.cell.ids = ids, project = "All conditions")
message("Merged Seurat objects.")
message(CountCells(seuratObj, "in"))
message("Finished.")
return (seuratObj)
}