-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcellranger_metrics.R
32 lines (30 loc) · 1.16 KB
/
cellranger_metrics.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
## ------------------------------------
##
## Script name: concatenating cellranger metrics for all the samples
##
## Author: Jiekun (Jackie) Yang
##
## Date Created: 2022-12-12
##
## Email: [email protected]
##
##--------------------------------------
### cellranger_input_file is a tab delimited file with three columns: folder_path, library_ID and sample_ID
### target_folder is where you would like to store output files generated by this function
## function
cellranger_metrics <- function(cellranger_input_file = NULL, target_folder = NULL) {
temp.pwd <- getwd()
cellranger_input <- read.table(cellranger_input_file, header = T, stringsAsFactors = F)
setwd(target_folder)
temp.df <- data.frame()
for (temp.row in 1:nrow(cellranger_input)) {
temp.path <- cellranger_input[temp.row, 1]
temp.lib <- cellranger_input[temp.row, 2]
print(temp.lib)
temp.df.out <- read.csv(file = paste0(temp.path, "/metrics_summary.csv"), header = T)
temp.df.out$library <- temp.lib
temp.df <- rbind(temp.df, temp.df.out)
}
write.table(temp.df, paste0(target_folder, "/cellranger_metrics.txt"), sep = "\t", quote = F, col.names = T, row.names = F)
setwd(temp.pwd)
}