Skip to content

Commit

Permalink
[WIP] added auto to plotheatmap #908 (#982)
Browse files Browse the repository at this point in the history
* added auto to plotheatmap

* fixed lint, added warning message, updated the help for zmin, zmax

* galaxy test plotPCA

* lower down the delat for potPCA galaxy test

Co-authored-by: Leily Rabbani <rabbani@pc390.ie-freiburg.mpg.de>
  • Loading branch information
LeilyR and Leily Rabbani authored Aug 10, 2020
1 parent a3ddfd4 commit 979241f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
10 changes: 6 additions & 4 deletions deeptools/parserCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,17 @@ def heatmapperOptionalArgs(mode=['heatmap', 'profile'][0]):
default=None,
help='Minimum value for the heatmap intensities. Multiple values, separated by '
'spaces can be set for each heatmap. If the number of zMin values is smaller than'
'the number of heatmaps the values are recycled.',
type=float,
'the number of heatmaps the values are recycled. If a value is set to "auto", it will be set '
' to the first percentile of the matrix values.',
type=str,
nargs='+')
optional.add_argument('--zMax', '-max',
default=None,
help='Maximum value for the heatmap intensities. Multiple values, separated by '
'spaces can be set for each heatmap. If the number of zMax values is smaller than'
'the number of heatmaps the values are recycled.',
type=float,
'the number of heatmaps the values are recycled. If a value is set to "auto", it will be set '
' to the 98th percentile of the matrix values.',
type=str,
nargs='+')
optional.add_argument('--heatmapHeight',
help='Plot height in cm. The default for the heatmap '
Expand Down
27 changes: 27 additions & 0 deletions deeptools/plotHeatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ def plotMatrix(hm, outFileName,
zMin = [None]
else:
zMin = [zMin] # convert to list to support multiple entries
elif 'auto' in zMin:
matrix_flatten = hm.matrix.flatten()
auto_min = np.percentile(matrix_flatten, 1.0)
if np.isnan(auto_min):
auto_min = None
new_mins = [float(x) if x != 'auto' else auto_min for x in zMin]
zMin = new_mins
else:
new_mins = [float(x) for x in zMin]
zMin = new_mins

if zMax is None:
if matrix_flatten is None:
Expand All @@ -422,6 +432,23 @@ def plotMatrix(hm, outFileName,
zMax = [None]
else:
zMax = [zMax]
elif 'auto' in zMax:
matrix_flatten = hm.matrix.flatten()
auto_max = np.percentile(matrix_flatten, 98.0)
if np.isnan(auto_max):
auto_max = None
new_maxs = [float(x) if x != 'auto' else auto_max for x in zMax]
zMax = new_maxs
else:
new_maxs = [float(x) for x in zMax]
zMax = new_maxs
if (len(zMin) > 1) & (len(zMax) > 1):
for index, value in enumerate(zMax):
if value <= zMin[index]:
sys.stderr.write("Warnirng: In bigwig {}, the given zmin ({}) is larger than "
"or equal to the given zmax ({}). Thus, it has been set "
"to None. \n".format(index + 1, zMin[index], value))
zMin[index] = None

if yMin is None:
yMin = [None]
Expand Down
2 changes: 1 addition & 1 deletion galaxy/wrapper/plotPCA.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<param name="outFileFormat" value="png" />
<param name="outFileNameData" value="True" />
<output name="outFileName" file="plotPCA_result2.png" ftype="png" compare="sim_size" delta="12000" />
<output name="output_outFileNameData" file="plotPCA_result2.tabular" ftype="tabular" />
<output name="output_outFileNameData" file="plotPCA_result2.tabular" ftype="tabular" compare="sim_size" delta="12000" />
</test>
</tests>
<help>
Expand Down

0 comments on commit 979241f

Please sign in to comment.