biopython / biopython/biopython

Unable to parse a psl file produced by BLAT

Open
#4,196 10 comments 0 reactions 1 assignee Claimed by @bow View on GitHub
Dominant language
Python
Stars
5.2k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
11

Description

Hello,

I'm working on a program that runs BLAT between two files with protein sequences and parses the output psl file using Bio.SearchIO.BlatIO. I stumbled an issue where parsing the psl produces an exception because of assertion errors. Here's my setup and how to reproduce the bug.

### Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

```python
>>> import sys; print(sys.version)
3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0]
>>> import platform; print(platform.python_implementation()); print(platform.platform())
CPython
Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.29
>>> import Bio; print(Bio.__version__)
1.80
```

### Expected behaviour

Should be able to parse the psl file.

### Actual behaviour

The error message I get is:

```bash
Traceback (most recent call last):
File "test.py", line 5, in
for hit in parser:
File "/home/user/project/env/lib/python3.8/site-packages/Bio/SearchIO/BlatIO.py", line 428, in __iter__
for qresult in self._parse_qresult():
File "/home/user/project/env/lib/python3.8/site-packages/Bio/SearchIO/BlatIO.py", line 526, in _parse_qresult
hsp = _create_hsp(prev_hid, prev_qid, prev)
File "/home/user/project/env/lib/python3.8/site-packages/Bio/SearchIO/BlatIO.py", line 377, in _create_hsp
assert hsp.query_end == psl["qend"]
AssertionError
```
When I inspect the values of the hsp object and the psl dict, it seems that it may be some kind of off-by-one error.

**hsp**:
- query_start = 188
- query_end = 1073

**psl**:
- qstart = 188
- qend = 1072

UPDATE:
I think that the issue is that the `_is_protein` function return False. Probably I'm missing something, but I've executed blat with the `-prot` option.

### Steps to reproduce

I've narrowed down the hit that causes the issue and more specifically the exact line from the psl that seems to be responsible for the error.
Here's an example file that should cause the parsing to fail: [unparsable.psl](https://gist.github.com/mzdravkov/fbbc905419243ec9937896aeae547b94).
The line that causes the error is line 17 (the one indicated as match 829). If you remove this line, the parsing can complete successfully.

Here's a short snippet that reproduces the bug:

```python
from Bio.SearchIO.BlatIO import BlatPslParser

with open('unparsable.psl') as handle:
parser = BlatPslParser(handle)
for hit in parser:
print(hit)
```

Any help will be greatly appreciated.

Best regards,
Mihail Zdravkov

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.