-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_metadata.R
40 lines (37 loc) · 1.07 KB
/
add_metadata.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
## ------------------------------------
##
## Script name: add metadata
##
## Purpose of script: Integrate samples by merging/concatenating or rPCA or CCA
##
## Author: Jiekun (Jackie) Yang
##
## Date Created: 2022-12-14
##
## Email: [email protected]
##
##--------------------------------------
### object_path is the path to the seurat object that needed the metadata
### object is the seurat object name if already loaded in the environment
### metadata is a data frame with the metadata to be added
## library setup
library(Seurat)
options(future.globals.maxSize = 128000 * 1024^2)
library(future)
library(future.apply)
library(qs)
plan("multiprocess", workers = 16)
## function
add_metadata <- function(object_path = NULL, object = NULL, metadata = NULL) {
if (!is.null(object_path)) {
temp.data <- qread(object_path)
}
if (!is.null(object)) {
temp.data <- get(object)
}
[email protected] <- cbind([email protected], pheno_df[match(temp.data$orig.ident, rownames(pheno_df)),])
if (!is.null(object_path)) {
qsave(temp.data, object_path)
}
return(temp.data)
}