How to over come "TypeError: argument of type 'int' is not iterable" in python?
2
0
Entering edit mode
9.7 years ago
murali ▴ 110

Hi,

I am working on variant calling. My goal is to get the chromosome positions from vcf file and coverage on positive and negative strands. I am using pysam and pyvcf modules in python. While executing the python script it throws error TypeError: argument of type 'int' is not iterable.

I understand what it means. How can I overcome this error?

I need suggestions to succeed in dealing with this problem?

import vcf, glob, pysam, csv
from os.path import basename
pyvcf pysam python next-gen • 22k views
ADD COMMENT
1
Entering edit mode

Can you give a traceback of the error or at least the line number where it is occurring? It would be faster than to go through hundred-odd rows of your code manually.

P.S. you do not need semicolons at the end of the lines in python. in fact, that is considered bad style.

ADD REPLY
0
Entering edit mode

I still occasionally do that myself. I blame C :)

ADD REPLY
0
Entering edit mode

The error takes place at line 74.

elif ( i not in vcf_pos and i in pos):

Thanks for notifying me that about semicolon(;) at the end of line and I'll follow this suggestion from now on.

ADD REPLY
1
Entering edit mode

Can you highlight the line where the error is happening ?

ADD REPLY
0
Entering edit mode

The line number 74

elif ( i not in vcf_pos and i in pos):

is the line throws error.

ADD REPLY
0
Entering edit mode

I've put your code in a code block, which will hopefully help formatting a bit.

ADD REPLY
0
Entering edit mode

Thanks @Devon Ryan

ADD REPLY
3
Entering edit mode
9.7 years ago

Note that originally pos is a list, but later on you make it an integer (pos = 0)...

Edit: I'll add that modifying something that you're iterating over is generally a bad idea.

Edit2: You could just change the instances of pos that relate to positive counts to positive.

ADD COMMENT
0
Entering edit mode

Thanks @ Devon Ryan. Hurry, It worked. I have been working on this couple of days, finally find out the bug.

ADD REPLY
3
Entering edit mode
9.7 years ago

The problem is that the variable named pos is really an integer, as you define it in line 51:

pos = 0

This variable pos should be a list to make this if statement (elif ( I not in vcf_pos and I in pos):) to work. You mistakenly overwritten the variable pos from line 20.

pos = list(set(all_pos))
ADD COMMENT

Login before adding your answer.

Traffic: 2562 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