Created
October 19, 2013 15:49
-
-
Save crazyhottommy/7057625 to your computer and use it in GitHub Desktop.
crazyhottommy's Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script reformats the tab delimited file like: | |
#FBgn00001 GO:0016301 [Name:****(annotation)] | |
#FBgn00002 GO:0016301 [Name:****(annotation)] | |
#FBgn00003 GO:0016301 [Name:****(annotation)] | |
#FBgn00004 GO:0003700 [Name:****(annotation)] | |
#FBgn00004 GO:0009651 [Name:****(annotation)] | |
#FBgn00004 GO:0006355 [Name:****(annotation)] | |
#FBgn00005 GO:0009556 [Name:****(annotation)] | |
#FBgn00005 GO:0005515 [Name:****(annotation)] | |
#FBgn00005 GO:0080019 [Name:****(annotation)] | |
#FBgn00005 GO:0016563 [Name:****(annotation)] | |
#FBgn00005 GO:0016627 [Name:****(annotation)] | |
#FBgn00006 GO:0003700 [Name:****(annotation)] | |
#FBgn00006 GO:0010018 [Name:****(annotation)] | |
# to: | |
# FBgn00001 GO:0016301 | |
#FBgn00002 GO:0016301 | |
#FBgn00003 GO:0016301 | |
#FBgn00004 GO:0003700 GO:0009651 GO:0006355 | |
#FBgn00005 GO:0009556 GO:0005515 GO:0080019 GO:0016563 GO:0016627 | |
#FBgn00006 GO:0003700 GO:0010018 | |
import csv | |
reader = csv.reader(open("GO.txt","r"), delimiter="\t") | |
new={} | |
for row in reader: | |
if row[0] not in new.keys(): | |
new[row[0]] = [row[1]] | |
else: | |
new[row[0]].append(row[1]) | |
with open("wego.txt","w") as f: | |
for key, value in sorted(new.items()): | |
f.write(key+"\t"+"\t".join(value)+"\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment