Exemplo n.º 1
0
def draw_minor_transition(ax, sc, d, a, b):
    # transition from i to b
    from numpy import logical_and
    for i in range(4):
        if i == b:
            continue
        d_ = d[d['Mn_seq_x'] == i]
        if len(d_) == 0: continue

        y_ = [
            linspace(p_.maf_x, p_.maf_y, seq_size)
            for p_ in d_[['maf_x', 'maf_y']].itertuples()
        ]
        x_ = array(y_)
        for j in range(len(d_)):
            x_[j].fill(d_[duma_position].values[j])
        c = [xlin for _ in range(len(x_))]

        sc[a]['minor'].append(
            ax.scatter(x_,
                       y_,
                       c=c,
                       cmap=mcols.cmap(dcolor[i][b]),
                       s=markersize))

        # draw major scatter
        y_ = get_uppery(y_)
        x_ = [i[0] for i in x_]
        sc[a]['major'].append(
            ax.scatter(x_,
                       y_,
                       color=colors[a],
                       label=basepair[a],
                       s=markersize - 1))
Exemplo n.º 2
0
		def lambda_style(x):
			from mcolors import mcols
			if len(x['ct']) == 1:
				return self.colors[self.basepair.index(x['ct'].upper())]
			else:
				return mcols.cmap(self.dcolor[self.basepair.index(x['ct'][0].upper())][self.basepair.index(x['ct'][1].upper())])
Exemplo n.º 3
0
	def visualize(self):
		import matplotlib.patches as mpatches

		self.fig, self.ax = plt.subplots(3, 1, sharex=True)
		self.ax[0].set_title('Click on legend rectangle to toggle data on/off', fontdict={'fontsize' : 8 })
		self.fig.set_size_inches(12, 7, forward=True)
		plt.subplots_adjust(left=0.05, bottom=0.15, right=0.98, hspace=0.15)
		# bpdiff_trans = [] # major transition

		self.ax = self.ax[::-1]

		# major가 같은 것 들만
		print('Run matplotlib...')
		for i in range(len(self.bpdiff)):
			sc = [ {'major' : [], 'minor': [] }, {'major' : [], 'minor': [] }, 
			       {'major' : [], 'minor': [] }, {'major' : [], 'minor': [] } ]

			self.draw_vspans(self.ax[i], self.B.range_dumas)
			
			for a in range(4):

				cond1 = self.bpdiff[i]['Mj_seq_x'] == a

				# major a -> minor b
				for b in range(4):
					if a == b:
						# sc[a]['major'].append(None)
						# sc[a]['minor'].append(None)
						continue

					# 1. minor가 같은 것들 처리 : 같은 색상
					cond2 = self.bpdiff[i]['Mn_seq_y'] == b
					# x는 
					cond3 = logical_or(self.bpdiff[i]['minor_x'] == 0, self.bpdiff[i]['Mn_seq_x'] == b)				
					cond3 = logical_and(cond2, cond3)

					d = self.B.get_bpdiff_cond(index=i, cond=logical_and(cond1, cond3)) #bpdiff[i][ logical_and(cond1, cond3).values ]
					if len(d) > 0:
						y_ = [ linspace(d_.maf_x, d_.maf_y, self.seq_size) for d_ in d[['maf_x', 'maf_y']].itertuples() ]					
						x_ = array(y_)
						for j in range(len(d)):
							x_[j].fill( d[self.duma_position].values[j] )
						c = [ self.xlin for _ in range(len(x_))]
						sc[a]['minor'].append(self.ax[i].scatter(x_, y_, c=c, cmap=mcols.cmap(self.mcolor[b]), s=self.markersize, linewidth=0.0))

						# draw major scatter
						y_ = self.get_uppery(y_)
						x_ = [ ii[0] for ii in x_]
						sc[a]['major'].append(self.ax[i].scatter(x_, y_, color=self.basecolors[a], label=self.basepair[a], s=self.markersize-1))
					
					# # 2. minor가 바뀌는 것들 처리 : colors diverging
					# 각 basetype -> b type, target이 b, 즉, b로 변한것
					cond2 = logical_and(self.bpdiff[i]['Mn_seq_x'] != b, self.bpdiff[i]['minor_x'] > 0)				
					cond3 = logical_and(cond2, self.bpdiff[i]['Mn_seq_y'] == b)
					d = self.bpdiff[i][ logical_and(cond1, cond3).values ]
					if len(d) > 0:
						self.draw_minor_transition(self.ax[i], sc, d, a, b)
				# end for b
			#end for a
			self.sct.append(sc)

			self.ax[i].set_ylim([0, 50])
			self.ax[i].set_ylabel('Variation of MAF(%)')
			self.ax[i].set_title(self.ylabel[i], loc='left', fontdict={'fontsize':13, 'verticalalignment':'top', 'color':'black', 'backgroundcolor':'#FEFEFE'})

		# ZoomSlider of Dumas position
		zaxes = plt.axes([0.08, 0.07, 0.90, 0.03], facecolor='lightgoldenrodyellow')
		self.zslider = ZoomSlider(zaxes, 'Dumas Position', valmin=self.B.minpos, valmax=self.B.maxpos, valleft=self.B.minpos, valright=self.B.maxpos, color='lightblue', valstep=1.0)
		self.zslider.on_changed(self.update_xlim)


		from legend import Legend
		spatches = [ mpatches.Patch(color=self.basecolors[idx], label=self.basepair[idx]) for idx in range(4) ]
		leg_basepair = Legend(self.fig, { 'spatches' : spatches, 'label' : self.basepair, 'bbox':(0.66, .91, 0.33, .102), 'loc' : 3,
					'ncol' : 4, 'mode' : 'expand', 'borderaxespad' : 0.})

		dumalabels = [ key for key in self.dumas.keys()]
		spatches = [ mpatches.Patch(color='grey', label=dumalabels[idx]) for idx in range(3) ]
		leg_dumas = Legend(self.fig, { 'spatches' : spatches, 'label' : dumalabels, 'bbox':(0.05, .91, 0.33, .102), 'loc' : 3,
					'ncol' : 3, 'mode' : 'expand', 'borderaxespad' : 0.})	

		spatches = [ mpatches.Patch(color=['black', 'magenta'][idx], label=['base', 'variation'][idx]) for idx in range(2) ]
		self.leg_filter = Legend(self.fig, { 'spatches' : spatches, 'label' : ['base_0.0', 'variation_5.0'], 'bbox':(0.40, .91, 0.24, .102), 'loc' : 3,
					'ncol' : 3, 'mode' : 'expand', 'borderaxespad' : 0.})	

		for x in self.ax:
			self.annot.append(x.annotate("", xy=(0,0), xytext=(20,-30),textcoords="offset points",
	                    bbox=dict(boxstyle="round", fc="w"), arrowprops=dict(arrowstyle="->")))
			# annotate over other axes
			x.figure.texts.append(x.texts.pop())

			# 
			# x.callbacks.connect('xlim_changed', xlim_changed_event)

		for c in self.B.range_dumas.keys():
			self.annot_gere[c] = []
			ay_ = 0.85 if c == self.duma_Repeat else 0.7
			if c == self.duma_ORF: ay_ = 1.
			for d in self.dumas[c]:
				self.annot_gere[c].append(self.ax[-1].annotate(d, xy=(self.B.range_dumas[c][d]['min'], 50*ay_), xytext=(-20,10),
					textcoords="offset points", bbox=dict(boxstyle="round", fc="w"), arrowprops=dict(arrowstyle="fancy")))

		for an_ in self.annot:
			an_.set_visible(False)
			an_.set_zorder(10)

		for c in self.B.range_dumas.keys():
			for an_ in self.annot_gere[c]:
				an_.set_visible(False)

		# legend pick event
		self.fig.canvas.mpl_connect('pick_event', self.onpick)
		leg_dumas.pick()

		self.fig.canvas.mpl_connect("button_press_event", self.click_)
		
		# ax[-1].text(105500, 49, 'IRS', fontdict={'fontsize':5})
		# buttonaxes = plt.axes([0.89, .95, 0.1, 0.025])
		# bnext = Button(buttonaxes, 'Export')
		# bnext.on_clicked(ExportToParallelCoordGraph)

		plt.show()
					continue

				# 1. minor가 같은 것들 처리 : 같은 색상
				cond2 = bpdiff[i]['Mn_seq_y'] == b
				# x는 
				cond3 = logical_or(bpdiff[i]['minor_x'] == 0, bpdiff[i]['Mn_seq_x'] == b)				
				cond3 = logical_and(cond2, cond3)

				d = B.get_bpdiff_cond(index=i, cond=logical_and(cond1, cond3)) #bpdiff[i][ logical_and(cond1, cond3).values ]
				if len(d) > 0:
					y_ = [ linspace(d_.maf_x, d_.maf_y, seq_size) for d_ in d[['maf_x', 'maf_y']].itertuples() ]					
					x_ = array(y_)
					for j in range(len(d)):
						x_[j].fill( d[duma_position].values[j] )
					c = [ xlin for _ in range(len(x_))]
					sc[a]['minor'].append(ax[i].scatter(x_, y_, c=c, cmap=mcols.cmap(mcolor[b]), s=markersize, linewidth=0.0))

					# draw major scatter
					y_ = get_uppery(y_)
					x_ = [ ii[0] for ii in x_]
					sc[a]['major'].append(ax[i].scatter(x_, y_, color=colors[a], label=basepair[a], s=markersize-1))
				
				# # 2. minor가 바뀌는 것들 처리 : colors diverging
				# 각 basetype -> b type, target이 b, 즉, b로 변한것
				cond2 = logical_and(bpdiff[i]['Mn_seq_x'] != b, bpdiff[i]['minor_x'] > 0)				
				cond3 = logical_and(cond2, bpdiff[i]['Mn_seq_y'] == b)
				d = bpdiff[i][ logical_and(cond1, cond3).values ]
				if len(d) > 0:
					draw_minor_transition(ax[i], sc, d, a, b)
			# end for b
		#end for a
Exemplo n.º 5
0
                cond3 = logical_and(cond2, cond3)

                d = bpdiff[i][logical_and(cond1, cond3).values]
                if len(d) > 0:
                    y_ = [
                        linspace(d_.maf_x, d_.maf_y, seq_size)
                        for d_ in d[['maf_x', 'maf_y']].itertuples()
                    ]
                    x_ = array(y_)
                    for j in range(len(d)):
                        x_[j].fill(d[duma_position].values[j])
                    c = [xlin for _ in range(len(x_))]
                    sc[a]['minor'].append(ax[i].scatter(x_,
                                                        y_,
                                                        c=c,
                                                        cmap=mcols.cmap(
                                                            mcolor[b]),
                                                        s=markersize,
                                                        linewidth=0.0))

                    # draw major scatter
                    y_ = get_uppery(y_)
                    x_ = [ii[0] for ii in x_]
                    sc[a]['major'].append(ax[i].scatter(x_,
                                                        y_,
                                                        color=colors[a],
                                                        label=basepair[a],
                                                        s=markersize - 1))

                # # 2. minor가 바뀌는 것들 처리 : colors diverging
                # 각 basetype -> b type, target이 b, 즉, b로 변한것
                cond2 = logical_and(bpdiff[i]['Mn_seq_x'] != b,