I have been struggling with this problem for long time and would appreciate if somebody answer some questions I have below. I need to count the number of 21 bases long reads in my bam file with the last base mismatched. First, I tried the following code:
bamfiles <- "aligned.bam"
params <-
ScanBamParam(
which = which,
flag = scanBamFlag(
isUnmappedQuery = FALSE,
isDuplicate = FALSE,
isNotPassingQualityControls = FALSE
),
simpleCigar = FALSE,
reverseComplement = FALSE,
what = c(
"qname",
"flag",
"rname",
"seq",
"strand",
"pos",
"qwidth",
"cigar",
"qual",
"mapq"
)
)
res <- scanBam(bamfiles, param=params)
res
I can count the cigar like this:
sum(res$`NC_013116:0-2166`$cigar =="21M1S")
I want to know what cigar I should use to get the number of reads with 21 bases long and last read mismatched. Shouldn't I be using "21M1S" cigar? How about the the minus strand reads? Does it take both plus and minus reads into account while counting?
how is it different from your previous question ? How to use scanbamparam and CIGAR from Rsamtools to count specific reads?
It is not, but want to use rsamtools. I also want to know if I ak using right cigar.