This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Subsetting data from BAM file using R tools

Good day to all! This is my first post in Biostars.

I have BAM file with Paired-End RNA seq reads, and I need filter this file by "isize" field: extract the reads with isize not equal to NA and with absolute value of isize lower than treshold (in this case, 642 bp). After all, I must write this subset into SAM file (because this type is required for package which I will use).

I tried use R package Rsamtools for this, but my experience in R is inadequate for solve this problem quickly. If I'm right, settings "param" of function filterBam() can help (if I get BAM file with targer subset, I'll use asSam() to convert into SAM format). Remove reads with isize == NA is possible by means scanBamFlag:

flag <- scanBamFlag(isPaired = TRUE, hasUnmappedMate = FALSE)

But I have no idea about filtration by treshold (abs(bamFile$isize) <= 642). How I can do it in R?

Thanks in advance for your help!

rna-seq r rna-seq

1 answer

you can use pmax function in R for athreshold

I don't see pmax working in this case!

Thank you for answer, but how it can help me with BAM file subsetting? Can you give an example?

Log in to answer this question.