def plot_data(self, column_pos, max_value, min_value): for item in self.data: gene = item[0] sample_name = item[1] real_value = item[2] if self.log_graph: value = log10(real_value) if real_value < 1: continue else: value = real_value colour = self.legend[sample_name]['colour'] cirlce_obj = Circle( center=(column_pos[gene], self.margin_top + self.plottable_y - self.scale_y(value, max_value, min_value)), r=3, stroke_width=0.1, stroke_linecap='round', stroke_opacity=1, fill=colour, fill_opacity=0.6) # set to 0.2 if you want to show clear. cirlce_obj.set_desc( f"{sample_name} - {self.legend[sample_name]['category']} - {round(real_value)}" ) self.plot.add(cirlce_obj)
def plot_data(self): if not self.show_legend: self.plot.add( Line(start=(self.margin_left, self.margin_top), end=(self.width - self.margin_right, self.margin_top), stroke_width=1, stroke="black")) self.max_value = max( [x['score'] for x in self.annotated_scores.values()]) if not self.min_value: self.min_value = min( [x['score'] for x in self.annotated_scores.values()]) if not self.show_legend: self.plot.add( Text("Fibroblasts", insert=(self.margin_left, self.margin_top - 5), fill="black", font_size="15")) self.plot.add( Text("Cardiomyocytes", insert=(self.width - self.margin_right - 100, self.margin_top - 5), fill="black", font_size="15")) delta = self.max_value - self.min_value plottable = self.width - (self.margin_left + self.margin_right) spacing = { "Fibroblasts": INIT_GAP, "Cardiomyocytes": INIT_GAP, "Experimental": INIT_GAP, "other": INIT_GAP } for sample, sample_details in self.annotated_scores.items(): position = self.margin_left + ( (sample_details['score'] - self.min_value) / delta * plottable) # colour = "grey" if "category" in sample_details: sample_type = sample_details["category"] if sample_type == "Fibroblasts": colour = "green" elif sample_type == "Cardiomyocytes": colour = "blue" elif sample_type == "Experimental": colour = "red" else: continue # sample_type = "other" else: continue # sample_type = "other" circle_obj = Circle( center=(position, self.margin_top + spacing[sample_type] + 5), r=3, stroke_width=0.1, stroke_linecap='round', stroke_opacity=1, fill=colour, fill_opacity=0.6) # set to 0.2 if you want to show clear. circle_obj.set_desc('{} - {} - {}'.format( sample, sample_type, sample_details["score"] if "description" not in sample_details else sample_details["description"])) self.plot.add(circle_obj) if sample_type == "other": spacing[sample_type] += 3 else: spacing[sample_type] += 6