Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
44 lines (35 sloc) 1.47 KB
outfile = open('', 'w')
# The input file format (tab delimited) is: Chromosome Position FST
# a function to modify the 3rd column to be 0 if the value is a number and is less than 0
def ChangeNegativeFst(line):
# split on tabs
SNPdata = line.split('\t')
# check the length of the line (we obviously need 3 elements if we're going to operate on the 3rd element)
if len(SNPdata) >= 3:
# Make sure the third element is either an integer or a float
FST = int(SNPdata[2])
except ValueError:
FST = float(SNPdata[2])
except ValueError:
# the question 'is it less than zero' is asked and if so, the value of the 3rd word is replaced with '0'.
if FST <= 0:
SNPdata[2] = "0\n"
except NameError:
# return the line with a tab separating each word
return '\t'.join(SNPdata)
# tell python "the program starts here".
# The program starts executing near the bottom because you have to have all your functions 'seen' by the interpreter before you can call them.
# All functions or classes have to be above this point.
if __name__ == "__main__":
filename = ""
with open(filename,"r") as theFile:
for line in theFile:
line = ChangeNegativeFst(line)