#!/usr/bin/env python #get_go_names.py is a script for retrieving Gene Ontology #terms for Gene Ontology ids #Copyright (C) 2007 Daniel Shriner #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #The text of the GNU General Public License, version 2, is available #as http://www.gnu.org/copyleft or by writing to the Free Software #Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import sys,gzip,os names = {} #Load the gene2go file try: f1 = gzip.open('gene2go.hs.09May06.gz','rb') except IOError: print >> sys.stderr, 'Error opening gene2go file.\n' sys.exit(1) while 1: line = f1.readline() if not line: break line = line.split('\t') names[line[2]] = line[5] f1.close() #Open the input file of weights try: f2 = open('adj_weights.txt','r') except IOError: print >> sys.stderr, 'Error opening weights file.\n' sys.exit(1) #Open an output file for printing out GO names try: f3 = open('adj_weights_names.txt','w') except IOError: print >> sys.stderr, 'Error opening output file.\n' sys.exit(1) while 1: line = f2.readline() if not line: break line = line.split('\t') line[0] = line[0].split('"') line[1] = line[1][:-1] line[1] = line[1].split('"') print >> f3, '%s\t%s\t%s' % (line[0][1],line[1][1],names.get(line[0][1])) f2.close() f3.close() os.remove('adj_weights.txt') os.rename('adj_weights_names.txt','adj_weights.txt')