Beispiel #1
0
	def output(self, curs, outf, known_gene_no2p_gene_id_src, unknown_gene_no2p_gene_id_src, p_gene_id_src_map):
		"""
		03-03-05
			loop over gene_no2p_gene_id_src and p_gene_id_src_map
		03-13-05
			add a column, #clusters in the output file
			
			--output_one_gene()
			--output_function_group()
		"""
		#three dictionaries
		gene_no2gene_id = get_gene_no2gene_id(curs)
		gene_no2direct_go = get_gene_no2direct_go(curs)
		go_no2go_id = get_go_no2go_id(curs)
		go_no2name = get_go_no2name(curs)
		go_no2accuracy, go_no2accuracy_pair = self.get_go_no2accuracy(curs, self.p_gene_table, self.gene_p_table)
		
		sys.stderr.write("Outputing prediction table...")
		writer = csv.writer(outf, delimiter='\t')
		#first output the known genes
		for (gene_no, p_gene_id_src_list) in known_gene_no2p_gene_id_src.iteritems():
			self.output_one_gene(curs, writer, gene_no, gene_no2gene_id, gene_no2direct_go)
			row = ['go_no', 'go_id', 'go_name', 'is_correct', 'is_correct_L1', 'is_correct_lca', 'p_value_list', '#clusters', 'mcl_id_list', \
				'e_acc', 'e_acc_pair', 'cluster_context']
			writer.writerow(row)
			for p_gene_id_src in p_gene_id_src_list:
				self.output_function_group(curs, writer, p_gene_id_src_map[p_gene_id_src], gene_no2gene_id,\
					go_no2go_id, go_no2name, go_no2accuracy, go_no2accuracy_pair)
			writer.writerow([])
		#second output the unknown genes
		for (gene_no, p_gene_id_src_list) in unknown_gene_no2p_gene_id_src.iteritems():
			self.output_one_gene(curs, writer, gene_no, gene_no2gene_id, gene_no2direct_go)
			row = ['go_no', 'go_id', 'go_name', 'is_correct', 'is_correct_L1', 'is_correct_lca', 'p_value_list', '#clusters', 'mcl_id_list', \
				'e_acc', 'e_acc_pair', 'cluster_context']
			writer.writerow(row)
			for p_gene_id_src in p_gene_id_src_list:
				self.output_function_group(curs, writer, p_gene_id_src_map[p_gene_id_src], gene_no2gene_id,\
					go_no2go_id, go_no2name, go_no2accuracy, go_no2accuracy_pair)
			writer.writerow([])
		del writer
		sys.stderr.write("Done\n")
Beispiel #2
0
	def output1(self, curs, outf, known_gene_no2p_gene_id_src, unknown_gene_no2p_gene_id_src, p_gene_id_src_map):
		"""
		03-15-05
			copied from output()
		"""
		#three dictionaries
		gene_no2gene_id = get_gene_no2gene_id(curs)
		gene_no2direct_go = get_gene_no2direct_go(curs)
		go_no2go_id = get_go_no2go_id(curs)
		go_no2name = get_go_no2name(curs)
		go_no2accuracy, go_no2accuracy_pair = self.get_go_no2accuracy(curs, self.p_gene_table, self.gene_p_table)
		from codense.common import get_prediction_pair2lca_list
		prediction_pair2lca_list = get_prediction_pair2lca_list(curs,p_gene_table=self.p_gene_table)
		
		sys.stderr.write("Outputing prediction table...")
		writer = csv.writer(outf, delimiter='\t')
		#first output the known genes
		for (gene_no, p_gene_id_src_list) in known_gene_no2p_gene_id_src.iteritems():
			self.output_one_gene1(curs, writer, gene_no, gene_no2gene_id, gene_no2direct_go)
			row = ['go_id', 'go_name', 'is_correct_lca', 'lca_list', 'p_value_list', '#clusters',\
				'e_acc']
			writer.writerow(row)
			for p_gene_id_src in p_gene_id_src_list:
				#NOTE: the arguments passed to this function is different between known and unknown genes.
				self.output_function_group1(curs, writer, p_gene_id_src_map[p_gene_id_src], gene_no2gene_id,\
					go_no2go_id, go_no2name, go_no2accuracy, go_no2accuracy_pair, prediction_pair2lca_list, gene_no)
			writer.writerow([])
		#second output the unknown genes
		for (gene_no, p_gene_id_src_list) in unknown_gene_no2p_gene_id_src.iteritems():
			self.output_one_gene1(curs, writer, gene_no, gene_no2gene_id, gene_no2direct_go)
			row = ['go_id', 'go_name', 'p_value_list', '#clusters', 'e_acc']
			writer.writerow(row)
			for p_gene_id_src in p_gene_id_src_list:
				self.output_function_group1(curs, writer, p_gene_id_src_map[p_gene_id_src], gene_no2gene_id,\
					go_no2go_id, go_no2name, go_no2accuracy, go_no2accuracy_pair)
			writer.writerow([])
		del writer
		sys.stderr.write("Done\n")