No @hd header returned in sam file when running bwa mem
2
0
Entering edit mode
17 months ago
MboiTui ▴ 20

Hello,

I produced sam files with the below command:

bwa mem -M -t 10\
    IndexedReference\
    ${sample}_R1.fastq.gz ${sample}_R2.fastq.gz\
    2> ${sample}_bwa.err > ${sample}.sam`

The resulting sam file doesn't have an @hd header. Example output of samtools view:

samtools view -H ${sample}.sam | head -n 5
@SQ SN:scaffold_1   LN:344421834
@SQ SN:scaffold_2   LN:300751346
@SQ SN:scaffold_3   LN:273662429
@SQ SN:scaffold_4   LN:261171726
@SQ SN:scaffold_5   LN:224480160

samtools view -H ${sample}.sam | tail -n 3
@SQ SN:Mitogenome   LN:18666
@PG ID:bwa  PN:bwa  VN:0.7.17-r1188 CL:bwa mem -M -t 10 4_align2genome/4_0_assembly/LitHap1 2_fastp/Lit01_L001_R1_trimmed.fastq.gz 2_fastp/Lit01_L001_R2_trimmed.fastq.gz
@PG ID:samtools PN:samtools PP:bwa  VN:1.16.1   CL:samtools view -H 4_align2genome/4_1_aligned/Lit01_L001.sam

As you can see there is no @HD header in the first line. This causes issues with ANGSD:

-> Inputtype is BAM/CRAM
-> We require a proper header starting with @HD for ANGSD
-> We observed: '@SQ    SN:sca' will exit

How can I get bwa mem to output the @HD file? I'd prefer this than having to add it manually.

bwa version 0.7.17
samtools version 1.16.1
angsd version 0.940

Cheers,
L

samtools bam bwa • 1.2k views
ADD COMMENT
2
Entering edit mode
17 months ago
GokalpC ▴ 100

Your sam file is not coordinate sorted or converted to a bam. @HD tags come after a secondary tool such as samtools view or sort.

ANGSD page specifically mentions that bam files must be coordinate sorted.

These are required do be sorted according to reference.
ADD COMMENT
2
Entering edit mode
17 months ago

the HD header is not generated by bwa, but you can add it using awk:

bwa (...) |  awk '(NR==1) {printf("@HD\tVN:1.6\tSO:unknown\n");}{print}' 

Theres's a PR about this: https://github.com/lh3/bwa/pull/336 , but sadly, all the PR have been ignored for years.

ADD COMMENT

Login before adding your answer.

Traffic: 1611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6