Samtools sort error: [pretty_header] invalid header
1
0
Entering edit mode
18 months ago
Ondina ▴ 100

Hello,

I want to convert my .sam files into .bam files with Samtools. Samtools view functioned well, here's my code: (My sam files have the @ indicator, indicating the header. If I use head on my files:

@SQ SN:NC_000067.7  LN:195154279  
@SQ SN:NT_166280.1  LN:169725  
@SQ SN:NT_166281.1  LN:241735  
@SQ SN:NT_166282.1  LN:153618 )  

  ls *.sam | parallel 'samtools view -bS {} > /media/bam_files/v2/{.}.bam -@ 15'

When I try to use samtools sort, it's stuck on the pretty header part, here the command line:

samtools sort aln-pe_RNA-Exo-Mouse-F1_S1.bam -o aln-RNA_EXO-Mouse-F1_S1.sorted.bam

Error obtained:

[bam_sort_core] merging from 45 files...  
[pretty_header] invalid header

Here's my version of samtools:

samtools --version
samtools 1.1  
Using htslib 1.1  
Copyright (C) 2014 Genome Research Ltd.  

Installed through conda.

How can I correct this error? Is something wrong with my code?

sam RNA-seq bam samtools • 984 views
ADD COMMENT
1
Entering edit mode
18 months ago
ATpoint 86k

First of all your samtools in ancient, almost 10 years old. Also, one would need to see the alignment command. Did you somehow modify the sam?

These days one should use pipes, for example as below, and never store sams as they're big and useless as not compressed. bam is the format to use downstream. You could replace view by sort right away, too.

bwa mem (...) | samtools view -o out.bam
ADD COMMENT
0
Entering edit mode

First of all your samtools in ancient, almost 10 years old. Also, one would need to see the alignment command. Did you somehow modify the sam?

I'm aware of it but conda doesn't seem to want to upgrade it more, maybe I should install it manually.

Here's my alignment command with BWA:

bwa mem reference/ncbi-genomes-2023-05-16/mm39bwaidx RNA-Exo-Mouse-[...]_R1_001.fastq.gz RNA-Exo-Mouse-[...]_R2_001.fastq.gz > sam_files/aln-pe_RNA-Exo-Mouse-[...].sam

I have 12 fastq files, they're paired end. I didn't modified the sam at all, it's how it was generated by bwa.

I confess I only used bwa and samtools once during a course but it's been a while, I probably messed up somewhere.

These days one should use pipes, for example as below, and never store sams as they're big and useless as not compressed. bam is the format to use downstream. You could replace view by sort right away, too.

Okay, thank you for your recommendations!

ADD REPLY
1
Entering edit mode

I've updated samtools to

samtools 1.17
Using htslib 1.17

I'll keep you updated to see if the error still occurs

ADD REPLY
1
Entering edit mode

Your ~/.condarc file should look like:

channels:
  - conda-forge
  - bioconda
  - defaults

That's the recommended order of channels for conda to get software well-going. This compensates the problem of samtools not upgrading properly.

ADD REPLY
1
Entering edit mode

Perfect, I updated the .condarc file, indeed I didn't had any order setted up on my environnement so that's why it failed. Thank you!

So, I used samtools 1.17 and I don't have the error anymore. The old version was the problem.

Now I'm regenerating the raw .bam files with the new version.

ADD REPLY

Login before adding your answer.

Traffic: 1719 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