Question: How to over come "TypeError: argument of type 'int' is not iterable" in python?
0
gravatar for murali
5.0 years ago by
murali100
Germany
murali100 wrote:

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 does it mean. 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
pysam next-gen pyvcf python • 15k views
ADD COMMENTlink modified 5.0 years ago • written 5.0 years ago by murali100
1

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 REPLYlink modified 5.0 years ago • written 5.0 years ago by Saulius Lukauskas530

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

ADD REPLYlink written 5.0 years ago by Devon Ryan94k

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 REPLYlink written 5.0 years ago by murali100
1

Can you highlight the line where the error is happening ?

ADD REPLYlink written 5.0 years ago by geek_y10k

The line number 74 (

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

) is the line throws error. 

ADD REPLYlink modified 5.0 years ago • written 5.0 years ago by murali100

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

ADD REPLYlink written 5.0 years ago by Devon Ryan94k

Thanks @Devon Ryan

ADD REPLYlink written 5.0 years ago by murali100
3
gravatar for Devon Ryan
5.0 years ago by
Devon Ryan94k
Freiburg, Germany
Devon Ryan94k wrote:

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 COMMENTlink modified 5.0 years ago • written 5.0 years ago by Devon Ryan94k

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

ADD REPLYlink written 5.0 years ago by murali100
3
gravatar for a.zielezinski
5.0 years ago by
a.zielezinski9.1k
a.zielezinski9.1k wrote:

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 COMMENTlink modified 5.0 years ago • written 5.0 years ago by a.zielezinski9.1k
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: 1198 users visited in the last hour