Entering edit mode
6.2 years ago
O.rka
▴
740
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
Hello O.rka ,
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.
for
statement. So thetry
/except
block inside the loop is to late. It must be outside.fin swimmer