From 3a8d76402a06b6ae3d583245c838df646a7ce9e1 Mon Sep 17 00:00:00 2001 From: jarbona <121-jarbona@users.noreply.gitbio.ens-lyon.fr> Date: Thu, 20 Jan 2022 13:53:02 +0100 Subject: [PATCH 1/2] Adding independent ranges by sample option: for zMax zMin yMin and yMax adding the possibility to set them to the value independent. It creates different ranges for each samples --- deeptools/heatmapper.py | 8 ++++++++ deeptools/plotHeatmap.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index 6a95ba0052..a18f7d2cdf 100644 --- a/deeptools/heatmapper.py +++ b/deeptools/heatmapper.py @@ -1150,6 +1150,14 @@ def get_num_samples(self): def get_num_groups(self): return len(self.group_labels) + def get_percentile_by_samples(self,percentile): + percentile_per_samples = [] + for sample in range(self.get_num_samples()): + sample_start = self.sample_boundaries[sample] + sample_end = self.sample_boundaries[sample + 1] + percentile_per_samples.append(np.percentile(np.ma.masked_invalid(self.matrix[:,sample_start:sample_end]),percentile)) + return percentile_per_samples + def set_group_labels(self, new_labels): """ sets new labels for groups """ diff --git a/deeptools/plotHeatmap.py b/deeptools/plotHeatmap.py index bc4bbcc2a4..5f03063d65 100755 --- a/deeptools/plotHeatmap.py +++ b/deeptools/plotHeatmap.py @@ -186,7 +186,11 @@ def addProfilePlot(hm, plt, fig, grids, iterNum, iterNum2, perGroup, averageType # It turns out that set_ylim only takes np.float64s for sample_id, subplot in enumerate(ax_list): localYMin = yMin[sample_id % len(yMin)] + if localYMin == "independent": + localYMin = ax_list[sample_id].get_ylim()[0] localYMax = yMax[sample_id % len(yMax)] + if localYMax == "independent": + localYMax = ax_list[sample_id].get_ylim()[1] lims = [globalYmin, globalYmax] if localYMin: if localYMax: @@ -412,6 +416,8 @@ def plotMatrix(hm, outFileName, zMin = [None] else: zMin = [zMin] # convert to list to support multiple entries + elif zMin == ["independent"]: + zMin = hm.matrix.get_percentile_by_samples(1.0) elif 'auto' in zMin: matrix_flatten = hm.matrix.flatten() auto_min = np.percentile(matrix_flatten, 1.0) @@ -432,6 +438,8 @@ def plotMatrix(hm, outFileName, zMax = [None] else: zMax = [zMax] + elif zMax == ["independent"]: + zMax = hm.matrix.get_percentile_by_samples(98.0) elif 'auto' in zMax: matrix_flatten = hm.matrix.flatten() auto_max = np.percentile(matrix_flatten, 98.0) @@ -452,8 +460,13 @@ def plotMatrix(hm, outFileName, if yMin is None: yMin = [None] + elif yMin == ["independent"]: + yMin = ["independent"] * hm.matrix.get_num_samples() + if yMax is None: yMax = [None] + elif yMax == ["independent"]: + yMax = ["independent"] * hm.matrix.get_num_samples() if not isinstance(yMin, list): yMin = [yMin] if not isinstance(yMax, list): From a9ebb1e94b025247ed4bacf274c2acac74f33e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gr=C3=BCning?= Date: Tue, 4 Apr 2023 19:18:58 +0200 Subject: [PATCH 2/2] small style changes --- deeptools/heatmapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index a18f7d2cdf..a989598ccd 100644 --- a/deeptools/heatmapper.py +++ b/deeptools/heatmapper.py @@ -1150,7 +1150,7 @@ def get_num_samples(self): def get_num_groups(self): return len(self.group_labels) - def get_percentile_by_samples(self,percentile): + def get_percentile_by_samples(self, percentile): percentile_per_samples = [] for sample in range(self.get_num_samples()): sample_start = self.sample_boundaries[sample]