I am not sure if it is iterating through the list or being called multiple times... in either case it shouldn't be doing either of those things. I am pretty new to python and programming in general. Here is the function:
"""
Gets the mass that may have an isotope of +1 neutron for C,N or O (if there is one)
@param mass the mass
@return the mass +1
"""
def getMassPlus(mass):
if (mass)+1 in mass_old2:
return (mass)+1
elif (mass)+1.1 in mass_old2:
return (mass)+1.1
elif (mass)+1.2 in mass_old2:
return (mass)+1.2
elif (mass)+.9 in mass_old2:
return (mass)+.9
and here is the function call:
if ((14.00674*multiplyByN)+(15.994915*multiplyByO)+(1.00794*multiplyByH)) == isotope_masses[i]+.5 or isotope_masses[i]-.5:
if isotope_masses[i]+1 or isotope_masses[i]+1.1 or isotope_masses[i]+1.2 or isotope_masses[i]+.9 in mass_old2:
nextMass = getMassPlus(isotope_masses[i])
What happens is that when I call the function, it somehow iterates through the list isotope_masses (which looks like this: isotope_masses = [1,2,3,4,...]) ten times and assigns nextMass ten values as well. It might also help you to know that the second block of code is part of a larger loop that iterates through the length of isotope_masses. I am not really sure why this issue happening, any ideas would be appreciated. Thanks in advance.
Loop:
for i in range(len(isotope_masses)):
if not noNitrogen(molecules[i]): #molecule has nitrogen and possibly hydrogen
if hasDoubleDig('N'):
multiplyByN = int(molecules[i][3:5])
multiplyByH = int(molecules[i][8:])
else:
multiplyByN = int(molecules[i][3])
multiplyByH = int(molecules[i][7:])
if ((14.00674*multiplyByN)+(1.00794*multiplyByH)) == isotope_masses[i]+.5 or isotope_masses[i]-.5:
if isotope_masses[i]+1 or isotope_masses[i]+1.1 or isotope_masses[i]+1.2 or isotope_masses[i]+.9 in mass_old2:
nextMass = getMassPlus(isotope_masses[i])
if float(intensities[mass_old2.index(nextMass)])/float(intensities[mass_old2.index(isotopes_masses[i])]) == multiplyByN * .00364:
file_isotopes.append("Isotope: is N-15")
else:
file_isotopes.append("Mix of isotopes")
elif not noCarbon(molecules[i]): #molecule has carbon and possibly hydrogen
if hasDoubleDig('C'):
multiplyByC = int(molecules[i][1:3])
multiplyByH = int(molecules[i][8:])
else:
multiplyByC = int(molecules[i][1])
multiplyByH = int(molecules[i][7:])
if ((12.0107*multiplyByC)+(1.00794*multiplyByH)) == isotope_masses[i]+.5 or isotope_masses[i]-.5:
if isotope_masses[i]+1 or isotope_masses[i]+1.1 or isotope_masses[i]+1.2 or isotope_masses[i]+.9 in mass_old2:
print isotope_masses[i]
nextMass = getMassPlus(isotope_masses[i])
if float(intensities[mass_old2.index(nextMass)])/float(intensities[mass_old2.index(isotope_masses[i])]) == multiplyByC * .0107:
file_isotopes.append("Isotope is: C-13")
else:
file_isotopes.append("Mix of isotopes")
There is more to the loop but its just repetitive so I only gave two cases in the loop for the sake of brevity.