Error with Pysam tabix fetch
1
0
Entering edit mode
9.6 years ago
always_learning ★ 1.1k

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 • 5.4k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
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.
ADD REPLY
0
Entering edit mode
9.6 years ago

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2968 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6