This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to over come "TypeError: argument of type 'int' is not iterable" in python?

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

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.

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

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.

Can you highlight the line where the error is happening ?

The line number 74

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

is the line throws error.

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

Thanks @Devon Ryan

2 answers

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.

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

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))

Log in to answer this question.