Class: BioDSL::PlotHeatmap

Inherits:
Object
  • Object
show all
Includes:
AuxHelper
Defined in:
lib/BioDSL/commands/plot_heatmap.rb

Overview

Plot tabular numerical data in a heatmap.

A heatmap can be plotted with plot_heatmap using numerical data (Non- numerical data is ignored). Data should be tabular with records as rows and keys as columns - the data cells plotted will be the values.

Default graphics are crufty ASCII and you probably want high resolution postscript or SVG output instead with is easy using the terminal option. Plotting is done using GNUplot which allows for different types of output.

GNUplot must be installed for plot_heatmap to work. Read more here:

www.gnuplot.info/

Usage

plot_heatmap([keys: <list> | skip: <list>[, output: <file>
             [, force: <bool> [, terminal: <string>
             [, title: <string>[, xlabel: <string>[, ylabel: <string>
             [, test: <bool>]]]]]]])

Options

  • keys: <list> - Comma separated list of keys to plot as columns.

  • skip: <list> - Comma separated list of keys to skip as columns.

  • output: <file> - Output file.

  • force: <bool> - Force overwrite existing output file.

  • terminal: <string> - Terminal for output: dumb|post|svg|x11|aqua|png|pdf

    (default=dumb).
    
  • title: <string> - Plot title (default=“Heatmap”).

  • xlabel: <string> - X-axis label (default=“x”).

  • ylabel: <string> - Y-axis label (default=“y”).

  • test: <bool> - Output Gnuplot script instead of plot.

Examples

Here we plot a heatmap of data a table:

BD.new.read_table(input: "test.tab").plot_heatmap.run

Constant Summary collapse

STATS =
%i(records_in records_out)

Instance Method Summary collapse

Methods included from AuxHelper

#aux_exist

Constructor Details

#initialize(options) ⇒ PlotHeatmap

Constructor for PlotHeatmap.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :keys (Array)

    List of keys to plot as column.

  • :skip (Array)

    List of keys to skip as column.

  • :output (String)

    Path to output file.

  • :forcea (Boolean)

    Flag to force overwrite output file.

  • :terminal (Symbol)

    Set plot terminal type.

  • :title (String)

    Set plot title.

  • :xlabel (String)

    Set plot xlabel.

  • :ylabel (String)

    Set plot ylabel

  • :logscale (Boolean)

    Logscale Z-axis.

  • :test (Boolean)

    Output gnuplot script.



93
94
95
96
97
98
99
100
101
# File 'lib/BioDSL/commands/plot_heatmap.rb', line 93

def initialize(options)
  @options   = options
  @headings  = nil
  @skip_keys = determine_skip_keys

  aux_exist('gnuplot')
  check_options
  defaults
end

Instance Method Details

#lmbProc

Return command lambda for plot_histogram.

Returns:

  • (Proc)

    Command lambda.



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/BioDSL/commands/plot_heatmap.rb', line 106

def lmb
  lambda do |input, output, status|
    status_init(status, STATS)

    gp = GnuPlotter.new

    plot_options(gp)
    plot_dataset(gp, input, output)
    plot_output(gp)
  end
end