This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error with Pysam tabix fetch

Dear All,

I am trying to us pysam for one of my scripts.

Here is a snippet of the code.

tabixfile = pysam.Tabixfile(vcf_dir_file)
for i in snp_pos:
        (chrom, snp) = i.split(" ")[0], i.split(" ")[1]
        val = int(snp)-1
        chrom = "'" + chrom + "'"
        for vcf in tabixfile.fetch(str(chrom), val, int(snp)):
                print vcf

Here snp_pos is an array of likewise of chr1 snp_position

When I am running this scripts then geting error here with tabixfile.fetch(str(chrom), val, int(snp)): part.

Error is : File "lowFrequency_impro.py", line 55, in <module>
    for vcf in tabixfile.fetch(str(chrom), val, int(snp)):
  File "ctabix.pyx", line 353, in pysam.ctabix.Tabixfile.fetch (pysam/ctabix.c:4318)
ValueError: could not create iterator for region ''chr1':774047-774047'`

But if I try to run same snippets at python terminal the I can able to run and get correct results with position 774047 as below then

>>> for gtf in tabixfile.fetch('chr1', 752565, 752566):
...     print gtf

I am wondering that what could be the error here and possible solution !! Please help me on this !! Its bit urgent too..

pysam python tabix

what are those quotes in ''chr1':774047-774047' ? are you sure about chr1 (and not only '1' )

Yaa, I am sure about chr1. 774077 is position on chromosome 1. You may see above that i can able to get result for same position while using python terminal but not not able to get within loop.

1 answer

What happens if you remove the chrom - "'" + chrom + "'" line? I imagine that that's breaking things.

Thanks !! After removing chrom - "'" + chrom + "'", it worked !! Thanks again!

Log in to answer this question.