mdshw5 / pyfaidx

Efficient pythonic random access to fasta subsequences
https://pypi.python.org/pypi/pyfaidx
Other
449 stars 75 forks source link

Support zero-length sequences #155

Closed prihoda closed 4 years ago

prihoda commented 4 years ago

Add support for zero-length sequences.

Example FASTA file:

>A
ABC
>B
>C

>D
DEF
GH

Result: ['ABC', '', '', 'DEFGH']

Also enables slicing sequences to zero length, which corresponds to slicing python lists:

from pyfaidx import Fasta
a = Fasta('example.fa')[0]
print(a[0:])
# >A:1-3
# ABC
print(a[100:]
#>A:101-101
#

Please review all the changes, I tested on an example dataset but I cannot be sure that this will always work.

prihoda commented 4 years ago

Fixes https://github.com/mdshw5/pyfaidx/issues/93

mdshw5 commented 4 years ago

I'll take a look today. On first glance this makes sense, and I'll add at least one test case before merging.

mdshw5 commented 4 years ago

It looks like this change not only fixes #93, but it doesn't break existing tests either. Great job @prihoda!. I'll merge and tag a new version (0.5.6) which will push to PyPI within the next hour.