f1 = pysam.VariantFile("test.vcf.gz")
for f in f1.fetch(str(chr), int(start), int(end)):
if f:
print "yes"
else :
print "hello"
In the above example Its not printing "hello" even for cases which doesn't have entry into VCF. I want to print program "hello" for cases where VariantFile doesn't have variants records.
Its their a way to do this ?
Thanks
Try:
instead of the
for
loop.Thanks Ryan, Its not working. I tried this earlier as well.
What do you get if you print
f
for positions which are not in the vcf?Its not going inside else condition.
There shouldn't be an
else
condition, since there shouldn't be afor
loop in this case in question.And looking at how
f
looks like doesn't depend on if else statement, you just need to now what fetch returns for a position you think isn't included in the vcf.Even this is not working as well.
What do you get if you print
f1.fetch(str(chr), int(start), int(end))
for positions which are not in the vcf?Reagrdless of absence or present its proting iterator object. I checked for object condition as well but no luck.
The TabixIterator is always
True
, regardless of precense or absence of that variant.yes and Thats why its never going to else condition.
Exactly. What are you trying to achieve? This issue probably has a better solution.
you means other ways Using Pysam ?