I have this rs.txt file containing:
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG rs41367249=AG (312, 0.207447)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG rs41444944=AG (310, 0.206117)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG (422, 0.280585)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41483646=AG (384, 0.255319)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41369844=AG rs235633=CT (301, 0.200133)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41369844=AG (396, 0.263298)
rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41440845=CT (384, 0.255319)
Can anyone help me with python codes to remove the numbers in the brackets? I just want the rs# to be saved in a new .txt file. Thanks.
How about
line = line.split("(")[0]
(everything preceding the first (
character)
so your program is something like
with open("rs.txt") as inf, open("new.txt", "w") as outf:
for line in inf:
line = line.split("(", 1)[0].rstrip() + "\n"
outf.write(line)