Você está na página 1de 4

Elements of Programming in Perl

<H16-1>

INTRODUCTION
Josep F. Abril
jabril@imim.es

MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 1/12

Algorithms
PROGRAM

INPUT

READ INPUT

ALGORITHM

ALGORITHM
IMPLEMENTATION

OUTPUT

MSc BioInformatics

WRITE OUTPUT

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 2/12

Algorithms in Biology
Homo sapiens leptin mRNA

INPUT

DNA
SEQUENCE

ALGORITHM

GENETIC
CODE

OUTPUT

PROTEIN
SEQUENCE

MSc BioInformatics

ATGCATTGGGGAACCCTGTGCGGATTCTTGTGGCTTTGGCCCTATCTT
TTCTATGTCCAAGCTGTGCCCATCCAAAAAGTCCAAGATGACACCAAA
ACCCTCATCAAGACAATTGTCACCAGGATCAATGACATTTCACACACG
CAGTCAGTCTCCTCCAAACAGAAAGTCACCGGTTTGGACTTCATTCCT
GGGCTCCACCCCATCCTGACCTTATCCAAGATGGACCAGACACTGGCA
GTCTACCAACAGATCCTCACCAGTATGCCTTCCAGAAACGTGATCCAA
ATATCCAACGACCTGGAGAACCTCCGGGATCTTCTTCACGTGCTGGCC
TTCTCTAAGAGCTGCCACTTGCCCTGGGCCAGTGGCCTGGAGACCTTG
GACAGCCTGGGGGGTGTCCTGGAAGCTTCAGGCTACTCCACAGAGGTG
GTGGCCCTGAGCAGGCTGCAGGGGTCTCTGCAGGACATGCTGTGGCAG
CTGGACCTCAGCCCTGGGTGCTGA

MHWGTLCGFLWLWPYLFYVQAVPIQKVQDDTKTLIKTIVT
RINDISHTQSVSSKQKVTGLDFIPGLHPILTLSKMDQTLA
VYQQILTSMPSRNVIQISNDLENLRDLLHVLAFSKSCHLP
WASGLETLDSLGGVLEASGYSTEVVALSRLQGSLQDMLWQ
LDLSPGC

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 3/12

The Software Development Cycle


SPECIFICATION

DESIGN

IMPLEMENTATION

TESTING

DEBUGGING

MAINTENANCE
MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 4/12

PERL
Perl is a high-level programming created by Larry Wall
and a cast of thousands, initially released in 1987.
It derives from the ubiquitous C programming language
and to a lesser extent from sed, awk, the Unix shell,
and at least a dozen other tools and languages.
The most recent production release is 5.8.2 (5.005_03
and 5.6.2 are still supported). The most cutting-edge
development release is 5.9.
Where to find help:
Your local Perl guru
MAN pages and PERLDOC
Perl Cookbook, Programming Perl, Elements of
Programming in Perl, etc...
http://cpan.org/
http://perl.com/

MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 5/12

Perl phylosophy
TMTOWTDI
There's More Than One Way To Do It

Laziness
The quality that makes you go to great effort
to reduce overall energy expenditure.

Impatience
The anger you feel when the computer is being lazy.

Hubris
The quality that makes you write (and maintain) programs
that other people wont want to say bad things about.
MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 6/12

Installing Perl
UNIX
Download latest version from CPAN.
Take a look to README/INSTALL files, and:
sh ./Configure; make; make test; make install;

WINDOWS
Obtain a perl port (for instance, ActiveState Perl version from
http://www.activestate.com/), and double-clik on the archive.

MAC
Compiled binary distribution for MacOS is available in the ports
section of CPAN.
MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 7/12

Writing Code
Structure
$s=0;$i=1;while($i<=
10){$s=$s+$i;$i=$i+
1;} print
"The result is $s\n";

Naming
$a = "ATGGGTA"

$s = 0;
$i = 1;
while ($i <= 10) {
$s = $s + $i;
$i = $i + 1;
};
print "The result is $s\n";
$dnaseq = "ATGGGTA"

Comments
# comments / POD comments / Literate Programming

Being strict
use strict;
use warnings;
MSc BioInformatics

Declare variables and


Initialize to default values

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 8/12

Our First Perl Script

Pure perl command-line:

sh$ perl e 'print "To bit or not to bit, that is the question...\n"'<RETURN>
To bit or not to bit, that is the question...
sh$

Perl command-line:
sh$ cat > myfirstscript.pl<RETURN>
print "To bit or not to bit, that is the question...\n"<RETURN>
<CTRL-D>
sh$ perl myfirstscript.pl<RETURN>
To bit or not to bit, that is the question...
sh$

Running a perl script:


sh$ which perl<RETURN>
/usr/bin/perl
sh$ cat > myfirstscript.pl<RETURN>
#!/usr/bin/perl
print "To bit or not to bit, that is the question...\n"<RETURN>
<CTRL-D>
sh$ chmod a+x myfirstscript.pl<RETURN>
sh$ ./myfirstscript.pl<RETURN>
To bit or not to bit, that is the question...
sh$
MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 9/12

Perl PRAGMAS
Pragmas are modules that change the behaviour of the interpreter.
use strict;
refs => generating run-time error if you use symbolic references
vars => compile-time error if variable was not previously declared
subs => barewords are treated as syntax errors
use warnings;
use constant PI => 3.14159;
use libs qw( /my/local/path/to/libs );
modifiying

@INC at compile time

use vars qw/ $dnaseq %codon_table @nucleotides /;


better => our($dnaseq,%codon_table,@nucleotides);
use subs qw/ read_seq reverse_complement /;
better => sub read_seq($); sub reverse_complement($);
MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 10/12

Suggested Bibliography
Elements of Programming with Perl
Andrew Johnson
Ed. Manning, 1st edition, 1999
Perl Cookbook
Tom Christiansen, Nathan Torkington
Ed. OReilly, 2nd edition, 2003
Learning Perl
Randal L. Schwartz, Tom Phoenix
Ed. OReilly, 3rd edition, 2001
Programming Perl
Larry Wall, Randal L. Schwartz, Tom Christiansen, Jon Orwant
Ed. OReilly, 3rd edition, 2003
Beginning Perl for Bioinformatics
James Tisdall
Ed. OReilly, 1st edition, 2001

Genomic Perl:
From Bioinformatics Basics to Working Code
Rex A. Dwyer
Cambridge University Press, 1st edition, 2002

MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 11/12

Materials for Perl Course


http://genome.imim.es/~jabril/teaching/MScBioinfo2004_H16/

MSc BioInformatics

Josep F. Abril Elements of Programming in Perl 2004/11/02

HG16.1 12/12

Você também pode gostar