@@ -48,13 +48,18 @@ prepareDataFromBam <- function(bamFile, yieldSize = NULL, verbose = FALSE,
4848
4949 # a checkpoint to parse CB and UMI from the bam file, either from reads or CB/UMI tags.
5050 # currently read name only accepts the format CB_UMI#READNAME (CB & UMI cannot have '_', otherwise parsing fails)
51- mcols(readGrgList [[counter ]])$ CB <- case_when(grepl(" ^[^_]+_[^#]+#" , names(readGrgList [[counter ]]), perl = TRUE ) ~ sub(" _.*" , " " , names(readGrgList [[counter ]])),
52- ! is.na(mcols(alignmentInfo )$ CB ) ~ mcols(alignmentInfo )$ CB ,
53- TRUE ~ NA )
51+ mcols(readGrgList [[counter ]])$ CB <- case_when(
52+ ! is.na(mcols(alignmentInfo )$ CB ) ~ mcols(alignmentInfo )$ CB ,
53+ grepl(" ^[^_]+_[^#]+#" , names(readGrgList [[counter ]]), perl = TRUE ) ~ sub(" _.*" , " " , names(readGrgList [[counter ]])),
54+ TRUE ~ NA
55+ )
5456
55- mcols(readGrgList [[counter ]])$ UMI <- case_when(grepl(" ^[^_]+_[^#]+#" , names(readGrgList [[counter ]]), perl = TRUE ) ~ sub(" ^[^_]+_([^#]+)#.*$" , " \\ 1" , names(readGrgList [[counter ]])),
56- ! is.na(mcols(alignmentInfo )$ UB ) ~ mcols(alignmentInfo )$ UB ,
57- TRUE ~ NA )
57+ mcols(readGrgList [[counter ]])$ UMI <- case_when(
58+ ! is.na(mcols(alignmentInfo )$ UB ) ~ mcols(alignmentInfo )$ UB ,
59+ grepl(" ^[^_]+_[^#]+#" , names(readGrgList [[counter ]]), perl = TRUE ) ~ sub(" ^[^_]+_([^#]+)#.*$" , " \\ 1" , names(readGrgList [[counter ]])),
60+ TRUE ~ NA
61+ )
62+
5863 } else { # if demultiplexed is a string path
5964 mcols(readGrgList [[counter ]])$ CB <- NA
6065 mcols(readGrgList [[counter ]])$ UMI <- NA
0 commit comments