Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch a chromosome on a FastaVariant which is not part of the vcf raises an error #179

Closed
lldelisle opened this issue Oct 20, 2021 · 2 comments

Comments

@lldelisle
Copy link
Contributor

I noticed that when I try to fetch a chromosome which is not part of the vcf on a FastaVariant I get an error:

~/.venvPyfaidx/lib/python3.7/site-packages/pyfaidx/__init__.py in __iter__(self)
    837             end = start + line_len
    838             if end < len(self):
--> 839                 yield self[start:end]
    840             else:
    841                 yield self[start:]

~/.venvPyfaidx/lib/python3.7/site-packages/pyfaidx/__init__.py in __getitem__(self, n)
    821                 if start < 0:
    822                     start = len(self) + start
--> 823                 return self._fa.get_seq(self.name, start + 1, stop)[::step]
    824 
    825             elif isinstance(n, integer_types):

~/.venvPyfaidx/lib/python3.7/site-packages/pyfaidx/__init__.py in get_seq(self, name, start, end)
   1164             seq_mut = list(seq.seq)
   1165             del seq.seq
-> 1166         var = self.vcf.fetch(name, start - 1, end)
   1167         for record in var:
   1168             if record.is_snp:  # skip indels

~/.venvPyfaidx/lib/python3.7/site-packages/vcf/parser.py in fetch(self, chrom, start, end)
    629             chrom = chrom[3:]
    630 
--> 631         self.reader = self._tabix.fetch(chrom, start, end)
    632         return self
    633 

pysam/libctabix.pyx in pysam.libctabix.TabixFile.fetch()

ValueError: could not create iterator for region 'MT:1-60'

I propose a fix in a PR.

@lldelisle
Copy link
Contributor Author

Versions used:

(.venvPyfaidx) [ldelisle@helvetios X]$ python --version
Python 3.7.7
(.venvPyfaidx) [ldelisle@helvetios X]$ pip list | grep pyfaidx
pyfaidx           0.6.2 

Also obtained with python 3.9.7. A minimal test to see it is in the PR #180

@mdshw5
Copy link
Owner

mdshw5 commented Nov 3, 2021

Fixed in #180

@mdshw5 mdshw5 closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants