Entering edit mode
17 months ago
sam
▴
30
Hi,
I have a few bam files after mapping using Bowtie2.
I want to extract the multi-mapped reads from these bam files. For doing so I used the following command:
samtools view -h $fq | grep -E "^\@|XS:i" | grep "NM:i:0" > multimapped_1.bam
To add the header I used the following command, I ran the following commands:
samtools view -H bamfile > $header_bam
samtools reheader $header_bam multimapped_1.bam
Now I wanted to merge the bam files together. However, while merging I get the following error:
[E::sam_parse1] missing SAM header
[W::sam_read1] Parse error at line 1
[main_samview] truncated file.
It seems the header is not added.
I also tried the following command:
samtools view -h $fq | grep -E "^\@|XS:i" | grep "NM:i:0" | samtools view -bS - > multimapped_1.bam
However, this produced a bam file that was less than 77 kb in size.
Looking forward to any suggestions.
Thank you!
Thank you Pierre! Should i split the single command into two and i use
Is this correct?
no, please read the manual.
Hi again. I do not see -e option in samtools v1.9. Thanks!
your version of samtools is just too old.
I have now updated to version v1.17. Thanks for notifying that.
Thanks Pierre! Figured it out!