This worked well. Thank you!
Hello,
I know that I can create a subset of a bam file for a desired region using samtools view:
samtools view -b UWNsub100k_int.bam chrXII:450000-470000 > UWNsub100k_ribos.bam
What I want to do, however, is create a .bam file that excludes these regions. Perhaps something similar to -v for grep. Is there a samtools command for this?
Thanks,
2 answers
samtools view -U file will output reads not selected by filters to file. This does not apply to regions specified on the command line (after the input file name) or with -M, as using the index to jump to the specified regions is separate from “filtering the reads” — however it does apply to -L.
So construct unwanted.bed from your regions to be excluded and use
samtools view -L unwanted.bed -U remaining.bam -o /dev/null UWNsub100k_int.bam
Samtools view -L will let you give samtools a bed files of the regions you want. I don't think there is a -v equivalent.
Log in to answer this question.
use
bedtools complementto generate the complement of chrXII:450000-470000