def _load_data(self, interval): self.gene_track = load_annotation(interval, self.annofile, vis=self.vis) self.max_tracks = len(self.gene_track.keys()) self.height *= self.max_tracks
def _load_data(self, interval): self.gene_track = load_annotation(interval, self.annofile, vis=self.vis) self.max_tracks = len(list(self.gene_track.keys())) self.height *= self.max_tracks
def profile_screenshot(fname, interval, tracks, fontsize=None, colors=None, scalegroups=None, scale=None, show_scale=True, annotation=None, bgmode="color", fragmentsize=200, dpi=600, rmdup=False, rmrepeats=False, reverse=False, adjscale=False): """ Plot a genome browser like profile Parameters ---------- fname: string output file name interval: string interval to plot in "chrom:start-end" format tracks: list list of filenames """ if scalegroups is None: scalegroups = [] if not fontsize: fontsize = FONTSIZE if not colors: colors = DEFAULT_COLORS # Plot size and padding definition plotwidth = 6 plotheight = 0.3 pad = { "left": 1.5, "right": 0.05, "top": 0.05, "bottom": 0.05, "row": 0, "column": 3, } # adjust width for track names if they are to long # kind of a quick hack max_len = 0 for group in tracks: names = [ os.path.splitext(os.path.basename(t))[0].strip() for t in group ] l = sum([len(name) for name in names]) if l > max_len: max_len = l if max_len > 27: pad["left"] = 3 # Genomic scale scale_height = 0.1 # Annotation track height annotation_height = 0.01 chrom, start, end = re.split(r'[-:]', interval) start, end = int(start), int(end) if annotation: ann = load_annotation([chrom, start, end], annotation) if ann: annotation_height = 0.2 * len(ann.keys()) else: annotation = False nrows = len(tracks) wsize = pad["left"] + plotwidth + pad["right"] hsize = pad["top"] + (nrows * plotheight) + (pad["row"] * (nrows - 1)) + pad["bottom"] hsize += scale_height + pad["row"] + annotation_height + pad["row"] # initialize figure fig = plt.figure(figsize=(wsize, hsize)) # initialize profile figure pfig = ProfileFigure(fig=fig, fontsize=fontsize, pad=pad) # add the genomic scale pfig.add_panel(ScalePanel()) if type(scale) != type([]): scale = [scale] # add the signal tracks c = 0 for group in tracks: for i, track in enumerate(group): panel = pfig.add_panel(BamProfilePanel( track, color=colors[c % len(colors)], bgmode=bgmode, name=os.path.splitext(os.path.split(track)[-1])[0], fragmentsize=fragmentsize, rmrepeats=rmrepeats, rmdup=rmdup, adjscale=adjscale, show_scale=show_scale, ), overlay=i != 0) panel.ymax = scale[c % len(scale)] c += 1 # add the annotation panel if annotation: pfig.add_panel(AnnotationPanel(annotation)) pfig.plot([chrom, start, end], scalegroups=scalegroups, reverse=reverse) plt.savefig(fname, dpi=dpi)
def profile_screenshot(fname, interval, tracks, fontsize=None, colors=None, scalegroups=None, scale=None, show_scale=True, annotation=None, bgmode="color", fragmentsize=200, dpi=600, rmdup=False, rmrepeats=False, reverse=False, adjscale=False): """ Plot a genome browser like profile Parameters ---------- fname: string output file name interval: string interval to plot in "chrom:start-end" format tracks: list list of filenames """ if scalegroups is None: scalegroups = [] if not fontsize: fontsize = FONTSIZE if not colors: colors = DEFAULT_COLORS # Plot size and padding definition plotwidth = 6 plotheight = 0.3 pad = { "left": 1.5, "right": 0.05, "top": 0.05, "bottom": 0.05, "row": 0, "column": 3, } # adjust width for track names if they are to long # kind of a quick hack max_len = 0 for group in tracks: names = [os.path.splitext(os.path.basename(t))[0].strip() for t in group] l = sum([len(name) for name in names]) if l > max_len: max_len = l if max_len > 27: pad["left"] = 3 # Genomic scale scale_height = 0.1 # Annotation track height annotation_height = 0.01 chrom, start, end = re.split(r'[-:]', interval) start, end = int(start), int(end) if annotation: ann = load_annotation([chrom,start,end], annotation) if ann: annotation_height = 0.2 * len(list(ann.keys())) else: annotation = False nrows = len(tracks) wsize = pad["left"] + plotwidth + pad["right"] hsize = pad["top"] + (nrows * plotheight) + (pad["row"] * (nrows - 1)) + pad["bottom"] hsize += scale_height + pad["row"] + annotation_height + pad["row"] # initialize figure fig = plt.figure(figsize=(wsize, hsize)) # initialize profile figure pfig = ProfileFigure(fig=fig, fontsize=fontsize, pad=pad) # add the genomic scale pfig.add_panel(ScalePanel()) if type(scale) != type([]): scale = [scale] # add the signal tracks c = 0 for group in tracks: for i,track in enumerate(group): panel = pfig.add_panel( BamProfilePanel(track, color = colors[c % len(colors)], bgmode = bgmode, name = os.path.splitext(os.path.split(track)[-1])[0], fragmentsize = fragmentsize, rmrepeats = rmrepeats, rmdup = rmdup, adjscale = adjscale, show_scale = show_scale, ), overlay= i != 0 ) panel.ymax = scale[c % len(scale)] c += 1 # add the annotation panel if annotation: pfig.add_panel(AnnotationPanel(annotation)) pfig.plot([chrom, start, end], scalegroups=scalegroups, reverse=reverse) plt.savefig(fname, dpi=dpi)