diff --git a/deeptools/heatmapper.py b/deeptools/heatmapper.py index 6a95ba0052..a989598ccd 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):