tseemann / snp-dists

Pairwise SNP distance matrix from a FASTA sequence alignment
GNU General Public License v3.0
126 stars 28 forks source link

Plotting output #40

Open mbhall88 opened 4 years ago

mbhall88 commented 4 years ago

Hey @tseemann

I've created a (python) script for plotting the matrix output from this tool as an interactive heatmap which others might find useful.

Feel free to link to it from the README if you like, or I guess people can just find it here in the issues too.

Usage

$ python plot_distance_matrix.py --help
Usage: plot_distance_matrix.py [OPTIONS]

  This script generates an interactive heatmap (HTML) for a distance matrix.

Options:
  -h, --help                      Show this message and exit.
  -i, --matrix FILE               Distance matrix to plot.  [default: -]
  -o, --output FILE               Path to save HTML plot to.  [default:
                                  heatmap.html]
  -d, --delim TEXT                Delimiter used in the matrix. [ default:
                                  '\t']
  -p, --palette [YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn|Accent|Dark2|Paired|Pastel1|Pastel2|Set1|Set2|Set3]
                                  ColorBrewer palette to use for heatmap.
                                  [default: RdBu]
  -t, --title TEXT                Title for the heatmap.  [default: Pairwise
                                  distance matrix]
  --width INTEGER                 Plot width in pixels  [default: 900]
  --height INTEGER                Plot height in pixels  [default: 900]

Static example

heatmap

Interactive example

heatmap.html.gz

guillemmasfiol commented 3 years ago

Very nice script @mbhall88, thank you!

Perhaps it would be really useful to add a functionality to cluster the sequences according to their SNP distance. There are already R packages to treat such heatmaps; one of them allows to include use a precomputed phylogeny to cluster the heatmap (https://rdrr.io/cran/phytools/man/phylo.heatmap.html)

mbhall88 commented 3 years ago

I would welcome a PR to add that functionality @guillemmasfiol