def on_button_draw_annotation_clicked(self, widget, data=None): """ 2008-12-16 use DrawSNPRegion.drawGeneModel() to draw gene models 2008-02-02 """ if not self.chr_id2size: sys.stderr.write("No genome-wide pvalue plot has been drawn yet. Do it first!\n") return #if not self.gene_id2model: # self.gene_id2model, self.chr_id2gene_id_ls = self.get_gene_id2model(self.postgres_curs, tax_id=3702) if not self.gene_annotation: self.db_connect() xlim = self.axe_gene_model.get_xlim() left_chr, left_pos = get_chr_pos_from_x_axis_pos(xlim[0], self.chr_gap, self.chr_id2cumu_size, self.chr_id_ls) right_chr, right_pos = get_chr_pos_from_x_axis_pos(xlim[1], self.chr_gap, self.chr_id2cumu_size, self.chr_id_ls) #fake a snps_within_this_region for drawGeneModel() snps_within_this_region = PassingData(chr_pos_ls=[[left_chr, left_pos],[right_chr, right_pos]]) base_y_value = 1 gene_width = 0.8 gene_position_cycle = 5 return_data = DrawSNPRegion.drawGeneModel(self.axe_gene_model, snps_within_this_region, self.gene_annotation, candidate_gene_set=None,\ gene_width=gene_width, gene_position_cycle=gene_position_cycle, base_y_value=base_y_value, \ gene_box_text_gap=20, label_gene=0, rotate_xy=False,\ chr_id2cumu_size=self.chr_id2cumu_size, chr_id2size=self.chr_id2size, chr_gap=self.chr_gap,\ artist_obj_id2artist_gene_id_ls=self.artist_obj_id2artist_gene_id_ls, \ gene_id2artist_object_id=self.gene_id2artist_object_id, drawGeneOnTheBoundary=False) #set drawGeneOnTheBoundary to False because later adding text to these genes would corrupt the running program. self.axe_gene_model.set_ylim([base_y_value-gene_width, gene_position_cycle+gene_width*2]) """ for gene_id in self.chr_id2gene_id_ls[left_chr]: gene_model = self.gene_id2model[gene_id] if gene_model.start!=None and gene_model.stop!=None and gene_model.stop>left_pos and gene_id not in self.gene_id2artist_object_id: if left_chr==right_chr: #same chromosome if gene_model.start>right_pos: #totally out of range, skip it continue y_value = len(self.gene_id2artist_object_id)%4 #cycling through the y position to avoid clogging self.plot_one_gene(self.ax, gene_id, self.gene_id2model, self.chr_id2cumu_size, self.chr_id2size, self.chr_gap, y_value=-1-y_value, gene_width=self.gene_width) if left_chr!=right_chr: for gene_id in self.chr_id2gene_id_ls[right_chr]: gene_model = self.gene_id2model[gene_id] if gene_model.start!=None and gene_model.stop!=None and gene_model.start<right_pos and gene_id not in self.gene_id2artist_object_id: y_value = len(self.gene_id2artist_object_id)%4 #cycling through the y position to avoid clogging self.plot_one_gene(self.ax, gene_id, self.gene_id2model, self.chr_id2cumu_size, self.chr_id2size, self.chr_gap, y_value=-1-y_value, gene_width=self.gene_width) """ self.canvas_matplotlib.draw()
def mouse_move(self, event): """ 2008-02-04 custom the label shown for 'motion_notify_event' self._idDrag=self.canvas.mpl_connect('motion_notify_event', self.mouse_move) """ #print 'mouse_move', event.button if not event.inaxes or not self._active: if self._lastCursor != cursors.POINTER: self.set_cursor(cursors.POINTER) self._lastCursor = cursors.POINTER else: if self._active=='ZOOM': if self._lastCursor != cursors.SELECT_REGION: self.set_cursor(cursors.SELECT_REGION) self._lastCursor = cursors.SELECT_REGION if self._xypress: x, y = event.x, event.y lastx, lasty, a, ind, lim, trans= self._xypress[0] self.draw_rubberband(event, x, y, lastx, lasty) elif (self._active=='PAN' and self._lastCursor != cursors.MOVE): self.set_cursor(cursors.MOVE) self._lastCursor = cursors.MOVE if event.inaxes and event.inaxes.get_navigate(): try: #2008-02-04 custom here if self.chr_id2size and self.chr_id2cumu_size and self.chr_gap!=None and self.chr_id_ls: x_axis_pos_int = int(round(event.xdata)) chr_id, position = get_chr_pos_from_x_axis_pos(x_axis_pos_int, self.chr_gap, self.chr_id2cumu_size, self.chr_id_ls) chr_perc = -1 #default if chr_id in self.chr_id2size: chr_perc = position/float(self.chr_id2size[chr_id])*100 if chr_perc>100 or chr_perc<0: #out of range chr_perc = -1 if position==-1: #not within any chromosome position = x_axis_pos_int s = 'chr=%s, pos=%i(%.1f%%), y=%s'%(chr_id, position, chr_perc, event.ydata) else: s = event.inaxes.format_coord(event.xdata, event.ydata) except ValueError: pass except OverflowError: pass else: if len(self.mode): self.set_message('%s : %s' % (self.mode, s)) else: self.set_message(s) else: self.set_message(self.mode)