Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding independent ranges by sample option: for zMax zMin yMin and y… #1116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deeptools/heatmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
13 changes: 13 additions & 0 deletions deeptools/plotHeatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand Down