This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Importing read pairs from BAM with specific R1 and R2 start/end positions for pair

Hi there,

Is it possible to set up a ScanBamParam() to import read pairs where the R1 and R2 reads start and end at specific positions? Note that this is not a range, but rather a conditional to only import the read pair if the R1 has a certain position AND its R2 pair has a certain position.

If not with ScanBamParam(), is there another way to filter for this? Help would be very much appreciated :)

Kind regards, Emily

rsamtools

1 answer

using samjdk https://jvarkit.readthedocs.io/en/latest/SamJdk/ assuming the MC (mate cigar) attribute is available.

java -jar dist/jvarkit.jar samjdk -e 'return record.getReadPairedFlag() && !record.getReadUnmappedFlag() && record.getContig().equals("chr1") && record.getReadPairedFlag() && !record.getMateUnmappedFlag() && record.getContig().equals(record.getMateReferenceName())  && record.getStart()==12345 && SAMUtils.getMateAlignmentEnd(record)==56789;' in.bam

Log in to answer this question.