Hi all, I have a problem with reheadering a bam file which I subsetted before. I mapped against a merged genome of human and mouse (since it is a patient derived xenograft sample) and want to remove residual mouse reads. I did this with samtools (version 1.8) by simply subsetting for the human chromosomes.
samtools view -b mybam.bam chrM chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrX chrY > no-mouse.bam
I want to remove the mouse chromosomes from the header by removing the respective lines from the header with sed (there are also some ERCCs etc. in the reference, which is why I have to remove so many lines) and reheadering the bam afterwards.
samtools view -H no-mouse.bam | sed '27,253d' | samtools reheader - no-mouse.bam > no-mouse.rehead.bam
I end up with a truncated bam file, if I want to look at e.g. the end of the file with
samtools view no-mouse.rehead.bam | tail
[main_samview] truncated file.Following steps (e.g. AddOrReplaceReadGroups) give errors as well.
I've seen some posts on similar topics but din't find any helpful solution unfortunately.
Can somone help me with that? Thanks a lot!