Hello,
I am trying to read in a BAM file using RSamtools into R. I only want to read in those rows that match a specific "RNAME" (eg: I only want to read rows where RNAME = "ref2")
I have looked through the vignette and online resources, and this is what I tried so far.
Obviously my "which" argument for ScanBamParam is
incorrect. Could someone help me correct this query ?
If there is no way to do this, is my only choice reading in all the rows in BAM file, and then sub-setting based on my RNAME match ?
inputBam = "test.bam"
bamFile <- BamFile(inputBam)
seqInfo1 <- seqinfo(bamFile)
seqInfo1
Seqinfo object with 2 sequences from an unspecified genome:
seqnames seqlengths isCircular genome
ref1 159322 NA <NA>
ref2 162114 NA <NA>
ref= "ref2"
# trying to read only rows in BAM file where RNAME = "ref2"
params <- ScanBamParam(which = GRanges(ref,seqlengths = 162114), what = c("qname", "flag","rname","pos","mapq","cigar"))
Error in ScanBamParam(which = GRanges(ref, seqlengths = 162114), what = c("qname", : error in evaluating the argument 'which' in selecting a method for function 'ScanBamParam': Error in asMethod(object) : The character vector to convert to a GRanges object must contain strings of the form "chr1:2501-2800" or "chr1:2501-2800:+" (".." being also supported as a separator between the start and end positions). Strand can be "+", "-", "*", or missing.
temp <- Rsamtools::scanBam(file =bam.file , param = params)
Thank you.
I would like to add that I am dealing with non-human genomes. So I don't have an IRanges to supply in the "which" condition as mentioned in here: filterBam using rname