This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Artificial deletion in bam

Hi everyone,

is there a way to introduce a specific artificial deletion in a bam file? I'm searching something that take a particular interval of coordinates and remove it from the bam file e.g. chrx:3122135-3425222

bam

A bam file is a representation of (typically) sequencing reads mapped against a reference genome. Is is not clear what you want. Do you want for the reference genome to have the deletion? Or do you want to remove the reads mapping to that region?

Forgive me if I wasn't very clear, I mean that I would need to remove the reads that map a certain chromosomal interval from the bam file. I need these samples with the artificial deletions to test a tool I'm developing.

2 answers

Forgive me if I wasn't very clear, I mean that I would need to remove the reads that map a certain chromosomal interval from the bam file.

samtools view  -L deletions.bed  -O BAM --unoutput output.bam in.bam > /dev/null

Thanks, I'll start with this! unfortunately the deletion in question is hemizygous and therefore I have to find a way that partially removes the reads and not all of them

e I have to find a way that partially removes the reads and not all of them

split your bam with

samtools view   --subsample 0.5  -O BAM --unoutput output1.bam -o output2.bam in.bam 

remove reads with deletion from output2.bam

and then samtools merge with output1.bam and output2.with_del.bam

If you just want to remove the reads, it's relatively easy.

If you want to simulate a truncation, this is difficult, because you will need to modify instead of remove the reads so they can cross both breakpoints of a truncation.

Log in to answer this question.