0

I have a list which contains the frame, start codon position, stop codon position, sequence of the gene, and gene length . Both sequence and length are based on the start and stop. I wanted to unpack this list and add frame, start/stop positions, sequence, and gene length for genes with a certain length to another list. My code is as follows:

for framenumber, startposition, stopposition, geneseq, genelength in range(len(codonpairsfwd)):
    if len(gene_seq) < 200:
        GenesToRemove_Fwd.append(framenumber)
        GenesToRemove_Fwd.append(startposition)
        GenesToRemove_Fwd.append(stopposition)
        GenesToRemove_Fwd.append(geneseq)
        GenesToRemove_Fwd.append(genelength)

and I get this error message: TypeError: cannot unpack non-iterable int object for the first line(i.e. line with for loop).

Any ideas where I might be going wrong would super appreciated

1
  • You are trying to get 5 values out of framenumber, startposition, stopposition, geneseq, genelength in range(len(codonpairsfwd)). This is not how range works. Have a look at the basics. If your list already includes at indice one a tuple of those 5 desired variable, then directly iterate over the list for v1, v2, v3, v4, v5 in L: Commented Mar 8, 2021 at 18:47

1 Answer 1

1

range() will list numbers (int) to loop, so you cannot unpack that number onto framenumber, startposition, stopposition, ... etc... as it's only an integer, starting from 0 and ends with len(codonparisfwd).

Sign up to request clarification or add additional context in comments.

5 Comments

what do you suggest I use? when I don't use range, I get the same error?
I dont know the structure of codonpairsfwd, but maybe: for framenumber, startposition, stopposition, geneseq, genelength in codonpairsfwd:
how does the data look like in codonpairsfwd ?
update the problem was that I needed a list of tuples instead to make up my codonpairsfwd list. (i.e. I had to append this variables together as a tuple when populating my list and append them as such when filtering my list!
You can iterate through a list of tuples like that: for x,y in [(1,2), (2,3)]: print(x, y)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.