Beispiel #1
0
	def draw_gene_function_map(self, no_of_p_funcs_gene_no_go_no_list, go_no2index, function_name_region,\
		output_fname, function_name_length, char_dimension, no_of_functions, font):
		"""
		10-31-05
		11-28-05 draw_grid
		2006-12-13 add font
		"""
		sys.stderr.write("Drawing gene_function_map...\n")
		char_width, char_height = char_dimension
		
		gene_no_repr_length = 0
		for row in no_of_p_funcs_gene_no_go_no_list:
			if len(repr(row[1]))>gene_no_repr_length:
				gene_no_repr_length = len(repr(row[1]))
		gene_no_repr_dimension = (char_width*gene_no_repr_length, char_height)
		function_name_dimension = (char_width*function_name_length, char_height)	#will rotate
		no_of_p_funcs_repr_length = len(repr(no_of_p_funcs_gene_no_go_no_list[-1][0]))	#-1 is the largest number
		no_of_p_funcs_repr_dimension = (char_width*no_of_p_funcs_repr_length, char_height)
		
		x_offset0 = 0
		x_offset1 = gene_no_repr_dimension[0]
		x_offset2 = x_offset1 + no_of_functions*function_name_dimension[1]
		y_offset0 = 0
		y_offset1 = function_name_dimension[0]
		
		whole_dimension = (x_offset2+no_of_p_funcs_repr_dimension[0], \
			y_offset1+len(no_of_p_funcs_gene_no_go_no_list)*gene_no_repr_dimension[1])
		
		im = Image.new('RGB',(whole_dimension[0],whole_dimension[1]),(255,255,255))
		draw = ImageDraw.Draw(im)
		
		box = (x_offset1, y_offset0, x_offset2, y_offset1)
		im.paste(function_name_region, box)
		
		for i in range(len(no_of_p_funcs_gene_no_go_no_list)):
			no_of_p_funcs, gene_no, go_no_set = no_of_p_funcs_gene_no_go_no_list[i]
			y_offset_upper = y_offset1 + i*gene_no_repr_dimension[1]
			y_offset_lower = y_offset_upper + gene_no_repr_dimension[1]
			#draw gene_no
			text_region = get_text_region(repr(gene_no), gene_no_repr_dimension, rotate=0, font=font)
			box = (x_offset0, y_offset_upper, x_offset1, y_offset_lower)
			im.paste(text_region, box)
			#draw p_function
			for go_no in go_no_set:
				index = go_no2index[go_no]
				x_offset_left = x_offset1 + index*function_name_dimension[1]
				x_offset_right = x_offset_left + function_name_dimension[1]
				draw.rectangle((x_offset_left, y_offset_upper, x_offset_right, y_offset_lower), fill=(0,255,0))
			#draw no_of_p_funcs
			text_region = get_text_region(repr(no_of_p_funcs), no_of_p_funcs_repr_dimension, rotate=0, font=font)
			box = (x_offset2, y_offset_upper, whole_dimension[0], y_offset_lower)
			im.paste(text_region, box)
		#11-28-05
		draw_grid(im, draw, [x_offset1, y_offset1, x_offset2, whole_dimension[1]], char_height, char_height)
		
		im = im.rotate(270)
		im.save(output_fname)
		del im
		sys.stderr.write("End drawing gene_function_map.\n")
Beispiel #2
0
	def draw_tf_map(self, recurrence_rec_array_bs_no_list, no_of_datasets, mt_no2tf_name, \
		output_fname, function_name_length, char_dimension, font):
		"""
		11-28-05 add grid
		2006-12-13 add font
		"""
		sys.stderr.write("Drawing tf_map...\n")
		
		no_of_tfs = len(recurrence_rec_array_bs_no_list)
		char_width, char_height = char_dimension
		dataset_no_length = len(repr(no_of_datasets))
		dataset_no_dimension = (char_width*dataset_no_length, char_height)
			#one is not rotated(dataset_no), one is rotated(recurrence)
		function_name_dimension = (char_width*function_name_length, char_height)	#will rotate
		
		x_offset0 = 0
		x_offset1 = dataset_no_dimension[0]
		y_offset0 = 0
		y_offset1 = function_name_dimension[0]
		y_offset2 = y_offset1 + no_of_datasets*dataset_no_dimension[1]
		y_offset3 = y_offset2 + dataset_no_dimension[0]
		whole_dimension = (x_offset1+no_of_tfs*char_height, y_offset3)
		
		im = Image.new('RGB',(whole_dimension[0],whole_dimension[1]),(255,255,255))
		draw = ImageDraw.Draw(im)
		#dataset_no section
		for i in range(no_of_datasets):
			text_region = get_text_region(repr(i+1), dataset_no_dimension, rotate=0, font=font)	#no rotate
			box = (x_offset0, y_offset1+i*dataset_no_dimension[1], x_offset1, y_offset1+(i+1)*dataset_no_dimension[1])
			im.paste(text_region, box)
			
		for i in range(len(recurrence_rec_array_bs_no_list)):
			recurrence, recurrence_array, bs_no = recurrence_rec_array_bs_no_list[i]
			x_offset_left = x_offset1+i*function_name_dimension[1]
			x_offset_right = x_offset1+(i+1)*function_name_dimension[1]
			#function_name
			tf_name = '%s %s'%(bs_no, mt_no2tf_name[bs_no])
			if len(tf_name)>function_name_length:
				tf_name = tf_name[:function_name_length]
			text_region = get_text_region(tf_name, function_name_dimension, font=font)	#rotate
			box = (x_offset_left, y_offset0, x_offset_right, y_offset1)
			im.paste(text_region, box)
			
			#fill in a cell for each dataset_no
			for dataset_no in recurrence_array:
				draw.rectangle((x_offset_left, y_offset1+(dataset_no-1)*dataset_no_dimension[1], \
					x_offset_right, y_offset1+dataset_no*dataset_no_dimension[1]), fill=(0,255,0))
			# write down the recurrence
			text_region = get_text_region(repr(recurrence), dataset_no_dimension, font=font)	#rotate
			box = (x_offset_left, y_offset2, x_offset_right, y_offset3)
			im.paste(text_region, box)
		#11-28-05
		draw_grid(im, draw, [x_offset1, y_offset1, whole_dimension[0], y_offset2], char_height, char_height)
		
		im = im.rotate(270)
		im.save(output_fname)
		del im
		sys.stderr.write("End drawing tf_map.\n")
Beispiel #3
0
	def draw_function_map(self, recurrence_go_no_rec_array_cluster_id_ls, no_of_datasets, go_no2name, \
		output_fname, function_name_length, char_dimension, no_of_functions, font):
		"""
		10-31-05 from misc.py. make it independent and return something for draw_gene_function_map()
		11-28-05 add grid
		11-28-05 include go_no in go_name
		2006-12-13 add font
		"""
		sys.stderr.write("Drawing function_map...\n")
		
		char_width, char_height = char_dimension
		dataset_no_length = len(repr(no_of_datasets))
		dataset_no_dimension = (char_width*dataset_no_length, char_height)	#one is not rotated, one is rotated
		no_of_clusters_dimension = (char_width*7, char_height)	#will rotate
		function_name_dimension = (char_width*function_name_length, char_height)	#will rotate
		
		x_offset0 = 0
		x_offset1 = dataset_no_dimension[0]
		y_offset0 = 0
		y_offset1 = function_name_dimension[0]
		y_offset2 = y_offset1 + no_of_datasets*dataset_no_dimension[1]
		y_offset3 = y_offset2 + dataset_no_dimension[0]
		whole_dimension = (x_offset1+no_of_functions*char_height, \
			y_offset3+no_of_clusters_dimension[0])
		
		im = Image.new('RGB',(whole_dimension[0],whole_dimension[1]),(255,255,255))
		draw = ImageDraw.Draw(im)
		#dataset_no section
		for i in range(no_of_datasets):
			text_region = get_text_region(repr(i+1), dataset_no_dimension, rotate=0, font=font)	#no rotate
			box = (x_offset0, y_offset1+i*dataset_no_dimension[1], x_offset1, y_offset1+(i+1)*dataset_no_dimension[1])
			im.paste(text_region, box)
		#10-31-05 following for draw_gene_function_map() to ensure correspondence.
		go_no2index = {}
		function_name_box = (x_offset1,y_offset0, whole_dimension[0], y_offset1)
		
		for i in range(len(recurrence_go_no_rec_array_cluster_id_ls)):
			recurrence, go_no, recurrence_array, mcl_id_set = recurrence_go_no_rec_array_cluster_id_ls[i]
			go_no2index[go_no] = i	#10-31-05
			x_offset_left = x_offset1+i*function_name_dimension[1]
			x_offset_right = x_offset1+(i+1)*function_name_dimension[1]
			#function_name
			go_name = '%s %s'%(go_no, go_no2name[go_no])	#11-28-05 include go_no
			if len(go_name)>function_name_length:
				go_name = go_name[:function_name_length]
			text_region = get_text_region(go_name, function_name_dimension, font=font)	#rotate
			box = (x_offset_left, y_offset0, x_offset_right, y_offset1)
			im.paste(text_region, box)
			
			#fill in a cell for each dataset_no
			for dataset_no in recurrence_array:
				draw.rectangle((x_offset_left, y_offset1+(dataset_no-1)*dataset_no_dimension[1], \
					x_offset_right, y_offset1+dataset_no*dataset_no_dimension[1]), fill=(0,255,0))
			# write down the recurrence
			text_region = get_text_region(repr(recurrence), dataset_no_dimension, font=font)	#rotate
			box = (x_offset_left, y_offset2, x_offset_right, y_offset3)
			im.paste(text_region, box)
			#write down the no_of_clusters
			text_region = get_text_region(repr(len(mcl_id_set)), no_of_clusters_dimension, font=font)	#rotate
			box = (x_offset_left, y_offset3, x_offset_right, whole_dimension[1])
			im.paste(text_region, box)
		function_name_region = im.crop(function_name_box)	#10-31-05
		
		#11-28-05
		draw_grid(im, draw, [x_offset1, y_offset1, whole_dimension[0], y_offset2], char_height, char_height)
		
		im = im.rotate(270)
		im.save(output_fname)
		del im
		sys.stderr.write("End drawing function_map.\n")
		return go_no2index, function_name_region