90 likes | 190 Views
Lecture 9: . Basic concepts of Perl Modules. Functions (Subs). In perl functions take the following format: sub subname { my $var1 = $_[0]; statements Return value } After all the subs are defined they are then called as required: my $variable = subname ($name);
E N D
Lecture 9: Basic concepts of Perl Modules
Functions (Subs) • In perl functions take the following format: • sub subname • { • my $var1 = $_[0]; • statements • Return value • } • After all the subs are defined they are then called as required: • my $variable = subname($name); • The SubroutineExample.pl
Perl Modules (.pm) • A perl module is a set of functions stored in a separate file (example.pm) which can be used by any perl script. (increase re-usability) • It is sometimes referred to as a library (like stdio.h) or package • There is two files assoicated with using modules. A .pm file and a .pl file
A Simple perl module • #!/usr/bin/perl • package Foo; • sub bar • { • print "Hello $_[0]\n" • } • sub blat • { • print "World $_[0]\n" • } • 1;
Utilising a perl Module • A perl module can be invoked (loaded) in a perl script by using • require and then :: function_name • use and qw( parameter list) • Loading with require: • #!/usr/bin/perl • requireFoo; # used to load the perl module • Foo::bar( "a" ); • Foo::blat( "b" );
Utilising a perl module • A perl module can also be loaded with use and by passing parameters via qw; e.g. • #!/usr/bin/perl • useFooUse; • bar( "a" ); # no need to use :: • blat( "b" ); • However must use qw to utilise the module • require Exporter; • @ISA = qw(Exporter); • @EXPORT = qw(bar blat);
Modified Perl module for “use” • package FooUse; • require Exporter; • @ISA = qw(Exporter); • @EXPORT = qw(bar blat); • sub bar { print "Hello $_[0]\n" } • sub blat { print "World $_[0]\n" } • sub splat { print "Not $_[0]\n" } # Not exported! • 1;
Exercise • Create and run the perl modules covered in class. • Modify the use perl script to see What happens if I call the splat function? • Re-write the “ByReference” subroutine in the pass by reference example (in the subroutine lecture) as a perl module and load it in a perl script. • Re-write your assignment perl scripts in the form of a perl module and a perl script driver.
Class Exercise: Finding start and stop codons and potential ORF • Download the file. (TUBAC3 gene complete sequence) (see last lecture) • Using “your” perl module and perl script determine the location of the start and stop codons. • Write a script that will “attempt” to find at least one ORF. Clearly state how, using your background knowledge of gene expression, you are going to try and resolve this problem. • Using your program: determine the position of an (the) ORF(s) for this gene. • Discuss How your findings compare with the results obtained in the genebank record file .