Reputation: 73
I have asked a similar question before, but here's a slightly different problem I'm encountering after fixing some previous issues:
There are two txt files that are structured similarly into columns. File 1 has the following columns: tagname1, aapos, synonymous; and file 2 has the following: tagname2, aapos1, aapos2. What I want to do is compare every single tagname1 in file 1 to every single tagname2 in file 2 and see if they match. For every single match, I want the program to then check if the aapos value corresponding to that specific tagname1 falls betweeen aapos1 and aapos2, as stated by my second if statement. If after going through all of file 2, it is unable to find a match for aapos, ONLY then do I want to execute the following if statements and check if synonymous in file 1 is equal to 0 or 1 and add 1 to syn2 or nonsyn2, depending on the case. The same applies if for a specific tagname1, the program goes through the entire list of tagname2 in file 2, and is unable to find a match.
However, according to my code, the program only runs once and I get a value of 1 for snps and a value of one for nonsyn2. I'm not sure why this is the case.
for x in range(1,15):
flag = 0
snps = 0
for b in range (1,15):
if tagname1[x]== tagname2[b]:
flag = 1
if int(aapos1[b]) <= int(aapos[x])<= int(aapos2[b]):
snps = snps + 1
if snps == 0:
if int(synonymous[x]) == 0:
nonsyn2 = nonsyn2 + 1
elif int(synonymous[x]) == 1:
syn2 = syn2 + 1
elif flag == 0:
if int(synonymous[x]) == 0:
nonsyn2 = nonsyn2 + 1
elif int(synonymous[x]) == 1:
syn2 = syn2 + 1
Upvotes: 0
Views: 96
Reputation: 1711
Are you sure you mean to break in the lower if statements?
eg:
if int(synonymous[x]) == 0:
nonsyn2 = nonsyn2 + 1
break
These are within the first for loop (for x in range(1,15):) so if one of these conditions is met you will be dropped out of the loop.
If this happens on your first loop, it might be why you only see it run once.
I'm not entirely sure I understand what your trying to do, but the keyword 'continue' might be what you want. It will make the program go to the next iteration of your loop.
Upvotes: 2