-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend_seurat.R
43 lines (35 loc) · 1.53 KB
/
extend_seurat.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
32
33
34
35
36
37
38
39
40
41
42
43
#' @export
#Functions in this file add columns to Seurat metadata
#Grouping a continuous measurement into categories
SetBandLabels <- function(breakPoints){
brLength <- length(breakPoints)
midSections <- unlist(lapply(seq(1:(brLength-1)),
function(x) str_c("Between ", breakPoints[x], " and ", breakPoints[x+1])))
return (c(str_c("Below ", breakPoints[1]), midSections, str_c("Above ", breakPoints[brLength])))
}
#Adding said categories to the metadata
AddBand <- function(seuratObj, bandName, columnName, breakPoints){
ticks <- SetBandLabels(breakPoints)
[email protected][[bandName]] <-
cut([email protected][[columnName]], breaks = c(-Inf, breakPoints, Inf),
labels = ticks)
[email protected][[bandName]] <- factor([email protected][[bandName]],levels = rev(ticks))
return(seuratObj)
}
#Adding cell types
AnnotateSeurat <- function(seuratObj, colName, types){
[email protected][[colName]] <- sapply(seuratObj$seurat_clusters, function(x) types[x])
return (seuratObj)
}
GeneExpression <- function(expression, gene)
return (expression[gene, ])
GenePresence <- function(expression, gene)
return (ifelse(expression[gene, ] > 0, 1, 0))
AppendGeneExpression <- function(seuratObj, expression, gene, colName = "geneExp"){
[email protected][[colName]] <- GeneExpression(expression, gene)
return(seuratObj)
}
AppendGenePresence <- function(seuratObj, expression, gene, colName = "genePres"){
[email protected][[colName]] <- GenePresence(expression, gene)
return(seuratObj)
}