Skip to content

Commit

Permalink
+ heatmaps hauto, hmin and hmax options
Browse files Browse the repository at this point in the history
  • Loading branch information
Pombert-JF committed May 3, 2024
1 parent af728ee commit 548b5b3
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 93 deletions.
71 changes: 51 additions & 20 deletions Plots/paf_to_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
## Pombert lab, 2024
version = '0.1b'
updated = '2024-05-01'
version = '0.2'
updated = '2024-05-03'
name = 'paf_to_heatmap.py'

import sys
Expand Down Expand Up @@ -35,11 +35,14 @@
-o (--outdir) Output directory [Default: ./]
-h (--height) Figure height in inches [Default: 10]
-w (--width) Figure width in inches [Default: 10]
-x (--matrix) Matrix output file [Default: matrix.tsv]
-c (--palette) Seaborn color palette [Default: winter_r]
# See https://www.practicalpythonfordatascience.com/ap_seaborn_palette
# for a list of color palettes
--fontsize Font size [Default: 8]
-x (--matrix) Matrix output file [Default: matrix.tsv]
--vmax Set maximum color bar value [Default: 100]
--vmin Set minimum color bar value [Default: 0]
--vauto Set color bar values automatically instead
"""

# Print custom message if argv is empty
Expand All @@ -60,16 +63,22 @@
cmd.add_argument("-c", "--palette", default='winter_r')
cmd.add_argument("-x", "--matrix", default='matrix.tsv')
cmd.add_argument("--fontsize", default=8)
cmd.add_argument("--vmin", default=0)
cmd.add_argument("--vmax", default=100)
cmd.add_argument("--vauto", action='store_true')
args = cmd.parse_args()

paf_files = args.paf
fasta_files = args.fasta
outdir = args.outdir
height = args.height
width = args.width
matrix_file = args.matrix
color_palette = args.palette
fontsize = int(args.fontsize)
matrix_file = args.matrix
vmin = int(args.vmin)
vmax = int(args.vmax)
vauto = args.vauto

################################################################################
## Working on output directory
Expand Down Expand Up @@ -208,14 +217,25 @@
heatmap_svg = svgdir + '/' + 'colinear_bases.mmap.heatmap.svg'

## Clustered heatmaps
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=0,
vmax=100
)
cm = None

if vauto:
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f'
)

else:
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=vmin,
vmax=vmax
)

cm.fig.suptitle(f"% of total bases in pairwise alignments", x=0.5, y=0.95)
print(f"1 / 4 - Plotting {clustered_png}")
Expand All @@ -227,14 +247,25 @@
plt.close('all')

## Normal heatmaps
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=0,
vmax=100
)
hm = None

if vauto:
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f'
)

else:
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=vmin,
vmax=vmax
)

hm.figure.suptitle(f"% of colinear bases in pairwise alignments", x=0.5, y=0.95)
print(f"3 / 4 - Plotting {heatmap_png}")
Expand Down
67 changes: 49 additions & 18 deletions Plots/protein_cluster_hm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
## Pombert lab, 2024

name = 'protein_cluster_hm.py'
version = '0.3c'
updated = '2024-05-01'
version = '0.3d'
updated = '2024-05-03'

import sys
import os
Expand Down Expand Up @@ -37,6 +37,9 @@
-h (--height) Figure height in inches [Default: 10]
-w (--width) Figure width in inches [Default: 10]
--fontsize Font size [Default: 8]
--vmax Set maximum color bar value [Default: 100]
--vmin Set minimum color bar value [Default: 0]
--vauto Set color bar values automatically instead
--threads Number of threads to use [Default: 16]
"""

Expand All @@ -56,6 +59,9 @@
cmd.add_argument("-w", "--width", default=10)
cmd.add_argument("-p", "--palette", default='winter_r')
cmd.add_argument("--fontsize", default=8)
cmd.add_argument("--vmin", default=0)
cmd.add_argument("--vmax", default=100)
cmd.add_argument("--vauto", action='store_true')
cmd.add_argument("--threads", default=16)
args = cmd.parse_args()

Expand All @@ -65,6 +71,9 @@
width = args.width
color_palette = args.palette
fontsize = int(args.fontsize)
vmin = int(args.vmin)
vmax = int(args.vmax)
vauto = args.vauto
threads = int(args.threads)

################################################################################
Expand Down Expand Up @@ -111,14 +120,25 @@ def heatmap(tsv_file):
heatmap_svg = svgdir + '/' + 'proteins_in_clusters.gap_' + gap + '.heatmap.svg'

## Clustered heatmaps
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=0,
vmax=100,
)
cm = None

if vauto:
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f'
)

else:
cm = sns.clustermap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=vmin,
vmax=vmax
)

cm.fig.suptitle(f"% of protein-coding genes in clusters (gap = {gap})", x=0.5, y=0.95)
with counter.get_lock():
Expand All @@ -133,14 +153,25 @@ def heatmap(tsv_file):
plt.close('all')

## Normal heatmaps
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=0,
vmax=100
)
hm = None

if vauto:
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f'
)

else:
hm = sns.heatmap(
data[0:],
cmap=color_palette,
annot=True,
fmt='.1f',
vmin=vmin,
vmax=vmax
)

hm.figure.suptitle(f"% of proteins found in clusters (gap = {gap})", x=0.5, y=0.95)
with counter.get_lock():
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ Options for run_SYNY.pl are:
-hw (--hwidth) Heatmap figure width in inches [Default: 10]
--hfsize Heatmap font size [Default: 8]
--hmpalette Heatmap color palette [Default: winter_r]
--hmax Set maximum color bar value [Default: 100]
--hmin Set minimum color bar value [Default: 0]
--hauto Set color bar values automatically instead
--no_heatmap Turn off heatmaps
```
The output directory will be structured as follows:
Expand Down Expand Up @@ -535,7 +538,7 @@ In the above example, small heatmaps with 25 datapoints (5 * 5 genomes) will be
<img src="https://github.com/PombertLab/SYNY/blob/main/Images/proteins_in_clusters.gap_0.heatmap.png">
</p>

Heatmap dimensions (default: 10 x 10) can be modified with the `--hheight` and `--hwidth` command line switches. The color palette (default: winter_r) can be modified with the `--hmpalette` command line switch (see this [URL](https://github.com/PombertLab/SYNY/blob/main/Images/python_color_palettes.png) for a list of color palettes). Color palettes available on the operating system can be listed and/or plotted with [check_mp_colors.py](https://github.com/PombertLab/SYNY/blob/main/Utils/check_mp_colors.py).
Heatmap dimensions (default: 10 x 10) can be modified with the `--hheight` and `--hwidth` command line switches. Color bar min/max values (defaults: 0/100) can be changed with the `--hmin` and `--hmax` command line switches or calculated automatically with `--hauto`. The heatmap color palette (default: winter_r) can be changed with the `--hmpalette` command line switch (see this [URL](https://github.com/PombertLab/SYNY/blob/main/Images/python_color_palettes.png) for a list of color palettes). Color palettes available on the operating system can be listed and/or plotted with [check_mp_colors.py](https://github.com/PombertLab/SYNY/blob/main/Utils/check_mp_colors.py).

#### Circos plots

Expand Down
Loading

0 comments on commit 548b5b3

Please sign in to comment.