This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Generate A Subset Of Bam Or Reads Based On Vcf

Generate a subset of BAM or reads based on VCF

After mapping, I am interested in extracting a subset of bam or reads with certain genoytpes. Could you please advise me some efficient ways to do this?

Thanks in advance!

vcf bam

2 answers

loop over each mutation and extract the subset of BAM using samtools view in.bam chr:start-end

If two different genotypes are in the same positon, this method cannot distinguish them.

Via BEDOPS and bash substitution:

$ bedops -e 1 <(bam2bed < reads.bam) <(vcf2bed < variants.vcf) > reads_overlapping_variants.bed

Log in to answer this question.