Question: Error with Pysam tabix fetch
0
gravatar for always_learning
4.5 years ago by
Doha, Qatar
always_learning960 wrote:

Dear All,

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

here is a snippets 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 tabix python • 2.7k views
ADD COMMENTlink modified 4.5 years ago • written 4.5 years ago by always_learning960

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

ADD REPLYlink written 4.5 years ago by Pierre Lindenbaum118k
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 REPLYlink written 4.5 years ago by always_learning960
0
gravatar for Devon Ryan
4.5 years ago by
Devon Ryan88k
Freiburg, Germany
Devon Ryan88k wrote:

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

ADD COMMENTlink written 4.5 years ago by Devon Ryan88k

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

ADD REPLYlink written 4.5 years ago by always_learning960
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 988 users visited in the last hour