def __process_loop_file(self): interval_tree = {} with opener(self.properties['file']) as f: for idx, line in enumerate(f): line = to_string(line) # skip header line if idx == 0 and self.__is_header(line): continue fields = line.split() chr1, x1, x2, chr2, y1, y2, *other = fields x1, x2, y1, y2 = list(map(int, [x1, x2, y1, y2])) # skip inter-chromosome interaction if chr1 != chr2: continue chromosome = chr1 if not chromosome.startswith("chr"): chromosome = change_chrom_names(chromosome) if chromosome not in interval_tree: interval_tree[chromosome] = IntervalTree() if len(other) == 0: color = self.DEFAULT_COLOR else: rgb = other[0].split(",") rgb = list(map(int, rgb)) color = rgb2hex(*rgb) loop = self.LoopInverval(chr1, x1, x2, chr2, y1, y2, color) interval_tree[chromosome].add(Interval(x1, y2, loop)) return interval_tree
def plot(self, ax, gr: GenomeRange, **kwargs): regions = self.fetch_data(gr, **kwargs) for (start, end, color) in regions: if self.properties['color'] != 'bed_rgb': color = self.properties['color'] if type(color) is not str: color = rgb2hex(*color) ax.axvspan(start, end, color=color, alpha=self.properties['alpha']) if self.properties['border_line'] == 'yes': # plot border line ymin, ymax = ax.get_ylim() ax.vlines([start, end], ymin, ymax, linestyle=self.properties['border_line_style'], linewidth=self.properties['border_line_width'], color=self.properties['border_line_color'], alpha=self.properties['border_line_alpha'])
def plot(self, ax, chrom_region, start_region, end_region): regions = self.__get_regions(chrom_region, start_region, end_region) for (start, end, color) in regions: if self.properties['color'] != 'bed_rgb': color = self.properties['color'] if type(color) is not str: color = rgb2hex(*color) ax.axvspan(start, end, color=color, alpha=self.properties['alpha']) if self.properties['border_line'] == 'yes': # plot border line ymin, ymax = ax.get_ylim() ax.vlines([start, end], ymin, ymax, linestyle=self.properties['border_line_style'], linewidth=self.properties['border_line_width'], color=self.properties['border_line_color'], alpha=self.properties['border_line_alpha'])