From db8e849befbec8f91d047f0f7dcfa2d8d9ec5243 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Tue, 29 Jun 2021 19:06:41 -0500 Subject: [PATCH 01/11] move legend to up and fix y-axis inward if using different ymax --- deeptools/plotHeatmap.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index bc4bbcc2a4..cbf2ddb62d 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -161,6 +161,7 @@ def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType if sample_id > 0 and len(yMin) == 1 and len(yMax) == 1: plt.setp(ax_profile.get_yticklabels(), visible=False) + ax_profile.get_yaxis().set_tick_params(direction='in',pad=-22) # beisi if sample_id == 0 and yAxisLabel != '': ax_profile.set_ylabel(yAxisLabel) xticks, xtickslabel = hm.getTicks(tickIdx) @@ -593,8 +594,13 @@ def plotMatrix(hm, outFileName, ax_list = addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType, plot_type, yAxisLabel, color_list, yMin, yMax, kwargs['wspace'], kwargs['hspace'], colorbar_position, label_rotation) if legend_location != 'none': - ax_list[-1].legend(loc=legend_location.replace('-', ' '), ncol=1, prop=fontP, - frameon=False, markerscale=0.5) + ax = ax_list[-1] # beisi + box = ax.get_position() + ax.set_position([box.x0, box.y0 - box.height * 0.1, box.width, box.height * 0.9]) + legend = ax.legend(loc='lower right', shadow=False, fontsize='x-large', bbox_to_anchor=(0, 1.3, 1, .22), ncol=10, frameon=False, prop=fontP) # beisi, legend line + ax.add_artist(legend) + # ax_list[-1].legend(loc=legend_location.replace('-', ' '), ncol=1, prop=fontP, + # frameon=False, markerscale=0.5) first_group = 0 # helper variable to place the title per sample/group for sample in range(hm.matrix.get_num_samples()): From 30f42e99b8fa073e14047b4de3f83aa975142c61 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Tue, 11 Jul 2023 18:43:25 -0500 Subject: [PATCH 02/11] autobreakline for title and rotation y label of heatmap --- deeptools/heatmapper.py | 4 ++-- deeptools/plotHeatmap.py | 19 ++++++++++++++----- deeptools/plotProfile.py | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index 6a95ba0052..d0eebaad22 100644 --- a/deeptools/heatmapper.py +++ b/deeptools/heatmapper.py @@ -1308,9 +1308,9 @@ def hmcluster(self, k, evaluate_silhouette=True, method='kmeans', clustering_sam _clustered_matrix = [] cluster_number = 1 for cluster in cluster_order: - self.group_labels.append("cluster_{}".format(cluster_number)) - cluster_number += 1 cluster_ids = _cluster_ids_list[cluster] + self.group_labels.append("cluster_{}_n{}".format(cluster_number,len(cluster_ids))) + cluster_number += 1 self.group_boundaries.append(self.group_boundaries[-1] + len(cluster_ids)) _clustered_matrix.append(self.matrix[cluster_ids, :]) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index cbf2ddb62d..521ebc388e 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -13,7 +13,7 @@ from matplotlib.font_manager import FontProperties import matplotlib.gridspec as gridspec from matplotlib import ticker -import copy +import copy, re import sys import plotly.offline as py import plotly.graph_objs as go @@ -115,6 +115,15 @@ def prepare_layout(hm_matrix, heatmapsize, showSummaryPlot, showColorbar, perGro return grids +def autobreaklinetitle(title,sep="[-_,.]",lmax=15): + sss = [ rr for rr in re.split(sep,title) if len(rr) ] + newtitle, tmp = "", "" + for ss in sss: + tmp += ss + if len(tmp) > lmax: + newtitle += tmp + "\n" + tmp = "" + return newtitle def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType, plot_type, yAxisLabel, color_list, yMin, yMax, wspace, hspace, colorbar_position, label_rotation=0.0): """ @@ -144,7 +153,7 @@ def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType else: ax_profile = fig.add_subplot(grids[0, sample_id]) - ax_profile.set_title(title) + ax_profile.set_title(autobreaklinetitle(title)) for group in range(iterNum2): if perGroup: sub_matrix = hm.matrix.get_matrix(sample_id, group) @@ -636,7 +645,7 @@ def plotMatrix(hm, outFileName, if group == first_group and not showSummaryPlot and not perGroup: title = hm.matrix.sample_labels[sample] - ax.set_title(title) + ax_profile.set_title(autobreaklinetitle(title)) if box_around_heatmaps is False: # Turn off the boxes around the individual heatmaps @@ -689,9 +698,9 @@ def plotMatrix(hm, outFileName, ax.axes.set_xlabel(xAxisLabel) ax.axes.set_yticks([]) if perGroup and group == 0: - ax.axes.set_ylabel(sub_matrix['sample']) + ax.axes.set_ylabel(sub_matrix['sample'],rotation=75,labelpad=0,fontsize=15) elif not perGroup and sample == 0: - ax.axes.set_ylabel(sub_matrix['group']) + ax.axes.set_ylabel(sub_matrix['group'],rotation=75,labelpad=0,horizontalalignment='right',fontsize=15) # Plot vertical lines at tick marks if desired if linesAtTickMarks: diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index b46be32bb9..aa8afc30a8 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -49,6 +49,15 @@ def parse_arguments(args=None): return parser +def autobreaklinetitle(title,sep="[-_,.]",lmax=15): + sss = [ rr for rr in re.split(sep,title) if len(rr) ] + newtitle, tmp = "", "" + for ss in sss: + tmp += ss + if len(tmp) > lmax: + newtitle += tmp + "\n" + tmp = "" + return newtitle def process_args(args=None): args = parse_arguments().parse_args(args) @@ -269,7 +278,7 @@ def plot_hexbin(self): for data_idx in range(self.numlines)[::-1]: ax = self.fig.add_subplot(sub_grid[data_idx, 0]) if data_idx == 0: - ax.set_title(title) + ax.set_title(autobreaklinetitle(title)) if data_idx != self.numlines - 1: plt.setp(ax.get_xticklabels(), visible=False) @@ -514,7 +523,7 @@ def plot_heatmap(self): else: title = self.hm.matrix.sample_labels[plot] tickIdx = plot - ax.set_title(title) + ax.set_title(autobreaklinetitle(title)) mat = [] # when drawing a heatmap (in contrast to drawing lines) for data_idx in range(self.numlines): if self.per_group: @@ -723,7 +732,7 @@ def plot_profile(self): plt.setp(ax.get_yticklabels(), visible=False) tickIdx = plot - ax.set_title(title) + ax.set_title(autobreaklinetitle(title)) for data_idx in range(self.numlines): if self.per_group: _row, _col = plot, data_idx From f1481a4cbe09404f02e44bb2d7d725502bc50493 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Tue, 11 Jul 2023 18:44:27 -0500 Subject: [PATCH 03/11] autobreakline for title and rotation y label of heatmap --- deeptools/plotHeatmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index 521ebc388e..7285ea816a 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -645,7 +645,7 @@ def plotMatrix(hm, outFileName, if group == first_group and not showSummaryPlot and not perGroup: title = hm.matrix.sample_labels[sample] - ax_profile.set_title(autobreaklinetitle(title)) + ax.set_title(autobreaklinetitle(title)) if box_around_heatmaps is False: # Turn off the boxes around the individual heatmaps From 7cacf3cb5243f9a46d085367c2629e9397eeaebb Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 12 Jul 2023 10:53:08 -0500 Subject: [PATCH 04/11] debug title --- deeptools/plotHeatmap.py | 2 ++ deeptools/plotProfile.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index 7285ea816a..e7657172a2 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -123,6 +123,8 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): if len(tmp) > lmax: newtitle += tmp + "\n" tmp = "" + else: + tmp += "-" return newtitle def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType, plot_type, yAxisLabel, color_list, yMin, yMax, wspace, hspace, colorbar_position, label_rotation=0.0): diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index aa8afc30a8..5011234c1a 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -57,6 +57,8 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): if len(tmp) > lmax: newtitle += tmp + "\n" tmp = "" + else: + tmp += "-" return newtitle def process_args(args=None): From a7059c1b3916482db341e41161e869d610a67bef Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 12 Jul 2023 15:07:46 -0500 Subject: [PATCH 05/11] debug title --- deeptools/plotHeatmap.py | 1 + deeptools/plotProfile.py | 1 + 2 files changed, 2 insertions(+) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index e7657172a2..0358390984 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -125,6 +125,7 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): tmp = "" else: tmp += "-" + newtitle += tmp.strip("-") + "\n" return newtitle def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType, plot_type, yAxisLabel, color_list, yMin, yMax, wspace, hspace, colorbar_position, label_rotation=0.0): diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index 5011234c1a..ce49e82ab5 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -59,6 +59,7 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): tmp = "" else: tmp += "-" + newtitle += tmp.strip("-") + "\n" return newtitle def process_args(args=None): From 23c5e1601c909cdab9b744af2b7d225818a3f9c5 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 12 Jul 2023 16:20:58 -0500 Subject: [PATCH 06/11] small tweak --- deeptools/plotHeatmap.py | 3 ++- deeptools/plotProfile.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index 0358390984..688d41df1d 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -125,7 +125,8 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): tmp = "" else: tmp += "-" - newtitle += tmp.strip("-") + "\n" + newtitle += tmp.strip("-") + newtitle = "\n" + newtitle return newtitle def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType, plot_type, yAxisLabel, color_list, yMin, yMax, wspace, hspace, colorbar_position, label_rotation=0.0): diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index ce49e82ab5..f100a9eac8 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- -import sys +import sys, re import argparse import numpy as np @@ -59,7 +59,8 @@ def autobreaklinetitle(title,sep="[-_,.]",lmax=15): tmp = "" else: tmp += "-" - newtitle += tmp.strip("-") + "\n" + newtitle += tmp.strip("-") + newtitle = "\n" + newtitle return newtitle def process_args(args=None): From 1b85c00c8c0efa1b10f724ff4ae338aec651e5d1 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Mon, 2 Oct 2023 18:09:32 -0500 Subject: [PATCH 07/11] hard limit to 15 chars --- deeptools/plotHeatmap.py | 16 +++++++++------- deeptools/plotProfile.py | 14 ++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index 688d41df1d..d2f8b5a18c 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -13,8 +13,8 @@ from matplotlib.font_manager import FontProperties import matplotlib.gridspec as gridspec from matplotlib import ticker -import copy, re -import sys + +import sys, re, os, copy import plotly.offline as py import plotly.graph_objs as go @@ -115,17 +115,19 @@ def prepare_layout(hm_matrix, heatmapsize, showSummaryPlot, showColorbar, perGro return grids -def autobreaklinetitle(title,sep="[-_,.]",lmax=15): +def autobreaklinetitle(title,sep="[-_,.:]",lmax=15): + outsep = "-" sss = [ rr for rr in re.split(sep,title) if len(rr) ] newtitle, tmp = "", "" for ss in sss: + tmp0 = tmp tmp += ss if len(tmp) > lmax: - newtitle += tmp + "\n" - tmp = "" + newtitle += tmp0.strip(outsep) + "\n" + tmp = ss else: - tmp += "-" - newtitle += tmp.strip("-") + tmp += outsep + newtitle += tmp.strip(outsep) newtitle = "\n" + newtitle return newtitle diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index f100a9eac8..6655d5940d 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- -import sys, re +import sys, os, re import argparse import numpy as np @@ -49,17 +49,19 @@ def parse_arguments(args=None): return parser -def autobreaklinetitle(title,sep="[-_,.]",lmax=15): +def autobreaklinetitle(title,sep="[-_,.:]",lmax=15): + outsep = "-" sss = [ rr for rr in re.split(sep,title) if len(rr) ] newtitle, tmp = "", "" for ss in sss: + tmp0 = tmp tmp += ss if len(tmp) > lmax: - newtitle += tmp + "\n" - tmp = "" + newtitle += tmp0.strip(outsep) + "\n" + tmp = ss else: - tmp += "-" - newtitle += tmp.strip("-") + tmp += outsep + newtitle += tmp.strip(outsep) newtitle = "\n" + newtitle return newtitle From e793e4840e500c811cf4258e407bd60e76d5d359 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 22 Nov 2023 13:01:56 -0600 Subject: [PATCH 08/11] add --repgrplist option to combine replicates for plotProfile --- deeptools/heatmapper_utilities.py | 21 +++++- deeptools/parserCommon.py | 8 +++ deeptools/plotProfile.py | 109 +++++++++++++++++++++--------- 3 files changed, 103 insertions(+), 35 deletions(-) diff --git a/deeptools/heatmapper_utilities.py b/deeptools/heatmapper_utilities.py index e63dfb0226..aa3559096f 100644 --- a/deeptools/heatmapper_utilities.py +++ b/deeptools/heatmapper_utilities.py @@ -9,6 +9,9 @@ old_settings = np.seterr(all='ignore') +debug = 0 +if debug: + from ipdb import set_trace def plot_single(ax, ma, average_type, color, label, plot_type='lines'): """ @@ -18,7 +21,7 @@ def plot_single(ax, ma, average_type, color, label, plot_type='lines'): ---------- ax : matplotlib axis matplotlib axis - ma : numpy array + ma : numpy array or list of numpy array(for plot with --repgrplist, take average between replicates ) numpy array The data on this matrix is summarized according to the `average_type` argument. average_type : str @@ -32,7 +35,9 @@ def plot_single(ax, ma, average_type, color, label, plot_type='lines'): type of plot. Either 'se' for standard error, 'std' for standard deviation, 'overlapped_lines' to plot each line of the matrix, fill to plot the area between the x axis and the value or any other string to - just plot the average line. + just plot the average line. When assign samples to replicates group such as + '--repgrplist WT WT KO KO' : 'std' would be the standard deviation between replicates groups. + 'se' for standard error between replicates groups. Returns ------- @@ -63,7 +68,15 @@ def plot_single(ax, ma, average_type, color, label, plot_type='lines'): """ - summary = np.ma.__getattribute__(average_type)(ma, axis=0) + if isinstance(ma,list): + summary_list = [] + for ma_each in ma: + tmp = np.ma.__getattribute__(average_type)(ma_each, axis=0) + summary_list.append(tmp) + ma = np.array(summary_list) + summary = np.ma.__getattribute__("average")(ma, axis=0) + else: + summary = np.ma.__getattribute__(average_type)(ma, axis=0) # only plot the average profiles without error regions x = np.arange(len(summary)) if isinstance(color, np.ndarray): @@ -72,6 +85,8 @@ def plot_single(ax, ma, average_type, color, label, plot_type='lines'): if plot_type == 'fill': ax.fill_between(x, summary, facecolor=color, alpha=0.6, edgecolor='none') + if debug: + set_trace() if plot_type in ['se', 'std']: if plot_type == 'se': # standard error std = np.std(ma, axis=0) / np.sqrt(ma.shape[0]) diff --git a/deeptools/parserCommon.py b/deeptools/parserCommon.py index ef4f4d0748..23de9e6472 100755 --- a/deeptools/parserCommon.py +++ b/deeptools/parserCommon.py @@ -846,6 +846,14 @@ def heatmapperOptionalArgs(mode=['heatmap', 'profile'][0]): 'group.', action='store_true') + optional.add_argument('--repgrplist', + default=None, + nargs='+', + help='Group profiles by genotype' + 'assign each profile to a group(as replicates) to plot average +/- se/std.' + 'If the number of group values is smaller than' + 'the number of plots, the values are recycled.') + optional.add_argument('--plotFileFormat', metavar='', help='Image format type. If given, this ' diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index 6655d5940d..8df0bf679d 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -26,12 +26,12 @@ from deeptools.heatmapper_utilities import plot_single, plotly_single, getProfileTicks from deeptools.computeMatrixOperations import filterHeatmapValues - debug = 0 +if debug: + from ipdb import set_trace old_settings = np.seterr(all='ignore') plt.ioff() - def parse_arguments(args=None): parser = argparse.ArgumentParser( parents=[parserCommon.heatmapperMatrixArgs(), @@ -111,6 +111,7 @@ def __init__(self, hm, out_file_name, plot_height=7, plot_width=11, per_group=False, + repgrplist=None, plot_type='lines', image_format=None, color_list=None, @@ -137,6 +138,7 @@ def __init__(self, hm, out_file_name, plot_height: in cm plot_width: in cm per_group: bool + repgrplist: list plot_type: string image_format: string color_list: list @@ -160,6 +162,7 @@ def __init__(self, hm, out_file_name, self.plot_height = plot_height self.plot_width = plot_width self.per_group = per_group + self.repgrplist = repgrplist self.plot_type = plot_type self.image_format = image_format self.color_list = color_list @@ -171,11 +174,13 @@ def __init__(self, hm, out_file_name, # Honor reference point labels from computeMatrix if reference_point_label is None: self.reference_point_label = hm.parameters['ref point'] - # decide how many plots are needed if self.per_group: self.numplots = self.hm.matrix.get_num_groups() - self.numlines = self.hm.matrix.get_num_samples() + if self.repgrplist: + self.numlines = len(set(self.repgrplist)) + else: + self.numlines = self.hm.matrix.get_num_samples() else: self.numplots = self.hm.matrix.get_num_samples() self.numlines = self.hm.matrix.get_num_groups() @@ -525,7 +530,7 @@ def plot_heatmap(self): if self.per_group: title = self.hm.matrix.group_labels[plot] - tickIdx = plot % self.hm.matrix.get_num_samples() + tickIdx = plot % self.numlines else: title = self.hm.matrix.sample_labels[plot] tickIdx = plot @@ -731,7 +736,7 @@ def plot_profile(self): title = self.hm.matrix.group_labels[plot] if row != 0 and len(self.y_min) == 1 and len(self.y_max) == 1: plt.setp(ax.get_yticklabels(), visible=False) - tickIdx = plot % self.hm.matrix.get_num_samples() + tickIdx = plot % self.numlines else: title = self.hm.matrix.sample_labels[plot] if col != 0 and len(self.y_min) == 1 and len(self.y_max) == 1: @@ -739,32 +744,71 @@ def plot_profile(self): tickIdx = plot ax.set_title(autobreaklinetitle(title)) - for data_idx in range(self.numlines): - if self.per_group: - _row, _col = plot, data_idx - else: - _row, _col = data_idx, plot - if localYMin is None or self.y_min[col % len(self.y_min)] < localYMin: - localYMin = self.y_min[col % len(self.y_min)] - if localYMax is None or self.y_max[col % len(self.y_max)] > localYMax: - localYMax = self.y_max[col % len(self.y_max)] - - sub_matrix = self.hm.matrix.get_matrix(_row, _col) - - if self.per_group: - label = sub_matrix['sample'] - else: - label = sub_matrix['group'] - - if self.numlines > 1: - coloridx = data_idx - else: - coloridx = plot - plot_single(ax, sub_matrix['matrix'], - self.averagetype, - self.color_list[coloridx], - label, - plot_type=self.plot_type) + if localYMin is None or self.y_min[col % len(self.y_min)] < localYMin: + localYMin = self.y_min[col % len(self.y_min)] + if localYMax is None or self.y_max[col % len(self.y_max)] > localYMax: + localYMax = self.y_max[col % len(self.y_max)] + if self.per_group and self.repgrplist: + nsamptmp = self.hm.matrix.get_num_samples() + repgrplistuniq = [] + repgrp_samp_dict = {} + for tmp in self.repgrplist: + if not tmp in repgrplistuniq: + repgrplistuniq.append(tmp) + for data_idx in range(nsamptmp): + thisrepgrp = repgrplistuniq[int(data_idx / (nsamptmp/self.numlines))] + try: + repgrp_samp_dict[thisrepgrp].append(data_idx) + except: + repgrp_samp_dict[thisrepgrp] = [ data_idx ] + + for irepgrp, repgrp in enumerate(repgrplistuniq): + sub_matrix_list = [] + for data_idx in repgrp_samp_dict[repgrp]: + _row, _col = plot, data_idx + sub_matrix = self.hm.matrix.get_matrix(_row, _col) + sub_matrix_list.append(sub_matrix['matrix']) + if debug: + set_trace() + + label = f"{repgrp}(n={len(repgrp_samp_dict[repgrp])})" + + if self.numlines > 1: + coloridx = irepgrp + else: + coloridx = plot + plot_single(ax, sub_matrix_list, + self.averagetype, + self.color_list[coloridx], + label, + plot_type=self.plot_type) + else: + for data_idx in range(self.numlines): + if self.per_group: + _row, _col = plot, data_idx + else: + _row, _col = data_idx, plot + if localYMin is None or self.y_min[col % len(self.y_min)] < localYMin: + localYMin = self.y_min[col % len(self.y_min)] + if localYMax is None or self.y_max[col % len(self.y_max)] > localYMax: + localYMax = self.y_max[col % len(self.y_max)] + + sub_matrix = self.hm.matrix.get_matrix(_row, _col) + + if self.per_group: + label = sub_matrix['sample'] + else: + label = sub_matrix['group'] + + if self.numlines > 1: + coloridx = data_idx + else: + coloridx = plot + plot_single(ax, sub_matrix['matrix'], + self.averagetype, + self.color_list[coloridx], + label, + plot_type=self.plot_type) globalYmin = min(np.float64(globalYmin), ax.get_ylim()[0]) globalYmax = max(globalYmax, ax.get_ylim()[1]) @@ -970,6 +1014,7 @@ def main(args=None): plot_height=args.plotHeight, plot_width=args.plotWidth, per_group=args.perGroup, + repgrplist=args.repgrplist, plot_type=args.plotType, image_format=args.plotFileFormat, color_list=args.colors, From f05c5faf8eaebf1f45d9cf1517d133f2150e04c7 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 22 Nov 2023 14:39:06 -0600 Subject: [PATCH 09/11] debug --repgrplist if number matching number of samples --- deeptools/parserCommon.py | 2 +- deeptools/plotProfile.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/deeptools/parserCommon.py b/deeptools/parserCommon.py index 23de9e6472..ce11b399f5 100755 --- a/deeptools/parserCommon.py +++ b/deeptools/parserCommon.py @@ -852,7 +852,7 @@ def heatmapperOptionalArgs(mode=['heatmap', 'profile'][0]): help='Group profiles by genotype' 'assign each profile to a group(as replicates) to plot average +/- se/std.' 'If the number of group values is smaller than' - 'the number of plots, the values are recycled.') + 'the number of samples, the values will be equally divide into groups.') optional.add_argument('--plotFileFormat', metavar='', diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index 8df0bf679d..69b536b37a 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -750,17 +750,25 @@ def plot_profile(self): localYMax = self.y_max[col % len(self.y_max)] if self.per_group and self.repgrplist: nsamptmp = self.hm.matrix.get_num_samples() - repgrplistuniq = [] repgrp_samp_dict = {} - for tmp in self.repgrplist: - if not tmp in repgrplistuniq: - repgrplistuniq.append(tmp) - for data_idx in range(nsamptmp): - thisrepgrp = repgrplistuniq[int(data_idx / (nsamptmp/self.numlines))] - try: - repgrp_samp_dict[thisrepgrp].append(data_idx) - except: - repgrp_samp_dict[thisrepgrp] = [ data_idx ] + if len(self.repgrplist) == nsamptmp: + for data_idx in range(nsamptmp): + thisrepgrp = self.repgrplist[data_idx] + try: + repgrp_samp_dict[thisrepgrp].append(data_idx) + except: + repgrp_samp_dict[thisrepgrp] = [ data_idx ] + else: + repgrplistuniq = [] + for tmp in self.repgrplist: + if not tmp in repgrplistuniq: + repgrplistuniq.append(tmp) + for data_idx in range(nsamptmp): + thisrepgrp = repgrplistuniq[int(data_idx / (nsamptmp/self.numlines))] + try: + repgrp_samp_dict[thisrepgrp].append(data_idx) + except: + repgrp_samp_dict[thisrepgrp] = [ data_idx ] for irepgrp, repgrp in enumerate(repgrplistuniq): sub_matrix_list = [] From 01caa598f8125541d3a4d06b48a9f08387414553 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 22 Nov 2023 14:45:20 -0600 Subject: [PATCH 10/11] debug --repgrplist if number matching number of samples --- deeptools/plotProfile.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index 69b536b37a..7bf4c61b78 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -751,24 +751,20 @@ def plot_profile(self): if self.per_group and self.repgrplist: nsamptmp = self.hm.matrix.get_num_samples() repgrp_samp_dict = {} - if len(self.repgrplist) == nsamptmp: - for data_idx in range(nsamptmp): + repgrplistuniq = [] + for tmp in self.repgrplist: + if not tmp in repgrplistuniq: + repgrplistuniq.append(tmp) + + for data_idx in range(nsamptmp): + if len(self.repgrplist) >= nsamptmp: thisrepgrp = self.repgrplist[data_idx] - try: - repgrp_samp_dict[thisrepgrp].append(data_idx) - except: - repgrp_samp_dict[thisrepgrp] = [ data_idx ] - else: - repgrplistuniq = [] - for tmp in self.repgrplist: - if not tmp in repgrplistuniq: - repgrplistuniq.append(tmp) - for data_idx in range(nsamptmp): + else: thisrepgrp = repgrplistuniq[int(data_idx / (nsamptmp/self.numlines))] - try: - repgrp_samp_dict[thisrepgrp].append(data_idx) - except: - repgrp_samp_dict[thisrepgrp] = [ data_idx ] + try: + repgrp_samp_dict[thisrepgrp].append(data_idx) + except: + repgrp_samp_dict[thisrepgrp] = [ data_idx ] for irepgrp, repgrp in enumerate(repgrplistuniq): sub_matrix_list = [] From 4e19dcbb4c79be497c306be928280165c74101f3 Mon Sep 17 00:00:00 2001 From: "Xu, Beisi" Date: Wed, 22 Nov 2023 14:52:38 -0600 Subject: [PATCH 11/11] debug --repgrplist if number matching number of samples --- deeptools/plotProfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeptools/plotProfile.py b/deeptools/plotProfile.py index 7bf4c61b78..dddea44482 100755 --- a/deeptools/plotProfile.py +++ b/deeptools/plotProfile.py @@ -766,14 +766,14 @@ def plot_profile(self): except: repgrp_samp_dict[thisrepgrp] = [ data_idx ] + if debug: + set_trace() for irepgrp, repgrp in enumerate(repgrplistuniq): sub_matrix_list = [] for data_idx in repgrp_samp_dict[repgrp]: _row, _col = plot, data_idx sub_matrix = self.hm.matrix.get_matrix(_row, _col) sub_matrix_list.append(sub_matrix['matrix']) - if debug: - set_trace() label = f"{repgrp}(n={len(repgrp_samp_dict[repgrp])})"