How to ignore truncation error with PySam?
0
0
Entering edit mode
5.5 years ago
O.rka ▴ 710

I want to extract some info from these sam files and ignore the truncation errors. I tried using ignore_truncation=True but it didn't work.

How can I catch this error and let it continue?

In [4]:
   ...: path_input = "./bbmap_output/1065.1/output.sam"
   ...: with pysam.AlignmentFile(path_input, ignore_truncation=True) as f:
   ...:     for i, segment in enumerate(f):
   ...:         try:
   ...:             pass
   ...:         except OSError:
   ...:             print(i, segment)
   ...:
[E::sam_parse1] SEQ and QUAL are of different length
[W::sam_read1] Parse error at line 7555317
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-f8c90b65a160> in <module>()
      2 path_input = "./bbmap_output/1065.1/output.sam"
      3 with pysam.AlignmentFile(path_input, ignore_truncation=True) as f:
----> 4     for i, segment in enumerate(f):
      5         try:
      6             pass

pysam/libcalignmentfile.pyx in pysam.libcalignmentfile.AlignmentFile.__next__()

OSError: truncated file
pysam sam alignment mapping python • 2.6k views
ADD COMMENT
0
Entering edit mode

Hello O.rka ,

  • Why do you want to do this?
  • The ignore_truncation isn't do what you are thinking. From the manual: Issue a warning, instead of raising an error if the current file appears to be truncated due to a missing EOF marker. Only applies to bgzipped formats.
  • The error arises during the for statement. So the try/except block inside the loop is to late. It must be outside.

fin swimmer

ADD REPLY

Login before adding your answer.

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