Volcano Plot – Gnuplot

One can benefit from different types of plots in order to better understand RNA-Seq data. A interesting one is the volcano plot.

Why not to give it a try using Gnuplot?

As toy, I am using DESeq2 output of airway dataset analysis.

My Gnuplot setup:

gnuplot> show version long

        G N U P L O T
        Version 5.2 patchlevel 7    last modified 2019-05-29 

        Copyright (C) 1986-1993, 1998, 2004, 2007-2018
        Thomas Williams, Colin Kelley and many others

        gnuplot home:     http://www.gnuplot.info
        faq, bugs, etc:   type "help FAQ"
        immediate help:   type "help"  (plot window: hit 'h')

Compile options:
    -READLINE  +LIBEDITLINE  +HISTORY  
    -BACKWARDS_COMPATIBILITY  +OBJECTS  +STATS +EXTERNAL_FUNCTIONS 
    +GD_PNG  +GD_JPEG  +GD_TTF  +GD_GIF  +ANIMATION  
    -USE_CWDRC  +X11  +X11_EXTERNAL +USE_MOUSE  +HIDDEN3D_QUADTREE  
    MAX_PARALLEL_AXES=13

GNUPLOT_DRIVER_DIR = "/usr/lib/gnuplot"
GNUPLOT_PS_DIR     = "/usr/share/gnuplot/gnuplot/5.2/PostScript"
HELPFILE           = "/usr/share/gnuplot/gnuplot.gih"

For this plot, the idea is highlight set of genes that make a established threshold for log2FC (<-2.5 or >2.5) and -log10(padj) (>3) values. The code follows:

#!/usr/bin/gnuplot -persist

set key autotitle columnhead # ignore tsv header
 
set palette defined (0 0.5 0.5 0.5, 1 1 0 0) # (grey, red)

unset colorbox               # get rid of the colorbox

set grid                     # get grid

log2fc_neg = -2.5            # log2FC threshold (negative) 
log2fc_pos = 2.5             # log2FC threshold (positive) 
padj = 3                     # padj threshold 

# function to select hits that make the thresholds
isDE(x,y) = ((x < log2fc_neg || x > log2fc_pos) && y > padj) ? 1: 0

# title and labels
set title "Airway dataset - VolcanoPlot" font "Helvetica,15"
set xlabel "log2FC"
set ylabel "-log10(padj)"

# set ranges
set xrange[-10:10]
set yrange[0:150]

# res.tsv - DESeq2 output file
plot 'res.tsv' \
using 3:(log10($7)*-1):(isDE($3,log10($7)*-1)) \
with points \
pt 7 \
ps 0.75 \
palette \
notitle, \
'' u 3:(log10($7)*-1):((($3 > log2fc_pos || $3 < log2fc_neg) && (log10($7)*-1)>padj) ? strcol(1) : sprintf ("")) \
with labels \
notitle \
offset 0,-0.5

And the result:

References

Gnuplot – http://www.gnuplot.info/

Interesting post on gnuplot and conditionals – https://stackoverflow.com/questions/14993538/using-gnuplot-to-plot-point-colors-conditionally

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s