samtools mpileup fails if .bam are differently ordered / headers are different

Open
#464 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c
Domain
cli

Research direction

Reproduce the two samtools mpileup commands using BAM files with the differing chromosome and header orders shown in the issue. Start at the mpileup entry point and determine why reversing the input order causes a segmentation fault; done means the command no longer crashes and the behavior is covered by a regression test or a clear diagnostic.

Written by the indexing model from the issue text.

Description

bug

I have two .bam files from Encode: ENCFF879HJE and ENCFF731VMU. They were sorted by different algorithms, thus chromosome order / headers are slightly different.
First command fails with Segmentation fault (core dumped) and exit code 139, while second works fine. Why is that?

samtools mpileup -r chr1:249230621 ENCFF879HJE.bam ENCFF731VMU.bam > /dev/null
samtools mpileup -r chr1:249230621 ENCFF731VMU.bam ENCFF879HJE.bam > /dev/null

Theirs headers are as follows:

  • ENCFF879HJE.bam
@HD     VN:1.4  SO:coordinate
@SQ     SN:chr10        LN:135534747
@SQ     SN:chr11        LN:135006516
@SQ     SN:chr12        LN:133851895
@SQ     SN:chr13        LN:115169878
@SQ     SN:chr14        LN:107349540
@SQ     SN:chr15        LN:102531392
@SQ     SN:chr16        LN:90354753
@SQ     SN:chr17        LN:81195210
@SQ     SN:chr18        LN:78077248
@SQ     SN:chr19        LN:59128983
@SQ     SN:chr1 LN:249250621
@SQ     SN:chr20        LN:63025520
@SQ     SN:chr21        LN:48129895
@SQ     SN:chr22        LN:51304566
@SQ     SN:chr2 LN:243199373
@SQ     SN:chr3 LN:198022430
@SQ     SN:chr4 LN:191154276
@SQ     SN:chr5 LN:180915260
@SQ     SN:chr6 LN:171115067
@SQ     SN:chr7 LN:159138663
@SQ     SN:chr8 LN:146364022
@SQ     SN:chr9 LN:141213431
@SQ     SN:chrM LN:16571
@SQ     SN:chrX LN:155270560
@SQ     SN:chrY LN:59373566
@PG     ID:bwa  PN:bwa  VN:0.7.12-r1039 CL:bwa sampe -n 10 -a 750 /net/lebowski/vol2/solexa_genomes/illumina/Homo_sapiens/UCSC/hg19/genom
e-sets/bwa-0.7.0/hg19 /tmp/3948300.1.all.q/R1.sai /tmp/3948300.1.all.q/R2.sai /tmp/3948300.1.all.q/trimmed.R1.fastq.gz /tmp/3948300.1.all
.q/trimmed.R2.fastq.gz
...
  • ENCFF731VMU.bam
@HD     VN:1.4  SO:coordinate
@SQ     SN:ERCC-00002   LN:1061
...
@SQ     SN:ERCC-00171   LN:505
@SQ     SN:chr1 LN:249250621
@SQ     SN:chr10        LN:135534747
@SQ     SN:chr11        LN:135006516
@SQ     SN:chr12        LN:133851895
@SQ     SN:chr13        LN:115169878
@SQ     SN:chr14        LN:107349540
@SQ     SN:chr15        LN:102531392
@SQ     SN:chr16        LN:90354753
@SQ     SN:chr17        LN:81195210
@SQ     SN:chr18        LN:78077248
@SQ     SN:chr19        LN:59128983
@SQ     SN:chr2 LN:243199373
@SQ     SN:chr20        LN:63025520
@SQ     SN:chr21        LN:48129895
@SQ     SN:chr22        LN:51304566
@SQ     SN:chr3 LN:198022430
@SQ     SN:chr4 LN:191154276
@SQ     SN:chr5 LN:180915260
@SQ     SN:chr6 LN:171115067
@SQ     SN:chr7 LN:159138663
@SQ     SN:chr8 LN:146364022
@SQ     SN:chr9 LN:141213431
@SQ     SN:chrM LN:16571
@SQ     SN:chrX LN:155270560
@SQ     SN:chrY LN:59373566
@PG     ID:Samtools     PN:Samtools     CL:perl tophat_bam_xsA_tag_fix.pl tophat_out/accepted_hits.bam | samtools view -bS - | samtools sort - mapped_fixed; samtools merge -h newHeader.sam merged.bam mapped_fixed.bam out/unmapped.bam        PP:Tophat       VN:VN:0.1.17 (r973:277)
...
Dominant language
C
Stars
950
Forks
475
Avg merge
3d 13h
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from samtools/htslib

All issues in samtools/htslib

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.