Description
Are you using the latest version of [samtools]
samtools 1.9
Using htslib 1.9
Please describe your environment.
- OS : Linux 4.4.0-130-generic
- machine architecture : x86_64
- compiler : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Please specify the steps taken to generate the issue, the command you are running and the relevant output.
I am just trying to convert a bam or sam into cram, however on at least 2 differents dataset I get a seg fault. The strange part is that it works otherwise with other datasets.
Here are the command I'm running :
bwa mem -t 100 contigs/contigs.fa Read_left.fastq Read_rigth.fastq 2>log | samtools view -T contigs/contigs.fa -C -F 4 - | samtools sort - > contigs.cram
After investigation, it is clearly the samtools view step which fail, so for instance
samtools view -C -T contigs/contigs.fa Test_sorted.bam > Test.cram
I found this link explaining I could launch gdb for more info :
https://www.biostars.org/p/96230/
So I ran gdb samtools and bt, and got theses infos :
Program received signal SIGSEGV, Segmentation fault.
__strncpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: No such file or directory.
#0 __strncpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
#1 0x000055555562e74d in string_ndup ()
#2 0x000055555562cd46 in sam_hdr_update ()
#3 0x0000555555622147 in cram_write_SAM_hdr ()
#4 0x00005555555def69 in sam_hdr_write ()
#5 0x0000555555563e95 in main_samview ()
#6 0x00007ffff698c830 in __libc_start_main (main=0x55555555a910
fini=, rtld_fini=, stack_end=0x7fffffffd918) at ../csu/libc-start.c:291
#7 0x000055555555b012 in _start () at ../sysdeps/x86_64/elf/start.S:103
My files are a bit big ~ around 50G of bam and I'd rather not share them too. I can try to build a minimal example but maybe this info is sufficient for you to help me?
Activity
jkbonfield commentedon Jun 18, 2019
How large is the SAM header? Or maybe easier to answer, how many contigs are there in your contigs.fa file? I'm wondering if it's gone beyond the 2GB size limit. It shouldn't crash, but it's also probably not something we've stress tested before.
Also note your command line isn't doing what you think it is:
The
samtools sortwill be outputting BAM (to a file called contigs.cram). You either needsort -O cramto specify the output format or usesort -o contigs.cramto specify the output file without a shell redirect in which case it'll also select the appropriate format.jkbonfield commentedon Jun 18, 2019
I managed to reproduce this by generating a SAM header with 40 million lines, but no M5 strings, and then converting this to CRAM. The crash was simply because it rather sloppily used "int" type instead of size_t and overflowed.
The good news is that particular bug has been fixed in the new header API (samtools/htslib#812) although I haven't yet tested whether it works. It may still fail due to the size of a CRAM block going over 2Gb. I'm unsure if we can handle that yet. (The same is probably true for BAM too, but it doesn't need the M5 tags so you can get away with a smaller header.)
For now, I think you may just need to stick with BAM until we fix this.
Sebastien-Raguideau commentedon Jun 18, 2019
Hi Thanks, for the thorough answer.
I'll will stick to bam which, it seems, I'm already doing :)