-
Notifications
You must be signed in to change notification settings - Fork 67
/
zUMIs-BCdetection.R
53 lines (44 loc) · 1.91 KB
/
zUMIs-BCdetection.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
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env Rscript
library(methods)
library(data.table)
library(yaml)
library(ggplot2)
##########################
myYaml <- commandArgs(trailingOnly = T)
opt <-read_yaml(myYaml)
setwd(opt$out_dir)
source(paste0(opt$zUMIs_directory,"/barcodeIDFUN.R"))
options(datatable.fread.input.cmd.message=FALSE)
if(opt$num_threads < 32){
data.table::setDTthreads(threads=opt$num_threads)
}else{
data.table::setDTthreads(threads=32)
}
if(!is.null(opt$barcodes$barcode_sharing)){
if(opt$barcodes$barcode_sharing == ""){
opt$barcodes$barcode_sharing <- NULL
}
}
#######################################################################
#######################################################################
##### Barcode handling & chunking
#read file with barcodecounts
# bc is the vector of barcodes to keep
bccount<-cellBC(bcfile = opt$barcodes$barcode_file,
bcnum = opt$barcodes$barcode_num,
bcauto = opt$barcodes$automatic,
bccount_file= paste0(opt$out_dir,"/", opt$project, ".BCstats.txt"),
outfilename = paste0(opt$out_dir,"/zUMIs_output/stats/",opt$project,".detected_cells.pdf"))
fwrite(bccount,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,"kept_barcodes.txt"))
#check if binning of adjacent barcodes should be run
if(opt$barcodes$BarcodeBinning > 0 | !is.null(opt$barcodes$barcode_sharing)){
binmap <- BCbin(bccount_file = paste0(opt$out_dir,"/", opt$project, ".BCstats.txt"),
bc_detected = bccount)
fwrite(binmap,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,".BCbinning.txt"))
#update the number reads in BCcount table
binmap_additional <- binmap[, .(addtl = sum(n)), by = trueBC]
bccount[match(binmap_additional$trueBC,XC),n := n + binmap_additional$addtl]
fwrite(bccount,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,"kept_barcodes_binned.txt"))
}
##############################################################
q()