Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generating and Spliting tsv in python
import sys
import random
f = open(sys.argv[1], "w")
f.write("OTU\tT5_300\tT5_250\tT5_160\n")
for i in range(0, 1000):
f.write("Otu")
f.write(str(random.randint(1,2000)))
f.write("\t");
f.write(str(random.randint(1,2000)))
f.write("\t");
f.write(str(random.randint(1,2000)))
f.write("\t");
f.write(str(random.randint(1,2000)))
f.write("\n")
f.close()
import sys
upper = ''
lower = ''
name = sys.argv[1]
f = open(name, "r")
header = f.readline()
upper += header
lower += header
for line in f:
columns = line.split("\t")
value = int(columns[1])
if value > int(sys.argv[2]):
upper += line
else:
lower += line
f.close()
f = open(name + "_upper.txt", "w")
f.write(upper)
f.close()
f = open(name + "_lower.txt", "w")
f.write(lower)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.