This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Removing reads which map to certain region of reference

I have mapped reads to a reference genome of a related species. I want to remove reads which map to a specific region (chromosome) of the reference, but I don't know what the best way to go about it is. I'm doing variant calling, and I've been using the -t ^ option in bcftools call to exclude the relevant chromosomes, but does this target regions in the reference, or in the mapped reads? Is it the same thing? Is it better to do this during mpileup phase?

I feel completely lost and would appreciate an ELI5.

mapping reference genome

Not sure if this would help but samtools view now has the option

-L FILE, --target-file FILE, --targets-file FILE

    Only output alignments overlapping the input BED FILE [null]. 

You could create intervals for parts you want to keep.

1 answer

use bedtools complement to get the complement of your blacklisted.bed and then use samtools view -L complement.bed -O BAM -o out.bam in.bam

or use samtools view -M -L blacklisted.bed -O BAM --unoutput out.bam in.bam > /dev/null

Log in to answer this question.