binf 634 fall 2013 - lec 11 visualization1 plan for tonight a synopsis of our progress through the...
TRANSCRIPT
BINF 634 Fall 2013 - Lec 11 Visualization 1
Plan for Tonight
A synopsis of our progress through the course
Lecture 11 Visualization in PERL
Lab 2
Based in Part on Previous Lecture of J. Grefenstette
Outline
BINF 634 Fall 2013 - Lec 11 Visualization 2
Where We are and Where We are Going
Program 1, Program 2, turned in and graded Midterm turned in and graded Program 3 turned in, Program 4 assigned tonight
Program 4 due in two week (11/25/13) Quiz 1, Quiz 2, Quiz 3, Quiz 4, lab1 turned in and
graded Lab 2 assigned tonight (11/11/13)
Lab 2 Due next week 11/18/13 Take home final provided 11/25/13
Take home final due to me 12/16/13
Miles to go …
BINF 634 Fall 2013 - Lec 11 Visualization 3
Data Visualization Numbers are well and good, but often we get more insight by
visualizing data
As always, it's a good idea to break the process down into individual steps:data analysis script => output file => plotting script
=> chart file
This can all be wrapped for Web access:CGI script to get user input =>data analysis script => output file => plotting script
=> chart file=> CGI script displays chart on web page
Viz strategyBased in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 4
GD::Graph
Created by Martien Verbruggen
GD::Graph is a Perl module to create charts using the GD module. The following classes for graphs with axes are defined:
GD::Graph::lines -- Create a line chart
GD::Graph::bars and GD::Graph::hbars-- Create a bar chart with vertical or horizontal bars.
GD::Graph::points-- Create an chart, displaying the data as points.
GD::Graph::linespoints-- Combination of lines and points.
GD::Graph::area-- Create a graph, representing the data as areas under a line.
GD::Graph::pie-- Create a pie chart.
GDBased in Part on Previous Lecture of J. Grefenstette
#!/usr/bin/perluse strict;use GD::Graph::bars;# File: bargraph.pl (based on http://linuxgazette.net/issue83/padala.html)
# All data arrays should have the same number of entriesmy @x = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec");my @y = (23, 5, 2, 20, 11, 33, 7, 31, 77, 18, 65, 52);
# create a 2-dimensional array, where row 1 is x and row 2 is ymy @data = (\@x, \@y);
#create a new bar graph object and give it size (in pixels)my $graph = GD::Graph::bars->new(500, 300);
# set graph features such as labels on the axes, title$graph->set( x_label=>'Month', y_label=>'Number of Hits',
title=>'Number of Hits in Each Month in 2002')or warn $graph->error;
# plot the data to create an image objectmy $image = $graph->plot(\@data) or die $graph->error;
# print the image as a PNG file formatopen IMG, ">hist.png" or die "Can't open hist.png\n";print IMG $image->png;exit; 5BINF 634 Fall 2013 - Lec 11 Visualization
GDBased in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 6
Output
% open hist.png
GDBased in Part on Previous Lecture of J. Grefenstette
#!/usr/bin/perluse strict;use CGI qw(:standard);use GD::Graph::bars;# File: bargraph.cgi
# All data arrays should have the same number of entriesmy @x = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec");my @y = (23, 5, 2, 20, 11, 33, 7, 31, 77, 18, 65, 52);
# create a 2-dimensional array, where row 1 is x and row 2 is ymy @data = (\@x, \@y);
#create a new bar graph object and give it size (in pixels)my $graph = GD::Graph::bars->new(500, 300);
# set graph features such as labels on the axes, title$graph->set( x_label=>'Month', y_label=>'Number of Hits',
title=>'Number of Hits in Each Month in 2002')or warn $graph->error;
# plot the data to create an image objectmy $image = $graph->plot(\@data) or die $graph->error;
# print the image as a PNG file formatprint "Content-type: image/png\n\n";print $image->png;
7BINF 634 Fall 2013 - Lec 11 Visualization
Let’s create a web version !
GD
Based in Part on Previous Lecture of J. Grefenstette
8BINF 634 Fall 2013 - Lec 11 Visualization
GDBased in Part on Previous Lecture of J. Grefenstette
#!/usr/bin/perluse strict;use GD::Graph::bars;# File: bargraph2.pl
# read a file to get the data:my @x = (); my @y = (); open FH, "hist.dat" or die;while (<FH>) { my ($xval, $yval) = split; push @x, $xval; push @y, $yval }close FH;
# create a 2-dimensional array, where row 1 is x and row 2 is ymy @data = (\@x, \@y);
#create a new bar graph object and give it size (in pixels)my $graph = GD::Graph::bars->new(500, 300);
# set graph features such as labels on the axes, title$graph->set( x_label=>'Month', y_label=>'Number of Hits',
title=>'Number of Hits in Each Month in 2002')or warn $graph->error;
# plot the data to create an image objectmy $image = $graph->plot(\@data) or die $graph->error;
# print the image as a PNG file formatopen IMG, ">hist.png" or die "Can't open hist.png\n";print IMG $image->png; 9
BINF 634 Fall 2013 - Lec 11 Visualization
Plotting points from a file.
GD
Based in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 10
% cat hist.dat
Jan 23
Feb 5
Mar 2
Apr 20
May 11
Jun 33
Jul 7
Aug 31
Sep 77
Oct 18
Nov 65
Dec 52
GDBased in Part on Previous Lecture of J. Grefenstette
#!/usr/bin/perluse strict;use GD::Graph::linespoints;# File: plot.plmy @x = (); my @y = ();
# read a file to get the data:open FH, "hist.dat" or die;while (<FH>) { my ($xval, $yval) = split; push @x, $xval; push @y, $yval }close FH;
# create a 2-dimensional array, where row 1 is x and row 2 is ymy @data = (\@x, \@y);
#create a new bar graph object and give it size (in pixels)my $graph = GD::Graph::linespoints->new(500, 300);
# set graph features such as labels on the axes, title$graph->set( x_label=>'Month', y_label=>'Number of Hits',
title=>'Number of Hits in Each Month in 2002')or warn $graph->error;
# plot the data to create an image objectmy $image = $graph->plot(\@data) or die $graph->error;
# print the image as a PNG file formatopen IMG, ">out.png" or die "Can't open out.png\n";print IMG $image->png; 11BINF 634 Fall 2013 - Lec 11 Visualization
Creating a plot with lines and points.
GD
Based in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 12
GDBased in Part on Previous Lecture of J. Grefenstette
Getting the Chart on the Web This can all be wrapped for Web access:
CGI script to get user input (e.g., wrapper) =>data analysis script => output file => plotting script (e.g., plot.pl) => chart file (e.g.,
out.png) CGI script (wrapper) displays chart on web page
To display a file on the web, it has to be in a readable directory in the ~/public_html directory tree
1. Create a directory that can be written to by the web server process:
% mkdir ~/public_html/cgi-images% chmod 777 ~/public_html/cgi-images
13BINF 634 Fall 2013 - Lec 11 Visualization
GD
Based in Part on Previous Lecture of J. Grefenstette
Getting the Chart on the Web2. In the wrapper, create the graphics file in the working directory3. Copy it to the images directory4. Display it using print img{src=>...}
use CGI qw(:standard); ...
# change to working directorymkdir $dir or die "Can't create directory $dir\n";chdir $dir or die "Can't change to directory $dir\n";
# create the data file for plottingsystem "cp /userhomes/faculty/jsolka/binf634/visualization/hist.dat $dir";
# run the plotting programsystem "/userhomes/faculty/jsolka/binf634/visualization/linegraph.pl";
# copy the output image to the web images directorysystem "cp out.png
/userhomes/faculty/jsolka/public_html/cgi-images/out.png";
# display image file on the web pageprint img {src=>"/jsolka/cgi-images/out.png"};
14BINF 634 Fall 2013 - Lec 11 Visualization
GD
Based in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 15
Limitations to GD::Graph
GD::Graph is good for simple graphs but has some severe limits for scientific plotting
X-axis data assumed evenly spaced 2-dimensional Limited control over labels, arrows, etc.
GDBased in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 16
gnuplot
gnuplot is an open source Unix application for creating high quality plots from data
http://www.gnuplot.info/ Runs interactively and in batch mode Interactive mode:
% gnuplot> plot sin(x)
gnuplotBased in Part on Previous Lecture of J. Grefenstette
gnuplot Batch mode
put commands into a file, for example, histogram.plt run gnuplot with the command file as argument
% gnuplot histogram.plt
% cat histogram.plt# file histogram.pltset xlabel "Length"set ylabel "Sequences"set title "Sequence Length Distribution"plot "plot.dat" with boxesexit
17BINF 634 Fall 2013 - Lec 11 Visualization
gnuplot
Based in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 18
gnuplot accepts input files with an x,y pair on each line:
% cat plot.dat500 22550 14600 12650 13700 3750 7800 0850 7900 6950 31000 2
gnuplotBased in Part on Previous Lecture of J. Grefenstette
gnuplot gnuplot can create PNG format files, which work in all
common browsers
# file hist.plt# usage: gnuplot hist.plt
set output "hist.png" # name of output file
set terminal png medium mono # type of output file = PNG
set size 0.8, 0.8 # adjusts size of text
unset key # do not display key
set xlabel "Length" # x-axis label
set ylabel "Sequences" # y-axis label
set title "Sequence Length Distribution"
set style fill solid 1.0 # make boxes black
set boxwidth 0.9 relative # leave small space between boxes
plot "plot.dat" with boxes # plot the data file
exit
19BINF 634 Fall 2013 - Lec 11 Visualization
gnuplot
Based in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization
20
Output
gnuplotBased in Part on Previous Lecture of J. Grefenstette
## File: hist3.plt# usage: gnuplot hist3.plt## assumes data is stored in “myplot.dat"#set terminal png # type of output file = PNGset output "hist3date.png" # name of output fileset title "Hits Per Month" # title of graphset xlabel "Months" 0,-1 # x-axis label (down 1 character)set ylabel "Hits" # y-axis labelset size 0.75,0.75 # reduce graph sizeunset key # do not display keyset boxwidth 0.9 relative # leave small space between boxesset style fill solid 1.0 # make boxes solidset xrange [0:13] # control size of x-axis
# fine tune labels on x axisset xtics rotate ("Jan" 1, "Feb" 2, "Mar" 3, "Apr" 4, "May" 5,
"Jun" 6, "Jul" 7, "Aug" 8, "Sep" 9, "Oct" 10, "Nov" 11, "Dec" 12)
# plot the data file, creating "hist.png"plot “myplot.dat" with boxes
21BINF 634 Fall 2013 - Lec 11 Visualization
gnuplotBased in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 22
gnuplot data file
% cat myplot.dat1 232 53 24 205 116 337 78 319 7710 1811 6512 52
gnuplotBased in Part on Previous Lecture of J. Grefenstette
BINF 634 Fall 2013 - Lec 11 Visualization 23
hist.png
gnuplotBased in Part on Previous Lecture of J. Grefenstette
Getting the Chart on the Web2. In the wrapper, create the graphics file in the working directory3. Copy it to the images directory4. Display it using print img{src=>...}
use CGI qw(:standard);$ENV{PATH} = "/bin:/usr/bin:/usr/local/bin"; # for gnuplot ...
# change to working directorymkdir $dir or die "Can't create directory $dir\n";chdir $dir or die "Can't change to directory $dir\n";
# create the data file for plottingsystem "cp /userhomes/faculty/jsolka/binf634/visualization/plot.dat $dir";
# run the plotting programsystem "gnuplot /userhomes/faculty/jsolka/binf634/visualization/hist.plt";
# copy the output image to the web images directorysystem "cp hist.png /userhomes/faculty/jsolka/public_html/cgi-images/hist.png";
# display image file on the web pageprint img {src=>"/jsolka/cgi-images/hist.png"};
24BINF 634 Fall 2013 - Lec 11 Visualization
gnuplot
Based in Part on Previous Lecture of J. Grefenstette
Perl Data Language (PDL)
BINF 634 Fall 2013 - Lec 11 Visualization 25
http://pdl.perl.org/
PDL
A Few Discussions on PDL
The next several slides were adapted from the PDL tutorial by David Mertens at this URL
http://www.slideshare.net/dcmertens/p-lplot-talk
BINF 634 Fall 2013 - Lec 11 Visualization 26
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 27
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 28
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 29
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 30
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 31
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 32
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 33
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 34
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 35
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 36
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 37
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 38
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 39
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 40
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 41
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 42
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 43
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 44
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 45
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 46
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 47
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
BINF 634 Fall 2013 - Lec 11 Visualization 48
Adapted from David Mertens at this URLhttp://www.slideshare.net/dcmertens/p-lplot-talk
PDL
More information Online documentation for GD::Graph
% perldoc GD::Graph
Online doc for gnuplot% gnuplot> help
Also see: http://www.gnuplot.info PLplot
http://plplot.sourceforge.net/examples.php PDL
http://pdl.perl.org/
49BINF 634 Fall 2013 - Lec 11 Visualization
Summary
BINF 634 Fall 2013 - Lec 11 Visualization 50
Homework and Reminders
Program 4 due next week 11/26/12 Lab 2 due by next week No more quizzes No more programming assignments Only the final
Read Chapter 11 Exercise 11.1 and 11.2
Reminders