have code snippet.any ideas?


for clust in clusters: #for each name in a list of names i have
outNM = "fam" + str(count) + ".mcl.fas" #a series of files i want written to
outFL = open(outNM, 'a')

for c in clust: #for each letter in my list of names that i have
c = c.rstrip()

for c in clust:
outFL.write(">" + dict[c] + "\n") write each name to my file i have open.

but it doesnt want to work.

have code snippet.any ideas?


for clust in clusters: #for each name in a list of names i have
outNM = "fam" + str(count) + ".mcl.fas" #a series of files i want written to
outFL = open(outNM, 'a')

for c in clust: #for each letter in my list of names that i have
c = c.rstrip()

for c in clust:
outFL.write(">" + dict[c] + "\n") write each name to my file i have open.

but it doesnt want to work.

Can you clarify what isn't working? I'm going to take a wild guess and say that dict[c] is failing for "c" not being in the dictionary. In your first for loop you say c = c.rstrip() but then you don't save the updated c back to clust for the next for loop. What you should do is just a single for loop like this:

for c in clust:
	outFL.write(">" + dict[c.rstrip()] + "\n")

See if that helps. There are other ways to improve your code (like don't name your dictionary dict as that's a reserved word in Python), but that's for another discussion

This article has been dead for over six months. Start a new discussion instead.