This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bamtools filter specific motif sequence

I am trying to use bamtools filter to keep output a new bam file with a specific sequence. This is what I am using...

bamtools filter -in Aligned.bam -queryBases AAACCTG >Aligned_1.bam

This does not return any matches. The question I am asking, is it possible to filter sequencing reads from a BAM file that has specific sequence of interest? If so, how? Are there any other tools that might be able to do this?

Thanks in advance for any guidance provided.

bamtools filter motif

1 answer

samtools  view -h input.bam | awk -F '\t' '($1 ~ /^@/ || $10 ~/AAACCTG/ )' | samtools view -Sb -o out.bam -

using samjs

java -jar dist/samjs.jar -e 'record.getReadString().contains("AAACCTG")' input.bam

Thanks a lot! I was able to make it work with the following:

samtools view -h input.bam | awk -F '\t' '($1 ~ /^@/ || $10 ~/AAACCTG/ )' >filter.sam ; samtools view filter.sam -Sb -o filter.bam

ah yes, I forgot to write the last hyphen on my command line. You should be able to write filter the bam without writing this 'filter.sam'.

Please check the green mark on the left to flag this question as answered.

Log in to answer this question.