de.jstacs.utils
Class SeqLogoPlotter

java.lang.Object
  extended by de.jstacs.utils.SeqLogoPlotter

public class SeqLogoPlotter
extends Object

Class with static methods for plotting sequence logos of DNA motifs, i.e., position weight matrices defined over a DNAAlphabet. In general, sequence logos can be plotted to any Graphics2D object, e.g., for on-screen printing using the plotLogo methods. For convenience, the method plotLogoToPNG(String, int, double[][]) can be used to directly plot a sequence logo to a PNG file with a given height and automatically chosen aspect ratio.

Author:
Jan Grau

Constructor Summary
SeqLogoPlotter()
           
 
Method Summary
protected static Pair<BufferedImage,Graphics2D> getBufferedImageAndGraphics(int height, double[][] ps)
          Creates a new BufferedImage with given height and width chosen automatically according to the number of rows of ps, and returns this BufferedImage and its Graphics2D object.
static int getHeight(int width, double[][] ps)
          Returns the automatically chosen height for a given width and position weight matrix.
static int getWidth(int height, double[][] ps)
          Returns the automatically chosen width for a given height and position weight matrix.
static void plotLogo(Graphics2D g, int h, double[][] ps)
          Plots the sequence logo for the position weight matrix given in ps.
static void plotLogo(Graphics2D g, int height, double[][] ps, String[] labels, String labX, String labY)
          Plots the sequence logo for the position weight matrix given in ps.
static void plotLogo(Graphics2D g, int w, int h, double[][] ps, String[] labels, String labX, String labY)
          Plots the sequence logo for the position weight matrix given in ps.
static void plotLogo(Graphics2D g, int x, int y, int w, int h, double[][] ps, String[] labels, String labX, String labY)
          Plots the sequence logo for the position weight matrix given in ps.
static BufferedImage plotLogoToBufferedImage(int height, double[][] ps)
          Plots the sequence logo for the position weight matrix given in ps.
static void plotLogoToPNG(String path, int height, double[][] ps)
          Plots the sequence logo for the position weight matrix given in ps.
static void plotTALgetterLogo(Graphics2D g, int x, int y, int w, int h, double[][] ps, double[] imp, String[] labels, String labX, String labY, String labY2)
          Plots the TALgetter logo for the binding specificities given in ps.
static BufferedImage plotTALgetterLogoToBufferedImage(int height, double[][] ps, double[] imp, String[] lab)
          Plots the TALgetter logo for the binding specificities given in ps.
static void plotTALgetterLogoToPNG(String path, int height, double[][] ps, double[] imp, String[] lab)
          Plots the TALgetter logo for the binding specificities given in ps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SeqLogoPlotter

public SeqLogoPlotter()
Method Detail

plotLogoToPNG

public static void plotLogoToPNG(String path,
                                 int height,
                                 double[][] ps)
                          throws IOException
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. The positions of the sequence logo are numbered contiguously from 1 to ps.length. The label of the x-axis is set to "Position", and the label of the y-axis is set to "bits". The sequence logo is written to the PNG file given in path.

Parameters:
path - the path to the PNG file written
height - the height of the PNG image (in pixels)
ps - the position weight matrix
Throws:
IOException - if the file could not be written

plotLogoToBufferedImage

public static BufferedImage plotLogoToBufferedImage(int height,
                                                    double[][] ps)
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. The positions of the sequence logo are numbered contiguously from 1 to ps.length. The label of the x-axis is set to "Position", and the label of the y-axis is set to "bits". The sequence logo is return as a BufferedImage.

Parameters:
height - the height of the PNG image (in pixels)
ps - the position weight matrix
Returns:
the sequence logo

getBufferedImageAndGraphics

protected static Pair<BufferedImage,Graphics2D> getBufferedImageAndGraphics(int height,
                                                                            double[][] ps)
Creates a new BufferedImage with given height and width chosen automatically according to the number of rows of ps, and returns this BufferedImage and its Graphics2D object.

Parameters:
height - the height (in pixels)
ps - the position weight matrix
Returns:
the created BufferedImage and its Graphics2D object

plotLogo

public static void plotLogo(Graphics2D g,
                            int h,
                            double[][] ps)
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. The positions of the sequence logo are numbered contiguously from 1 to ps.length. The label of the x-axis is set to "Position", and the label of the y-axis is set to "bits". The sequence logo is written to the Graphics2D object given in g.

Parameters:
g - the Graphics2D object
h - the height of the sequence logo
ps - the position weight matrix

plotLogo

public static void plotLogo(Graphics2D g,
                            int height,
                            double[][] ps,
                            String[] labels,
                            String labX,
                            String labY)
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. The sequence logo is written to the Graphics2D object given in g.

Parameters:
g - the Graphics2D object
height - the height of the sequence logo
ps - the position weight matrix
labels - the labels of the positions of the sequence logo, if null the positions are numbered contiguously from 1 to ps.length
labX - the label of the x-axis
labY - the label of the y-axis

getWidth

public static int getWidth(int height,
                           double[][] ps)
Returns the automatically chosen width for a given height and position weight matrix.

Parameters:
height - the height
ps - the position weight matrix
Returns:
the width

getHeight

public static int getHeight(int width,
                            double[][] ps)
Returns the automatically chosen height for a given width and position weight matrix.

Parameters:
width - the width
ps - the position weight matrix
Returns:
the height

plotLogo

public static void plotLogo(Graphics2D g,
                            int w,
                            int h,
                            double[][] ps,
                            String[] labels,
                            String labX,
                            String labY)
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. The sequence logo is written to the Graphics2D object given in g.

Parameters:
g - the Graphics2D object
w - the width of the sequence logo
h - the height of the sequence logo
ps - the position weight matrix
labels - the labels of the positions of the sequence logo, if null the positions are numbered contiguously from 1 to ps.length
labX - the label of the x-axis
labY - the label of the y-axis

plotLogo

public static void plotLogo(Graphics2D g,
                            int x,
                            int y,
                            int w,
                            int h,
                            double[][] ps,
                            String[] labels,
                            String labX,
                            String labY)
Plots the sequence logo for the position weight matrix given in ps. The rows of ps correspond to positions in the sequence logo. Each row must be normalized. The sequence logo is written to the Graphics2D object given in g.

Parameters:
g - the Graphics2D object
x - the x-coordinate of the bottom left corner of the sequence logo
y - the y-coordinate of the bottom left corner of the sequence logo (-h results in a sequence logo spanning from 0 to h)
w - the width of the sequence logo
h - the height of the sequence logo
ps - the position weight matrix
labels - the labels of the positions of the sequence logo, if null the positions are numbered contiguously from 1 to ps.length
labX - the label of the x-axis
labY - the label of the y-axis

plotTALgetterLogoToPNG

public static void plotTALgetterLogoToPNG(String path,
                                          int height,
                                          double[][] ps,
                                          double[] imp,
                                          String[] lab)
                                   throws IOException
Plots the TALgetter logo for the binding specificities given in ps. The rows of ps correspond to specificities of the RVDs. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. In addition, the importance of RVDs is plotted as given in imp. The labels of the RVDs are given in lab. The label of the x-axis is set to "RVD", and the label of the y-axes are set to "bits" and "Importance", respectively. The TALgetter logo is written to the PNG file given in path.

Parameters:
path - the path to the PNG file written
height - the height of the PNG image (in pixels)
ps - the binding specificities of RVDs
imp - the importance of RVDs
lab - the amino acids of the RVDs in one-letter code
Throws:
IOException - if the file could not be written

plotTALgetterLogoToBufferedImage

public static BufferedImage plotTALgetterLogoToBufferedImage(int height,
                                                             double[][] ps,
                                                             double[] imp,
                                                             String[] lab)
Plots the TALgetter logo for the binding specificities given in ps. The rows of ps correspond to specificities of the RVDs. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. In addition, the importance of RVDs is plotted as given in imp. The labels of the RVDs are given in lab. The label of the x-axis is set to "RVD", and the label of the y-axes are set to "bits" and "Importance", respectively. The TALgetter logo is returned as BufferedImage.

Parameters:
height - the height of the PNG image (in pixels)
ps - the binding specificities of RVDs
imp - the importance of RVDs
lab - the amino acids of the RVDs in one-letter code
Returns:
the TALgetter logo

plotTALgetterLogo

public static void plotTALgetterLogo(Graphics2D g,
                                     int x,
                                     int y,
                                     int w,
                                     int h,
                                     double[][] ps,
                                     double[] imp,
                                     String[] labels,
                                     String labX,
                                     String labY,
                                     String labY2)
Plots the TALgetter logo for the binding specificities given in ps. The rows of ps correspond to specificities of the RVDs. Each row must be normalized. For a given height (in pixels), the width is chosen automatically depending on the number of rows in ps. In addition, the importance of RVDs is plotted as given in imp. The labels of the RVDs are given in lab. The label of the x-axis is set to "RVD", and the label of the y-axes are set to "bits" and "Importance", respectively. The TALgetter logo is returned as BufferedImage.

Parameters:
g - the Graphics2D object
x - the x-coordinate of the bottom left corner of the TALgetter logo
y - the y-coordinate of the bottom left corner of the TALgetter logo (-h results in a logo spanning from 0 to h)
w - the width of the TALgetter logo
h - the height of the TALgetter logo
ps - the binding specificities of RVDs
imp - the importance of RVDs
labels - the amino acids of the RVDs in one-letter code
labX - the label of the x-axis
labY - the label of the y-axis
labY2 - the label of the second (importance) y-axis