Introduction to Bioinformatic Computation. Lecture 6 02-22-2010 Objectives for today Packages, Modules, Objects /home/afedorov/IBC1_PROGRAMS/LECTURE13
prog_log #!/usr/bin/perl/ use POSIX qw(log10); $r = 10000; $log = log10($r); print $log, "\n";
export PERL5LIB=/home/foobar/code echo PERL5LIB perl INC export PERL5LIB=/home/foobar/code echo PERL5LIB perl INC.pl http://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations
#!/usr/local/bin/perl #color.pl program #http://perl.active-venture.com/lib/Term/ANSIColor.html use Term::ANSIColor; print color 'bold blue'; print "This text is bold blue.\n"; print color 'reset'; print "This text is normal.\n"; print colored ("Yellow on magenta.\n", 'yellow on_magenta'); print colored ['yellow on_magenta'], "Yellow on magenta.\n"; use Term::ANSIColor qw(uncolor); print uncolor '01;31', "\n"; use Term::ANSIColor qw(:constants); print BOLD, BLUE, "This text is in bold blue.\n", RESET; $Term::ANSIColor::AUTORESET = 1; print BOLD BLUE "This text is in bold blue.\n";
prog_INC #!/usr/local/perl $i=0; foreach $x (@INC) {printf "%d %s\n", $i++, $x}
Our previous approach: invocation of a perl program by another perl script (EID, lecture 9) makeEID.pl first_parse.pl check_translations.pl finalmakeCHECK.pl
more makeEID.pl #!/usr/bin/perl -w # Serge Saxonov, Iraj Daizadeh, Alexei Fedorov, Walter Gilbert ($#ARGV != -1) || die "Usage: $0 prefix\n"; $prefix = $ARGV[0]; unless(-e "seqfiles.list"){ die "Need to have seqfiles.list in the current directory\n"; } system("perl first_parse.pl $prefix"); system("cat $prefix.RAW |perl check_translations.pl $prefix"); system("rm -f $prefix.RAW"); system("finalmakeCHECK.pl $prefix"); system("rm -f $prefix.RAWchecked");
New approach: invocation of a perl program from a module (file with New approach: invocation of a perl program from a module (file with .pm on the end) In your perl script write: use Module_name; (let’s, for example, look at our bioperl programs)
Examples of Bioperl COMPUTER: mco321125.mco.edu DIR: /home/afedorov/IBC1_PROGRAMS/LECTURE13 bioperl_test.pl (bring the information about my sequence from the web) bioperl_blast.pl (open NCBI blast web site and perform blast of my sequence)
more bioperl_blast.pl #!/usr/local/perl use Bio::Perl; $seq = get_sequence('swiss',"ROA1_HUMAN"); # uses the default database - nr in this case $blast_result = blast_sequence($seq); write_blast(">roa1.blast",$blast_result);
Modification of bioperl_blast.pl for obtaining another alignment vi bioperl_blast.pl Change line 4 (input: MALK_ECOLI) Change line 7 (output file)
find / -name Perl.pm –print >where_is_Perl.pm /usr/lib/perl5/site_perl/5.8.0/Bio/Perl.pm
more /usr/lib/perl5/site_perl/5.8.0/Bio/Perl.pm Other modules inside Perl.pm use vars qw(@ISA @EXPORT @EXPORT_OK $DBOKAY); use strict; use Carp; use Exporter; use Bio::SeqIO; use Bio::Seq;
Bioperl http://www.bioperl.org/ BioPerl 1.4 Tutorial Pasteur Institute Bioperl Course BioPerl 1.4 Module Documentation
Additional information on www.bioperl.org Getting Started Just learning about perl and computational biology? Read Lincoln Stein's classic article, "How Perl Saved the Human Genome Project" Join a Bioperl mailing list Visit perl.com Find a local users group The International Society for Computational Biology (iscb.org)
Is it possible to accomplish our project using available modules? NO However, you, probably, could perform some very helpful steps using Bioperl and other modules.
http://www.perl.com/CPAN/ CPAN is the Comprehensive Perl Archive Network, a large collection of Perl software and documentation. 6200 modules available CPAN Frequently Asked Questions
Definition of Package Cookbook pp395-400 Package is a compile-time declaration that sets the default package prefix for unqualified global identifiers Any variable not declared with my is associated with a package $current_package = __PACKAGE__;
PACKAGE [afedorov@intron BIOPERL]$ more test_package.pl #!/usr/local/perl package Alpha; $name = 'first'; package Omega; $name = 'last'; package main; print " Alpha is $Alpha::name Omega is $Omega::name \n";
Definition of module Traditional modules (define subroutines and variables for the caller to import and use) Object-oriented modules (outside the scope of this course)
MODULE example more MYTEST.pm package MYTEST; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; $VERSION = 1.00; @ISA = qw(Exporter); ################################### #PUT WHATEVER YOU WANT HERE our $test = 5; our $seq1 = 'atg'; our $seq2 = 'fdndidfdndfkf'; our @array = ('a', 't', 'g', 'c'); 1;
more test2.pl #!/usr/local/perl use MYTEST; print "value is $MYTEST::seq1 \n array is @MYTEST::array \n";
Export variables and functions more TestExport.pm package TestExport; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw($seq1 @array); ################################### #PUT WHATEVER YOU WANT HERE our $test = 5; our $seq1 = 'atg'; our $seq2 = 'fdndidfdndfkf'; our @array = ('a', 't', 'g', 'c'); 1;
Export variables and functions from a module more test3.pl #!/usr/local/perl use TestExport; print "seq1 is $seq1 \n seq2 is $seq2 \n array is @array \n";
Export variables and functions from a module by a request Inside a module create a line @EXPORT_OK =qw(&alexei %fedorov); Load the module with the request for your variables use YourModule qw(alexei %fedorov);
%EXPORT_TAGS %EXPORT_TAGS = ( Variables1 => [qw($seq1 Seq2 alexei)], Var2 => [qw(@array, $seq2 %fedorov], ); use YourModule qw(:Variables1 @array);
How to prepare a module in a standard distribution format COMMAND LINE: h2xs –XA –n OurFirstModule perl Makefile.PL make dist (to create name.tar.gz file)
RepeatMasker program (lecture 11) use Getopt::Long; use POSIX qw(:sys_wait_h); use File::Copy; use File::Basename; use Cwd;
How to install a module (example Bioperl in INTRON) Get step by step instructions from web sites (CPAN, bioperl, etc) Example: read INSTALL file (in bioperl ->download ->docs) >gunzip bioperl-1.2.tar.gz >tar xvf bioperl-1.2.tar >cd bioperl-1.2
What’s inside @INC array? (INTRON ~/BIOPERL) [afedorov@intron BIOPERL]$ perl prog_INC 0 /usr/lib/perl5/5.8.0/i386-linux-thread-multi 1 /usr/lib/perl5/5.8.0 2 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi 3 /usr/lib/perl5/site_perl/5.8.0 4 /usr/lib/perl5/site_perl 5 /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi 6 /usr/lib/perl5/vendor_perl/5.8.0 7 /usr/lib/perl5/vendor_perl 8 .
BIOPERL INSTALL FILE THE EASY WAY The Bioperl modules are distributed as a tar file in standard perl CPAN distribution form. This means that installation is very simple. Once you have unpacked the tar distribution there is a directory called bioperl-xx/, which is where this file is. Move into that directory (you may well be already in the right place!) and issue the following commands: perl Makefile.PL # makes a system-specific makefile make # makes the distribution make test # runs the test code make install # [may need root access for system install. # See below for how to get around this.]
tar xvf current_core_stable.tar cd bioperl-1.4 su – make install
BIOPERL TUTORIAL perl bptutorial.pl 1 perl bptutorial.pl 9 perl bptutorial.pl 100 swiss perl bptutorial.pl 100 Bio::Tools::SeqStats