brentp / bwa-meth

fast and accurate alignment of BS-Seq reads using bwa-mem and a 3-letter genome
https://arxiv.org/abs/1401.1129
MIT License
139 stars 53 forks source link

'samtools' errors aren't reported in 'as_bam' #7

Closed superbobry closed 9 years ago

superbobry commented 10 years ago

Errors, raised by samtools view ... | samtools sort ... aren't reported, due to the buffering of sys.stderr. In my case the error was:

[samopen] SAM header is present: 25 sequences.
Parse error at line 31: sequence and quality are inconsistent

Instead of outputting the error bwa-meth printed the following traceback:

Traceback (most recent call last):
  File "/home/user/.virtualenvs/env/bin/bwameth.py", line 10, in <module>
    execfile(__file__)
  File "/home/user/.virtualenvs/env/src/bwameth-head/bwameth.py", line 596, in <module>
    main(sys.argv[1:])
  File "/home/user/.virtualenvs/env/src/bwameth-head/bwameth.py", line 581, in main
    set_as_failed=args.set_as_failed)
  File "/home/user/.virtualenvs/env/src/bwameth-head/bwameth.py", line 259, in bwa_mem
    as_bam(cmd, fa, prefix, calmd, set_as_failed)
  File "/home/user/.virtualenvs/env/src/bwameth-head/bwameth.py", line 296, in as_bam
    out.write(str(aln) + '\n')
IOError: [Errno 32] Broken pipe

The traceback makes perfect sense, because after reporting the error samtools exited and the file descriptor behind out became stale. However, the original error is much more helpful.

I'm ready to submit a patch for this.