Escolar Documentos
Profissional Documentos
Cultura Documentos
Timothy M. Kunau
Center for Biomedical Research Informatics
Academic Health Center
University of Minnesota
kunau@umn.edu
Bioinformatics Summer Institute 2007
Outline
Art and Programming
Getting Started
Biology and Computer Science
Bioinformatics Data
Perl basics:
Strings and Variables
Math and Logic
Looping, operators, and functions
Programming
Is an exercise in problem solving:
iterative
gradual
often a solitary activity
Social activity
You are now part of a community of tool builders.
A program does not often stand alone, but interacts with other programs
that make up its environment. Each building on the others.
Systematic and beautiful
Programming
Is an economically valuable skill.
Commercial and proprietary
systems are built to protect their
economic value.
Open Source projects are
different.
Open Source software projects
publish their source code so that
is can be shared and improved
by the community of users.
http://www.opensource.org/
Programming Strategies
Break down into two major approaches:
1.
2.
Programming Strategies
Open Source programming communities are often large
and prolific.
If you cannot find a program that does exactly what you
need -- you can likely find one that does most of what
you need.
A little tweaking is often significantly quicker than rolling
your own.
A day in the library can save you six months in the lab.
-- ancient adage
Programming Strategies
It is important to become aware of the communities
that use and support the tools you use.
Some copyrights may apply but use is generally
free.
CPAN
The Process
1. Identify the inputs, data, and specifications from the user.
2. Design the solution as a series of steps toward the desired
result.
3. Decide on the output(s). Does the result print to the screen
Pseudocode
An informal program in which
there are no details and formal
syntax is not followed.
What is Perl?
Scripting language by Larry Wall, cica 1985
Born of AWK
Practical Extraction and Reporting Language
Pathologically Eclectic Rubbish Lister
Disturbingly flexible in form, format, and usage.
Swiss Army chain-saw
Why Perl?!
An easy language to use, though sometimes hard to
learn. Some choices were made to make things easier
for the programmer at the expense of the student.
Fast cross platform text processing.
Good pattern matching. (regex)
Many extensions for Life Sciences data types. (BioPerl)
Many biologists already know Perl.
Powerful
#!/usr/local/bin/perl -w
use SOAP::Lite;
print STDERR "Welcome to the SOAP demonstration\n";
my $res;
$servername = "inquiry.ccgb.umn.edu";
my $server = SOAP::Lite
-> uri("http://$servername/Backbeat")
-> proxy("http://$servername/cgi-bin/bipod/BIFX.pl");
$res = $server->
(SOAP::Data->name(USER)->value("kunau"),
SOAP::Data->name(PASSWORD)->value(
my $ticket;
if ($res->result()) { $ticket = $res->result(); }
print STDERR "Got ticket $ticket\n";
));
Login
Get a ticket
my $id = "nt:ABY13260";
= $id;
=~ s/:
;
$res = $server->
(SOAP::Data->name(TICKET)->value($ticket),
SOAP::Data->name("BLOCKING")->value(1),
SOAP::Data->name("sequence")->value("$id"),
SOAP::Data->name(
)->value("fasta"),
SOAP::Data->name("outseq")->value(
));
($res);
print STDERR "fetched file for $id\n";
$res = $server->
(SOAP::Data->name(TICKET)->value($ticket),
SOAP::Data->name("BLOCKING")->value(0),
SOAP::Data->name("blastall")->value("blastn"),
SOAP::Data->name("query")->value(
),
SOAP::Data->name(
)->value("yeast.nt"),
SOAP::Data->name(
)->value("yeast.nt"),
SOAP::Data->name(
)->value(
. ".blastx"));
($res);
my $jid = 0;
if ($res->result()) { $jid = $res->result(); }
print "Submitted BLAST for
. Got job id $jid\n";
# Client side block
my $result = "";
while ($result ne "FINISHED") {
print "Checking status for job $jid\n";
$res = $server->
(
SOAP::Data->name("TICKET")->value($ticket),
$jid));
($res);
if ($res->result()) { $result = $res->result(); }
print "Got status $result\n";
if ($result ne "FINISHED") { sleep 3; }
}
Configure a service
Submit request
Check status (rinse, repeat)
$res = $server->
(SOAP::Data->name(TICKET)->value($ticket),
SOAP::Data->name(FILENAME)->value("blastall.txt"));
($res);
if ($res->result()) {
$result = $res->result();
print "Got status $result\n";
if ($result ne "FINISHED") { sleep 3; }
}
$res = $server->
(SOAP::Data->name(TICKET)->value($ticket),
SOAP::Data->name(FILENAME)->value("blastall.txt"));
($res);
if ($res->result()) { print $res->result(); }
###################### SUBROUTINES #####################
sub
{
my $res = shift;
if (my $fault = $res->fault()) {
my %fault = %$fault;
while (my ($key, $val) = each (%fault)) {
print "$key $val\n";
}
}
}
Print result
http://proquest.safaribooksonline.com/home
Safari: Perl
Safari: bioinformatics
Getting Started
The programming rite of passage.
Tidbits
print string;
newline: \n
tab: \t
# comments
All about context
A simple program
#!/usr/bin/perl -w
#
# a program to do the obvious
#
print Hello, world!\n;
A simple result
% ./hello-world.pl
Hello, world!
Comments
#
print Hello, world!\n;
#!/usr/bin/perl -w
#
# assign a value to $message
my $message = Hello, world!\n;
# print the $message
print $message;
Store the
value Hello,
world! in a
container
called a
variable.
#!/usr/bin/perl -w
#
# assign a value to $message
my $message = qq{Hello, world!\n};
# print the $message
print $message;
Dont let a
change in
form throw
you.
TMTOWTDI
Theres More Than One
Way To Do It
This can be frustrating
for new users.
Well try to focus on what
were doing. Dont worry
about all the possible
ways to do it yet.
% mkdir bsi2007
% cd bsi2007
% pico hello-world.pl
% chmod +x hello-world.pl
% ./hello-world.pl
#!/usr/bin/perl -w
#
# a program to do the obvious
#
print Hello, world!\n;
#!/usr/bin/perl -w
#
# assign a value to $message
my $message = Hello, world!\n;
# print the $message
print $message;
2.
3.
4.
#!/usr/bin/perl -w
#
# a program to do the obvious
#
print Hello, world!\n;
% ./hello-world.pl
Hello, world!
A brief history
1950s: Double helix structure of DNA
1960s: Manual alignment using edit distances
1970s: Optimal global alignment (Needleman & Wunsch)
Substitution matrixes (Dayhoff)
1980s: Optimal local alignment (Smith & Waterman)
1990s: Heuristic local alignment search
FASTA: (Pearson et al.),
BLAST: (Altschul et al.)
Disconnects
Social differences
Managing expectations
Developing a common
vocabulary
Conways Law
Social differences
Tool building versus the great discovery:
Computer scientists create new rules to engineer a solution.
(Inventing laws)
Life scientists look for the exception that breaks the rules.
(Discover laws)
Social differences
Biologists
Computer
Scientists
Sharing results
Reporting results
Talks at conferences
Publish Source Code
Whos who
(on publications)
Managing Expectations
What can we expect
from each other?
Life Sciences are
presenting the grand
challenges of our
time...
What does Computer
Science have to offer
Life Sciences
research?
Isnt it odd?
Conways Law"
Bioinformatics Data
Quantity has a quality
all its own
Russian military axiom
Bioinformatics Data
Often unstructured or semi-structured.
Data appears as text strings:
Protein sequences: FASTA flat-files,
et alia.
Annotation: often free-text
Feudal states (Lincoln Stein)
FASTA
>ContigId:Contig1 AssemblyProcessId:MtSC AssemblyProcessVersion:6
GCTTTAATCTTGTAGGTTTGATGAAAGAATAAGTTCGTTTGCTGAGAAGA
AGTTTACAAGAGATGGTATAGAAGTTCAAACTGGATGCCGCGTTATGAGT
GTTGATGACAAGGAAATTACAGTGAAGGTGAAATCAACGGGAGAGGTTTG
CTCGGTTCCCCATGGATTGATTATCTGGTCTACTGGCATTTCTACTCTTC
CAGTTATAAGAGATTTTATGGAAGAAATTGGTCAGACTAAAAGGCATGTA
CTGGCAACCGATGAATGGTTGAGAGTGAAGGAATGTGAAGATGTGTTTGC
CATTGGTGATTGTTCATCAATAAATCAACGTAAAATCATGGATGATATCT
TGGACATATTTAAGGCTGCAGACAAAAATAACTCCGGTACCTTAACTGTG
TAAGAATGCGAAGAAGTGATGGATGAATGTATCTTAAGATATCCTGCAGT
GGAATGC
LOCUS
DEFINITION
GenBank
SCU49845
5028 bp
DNA
PLN
21-JUN-1999
Saccharomyces cerevisiae TCP1-beta gene, partial cds, and Axl2p
(AXL2) and Rev7p (REV7) genes, complete cds.
ACCESSION
U49845
VERSION
U49845.1 GI:1293613
KEYWORDS
.
SOURCE
Saccharomyces cerevisiae (baker's yeast)
ORGANISM Saccharomyces cerevisiae
Eukaryota; Fungi; Ascomycota; Saccharomycotina; Saccharomycetes;
Saccharomycetales; Saccharomycetaceae; Saccharomyces.
REFERENCE
1 (bases 1 to 5028)
AUTHORS
Torpey,L.E., Gibbs,P.E., Nelson,J. and Lawrence,C.W.
TITLE
Cloning and sequence of REV7, a gene whose function is required for
DNA damage-induced mutagenesis in Saccharomyces cerevisiae
JOURNAL
Yeast 10 (11), 1503-1509 (1994)
PUBMED
7871890
REFERENCE
2 (bases 1 to 5028)
AUTHORS
Roemer,T., Madden,K., Chang,J. and Snyder,M.
TITLE
Selection of axial growth sites in yeast requires Axl2p, a novel
plasma membrane glycoprotein
JOURNAL
Genes Dev. 10 (7), 777-793 (1996)
PUBMED
8846915
REFERENCE
3 (bases 1 to 5028)
AUTHORS
Roemer,T.
TITLE
Direct Submission
JOURNAL
Submitted (22-FEB-1996) Terry Roemer, Biology, Yale University, New
Haven, CT, USA
FEATURES
Location/Qualifiers
source
1..5028
/organism="Saccharomyces cerevisiae"
/db_xref="taxon:4932"
/chromosome="IX"
/map="9"
CDS
<1..206
/codon_start=3
/product="TCP1-beta"
/protein_id="AAA98665.1"
/db_xref="GI:1293614"
/translation="SSIYNGISTSGLDLNNGTIADMRQLGIVESYKLKRAVVSSASEA
AEVLLRVDNIIRARPRTANRQHM"
gene
687..3158
/gene="AXL2"
CDS
687..3158
/gene="AXL2"
GenBank
gene
CDS
ORIGIN
1
61
121
181
241
301
361
421
gatcctccat
ccgacatgag
ctgcatctga
gaaccgccaa
ccacactgtc
agacgcgaaa
attttggcaa
aatacccatc
atacaacggt
acagttaggt
agccgctgaa
tagacaacat
attattataa
aaaaaagaac
cttatgtttc
gtaggtatgg
atctccacct
atcgtcgaga
gttctactaa
atgtaacata
ttagaaacag
aacgcgtcat
ctcttcgagc
ttaaagatag
caggtttaga
gttacaagct
gggtggataa
tttaggatat
aacgcaaaaa
agaacttttg
agtactcgag
catctccaca
tctcaacaac
aaaacgagca
catcatccgt
acctcgaaaa
ttatccacta
gcaattcgcg
ccctgtctca
acctcaaagc
ggaaccattg
gtagtcagct
gcaagaccaa
taataaaccg
tataattcaa
tcacaaataa
agaatgtaat
tccttgccga
GenBank
481
541
601
661
721
781
841
901
961
1021
1081
1141
1201
1261
1321
1381
1441
1501
1561
1621
1681
1741
1801
1861
1921
1981
2041
2101
2161
2221
2281
2341
2401
2461
2521
2581
2641
2701
2761
2821
2881
2941
3001
3061
gagtcgccct
tttactctca
acaattactt
cgtatatcaa
ctactatatc
aacaataccc
cctataaatc
gctggctttc
tatctgatgc
acagcacgtc
tatcgtcaga
acgctctgaa
ctaacgaaga
ccaattggct
actcggcgat
gattttctgc
ctattcaaaa
ctctaaacta
acttattgga
cagatgaatt
cttatggtga
ttagttctct
cttctcagtt
aagaccatga
agaatttcga
tatattttaa
caacgtccac
acactgcaaa
cagcagccaa
ctatcccatt
gaagggaaaa
atcctgcaaa
atgcttcctc
aattggataa
ctctatcagg
tagcaaaacc
cttctgtgta
tgtcaccagt
aaaaactttt
tgtcttcact
caccatcacc
ctcaaagcgg
ttgttccggt
gaccaagtaa
cctttgtcga
catcctgtag
aatagaaaaa
gaagcattca
actactccat
cccagtggca
gtctgtagac
gtttgactct
gaacaccacg
tttgaacaat
tttcaatcta
actagatcct
atccattgtg
gttcttcgat
tgctccagaa
cgttgaggta
tagtttgata
tgtttatctc
tgctccagac
actcggtaag
tgtgatttat
tcccaatatt
tacagactac
ctgggtgaaa
caagctttca
catcattggc
aagaagttct
aatttcttct
taaaacttca
aggcgttatc
tccagacgat
taaaccaaat
gtacgatgat
ccactctgcc
tatgaataca
cccagtacag
tatggatagt
ctctgatatt
cgatttagaa
ggacccttgg
atataacgta
taaaaacgga
taaagatggt
gaaaaggtta
gtaattttca
tgattgacac
ttatatcttc
cttaccatga
ctagtagtgg
agagtcaatg
aagacagctc
agttctagaa
ttgtatttca
acataccaat
ttggcgttgt
aatgaagtct
tcgtattacg
tctggcgagt
acaagctaca
gaattcgaat
atcaacgtta
gatgacgatc
tgggtggcat
aactccaatc
ttcaacttcg
aacgctacaa
gtgaatacaa
ttccaatcat
ttaggtttga
atggattcaa
caccactcca
acctccgctg
tctcacaata
ctagtagctc
gaaaacttac
caagaaaacg
acttcaatag
actgaatctg
tacaatgatc
cctccagaga
gaaccagcag
gtcagagaca
gcaccagaga
aacagcaata
acgaagcatc
atcactccca
gaaaattttt
gtagattttt
cttttcatat
tgcaacagcc
ctcgaaacga
cacagcttca
ccacgcccta
aatcgtttac
aaataacata
cgttctcagg
atgtaatact
ttgttgttac
taaaaaacta
tcaacgtgac
gacgttctca
tgaagtttac
gttttgtcat
tagtcatcgg
ctgacacagg
ctatttcttc
tagataatgc
ctgccaattt
aagttgtctc
ggggtgaatg
acgtttcatt
ctaatttaac
aagcgaacca
agataactca
cctcaacaag
ctgctacttc
aaaaagcagt
tcatttgctt
cgcatgctat
ctacaccttt
caagaagatt
atatttccag
agttccaatc
gcccgttctt
taaataaatc
gttacggatc
aggaaaaacg
ttagcccttc
gtaaccgcca
caacaatgtc
gctgggtcca
caaataagag
gagaacttat
accatcacta
tttcctgctt
gatttcatta
tgaggcatat
atttcaaatt
caattgcttc
tgaaccttct
cgagggtacg
aaaccgtcca
tggttatact
ttttgaccgt
gttgtataat
tgggacggca
catcgctaca
ggctcaccag
taacgtttca
tgataaattg
taccatttcc
ttctgtgtcc
cacaacggat
gttctcctac
agagtttact
attagctgga
aggttcacaa
ctcaaaccac
ttcttacaca
ttctgctcca
agcaattgcg
cctaatattc
tagtggacct
gaacaacccc
ggctgctttg
cgtggatgaa
ccaaagtaaa
tgacccacag
ctggcgatat
acaaaaaact
tacgtcaagg
tcccgtaaga
cttacaaaat
aacttcatct
tagcatggaa
taatgtcaat
tttcttattc
gaagaacaga
ccaacatcta
ttgctgacag
cctatcggaa
tccaatgata
gacttaccga
tctgacttac
gactctgccg
tccatctcgc
aacggcaaaa
tcaatgttca
gcgccgttac
ccggtgataa
gacattgaag
ttaactacct
tatgacttac
ggttctataa
gggtctgtcc
atttatgata
ttgtttgcca
tattttttgc
aattcaagcc
gaagtgccca
tctcaagagc
agtgcgaatg
tcttctactt
gcagcgctgc
tgcggtgttg
tggagacgca
gatttgaata
tttgatgatg
aacactttga
aagagagatt
gaagaattat
aataggtctt
actggcaacc
gttgatacag
gatgtcacta
aaatcagtaa
attcaagact
tctgacgatt
ccagacagaa
gttggtcaag
3121
3181
3241
3301
3361
3421
3481
3541
3601
3661
3721
3781
3841
3901
3961
4021
4081
4141
4201
4261
4321
4381
4441
4501
4561
4621
4681
4741
4801
4861
4921
4981
GenBank
//
ttaaggacat
taattttatt
agtttttata
taaaacaaag
attttgtcgt
tcagaaccga
aaattttcat
tccaaactat
ttaataactg
ataatcaaac
tgatcgtctt
aaatcgttct
agaacatcca
acgaactgcg
acatttctat
tctacccatc
tcagtcgtcg
gtttatatta
atattaagaa
ctgtttatgt
tttggtaaag
cttagttcat
ccatctgtca
agcgcgtttg
tccaatgaat
tcttcgcact
atttgctcag
tcactgtctt
gatctcaagt
ttctccactt
ttttcagtgt
tgccatgact
tcacggacgc
ttcctgtttt
cttagagaca
atccaaaaat
caccgctgat
ctaaagaagt
cttcttgaca
cgaccctcct
cttcaaatgt
tatttaagga
tatccacatg
ttttattaat
gtataagttc
gcaagttgaa
aaaataaaat
tattcataaa
caaaaacgta
gttaaacagg
agtggaaatt
ttctacgtac
gtgaaagcat
cttttttcca
gcaacatcag
tcgtttgtat
tagcaatttc
tcttttccca
agttcaaatc
ctagctgttg
tattggagtc
cactgtcgag
tagattgctc
cagattctaa
atcccagaaa
attttttatt
tttaatttta
gctctcgccc
taatttttca
gagttttatt
tttaacccag
gtttctgtcc
tattgtgtca
agatcggaat
ttgtaattca
aatgcagatg
ttctatatag
tgactggtaa
caaattaatg
gctgacgcaa
taccttcttt
gtctagtctt
aaattagtag
ttttgattta
aatgtaaaag
aaaagcaccc
ttgtgtgagc
cttccgtaat
gtccaattct
ttcatctctt
ggcctctttc
ttctagatcc
ttcagccaat
ttgctcgttt
taattctttg
ttttaagcta
tgctgtgatt
agtggtttac
attccattct
tcttcatatt
ctaaactgat
ttaggaggtt
tttgaatccc
aacttatgtc
tcgttgactt
tcgtcgaaca
ctaaaatcta
gaaaatctgt
tcaattaaag
gtagtgtagt
tagcatttta
cgattactat
ttccgacctt
agtgtgaaag
tgtagacgta
tagcaagggg
ctagaataaa
aatgataata
aataataaaa
tttagtctta
ttttgagctt
tcttcttcca
agtttatcca
tggtttttct
tgctttgtat
ttagcggaca
agctgttctc
ttcaatttct
atacgcaacg
agatacccta
tcaaatttca
gagaatacac
gaataatcaa
gaaaaccatt
tttcaatttc
ctagttccaa
taggtaattt
cttcagtttc
aaacgtattt
aaacgtgcgt
caggatgcct
cgaatgactg
agtataccct
tttttttttc
ttttttagct
ctagtggttt
tatgcatatg
aaaagaaata
atggacgaaa
actaaaatga
tcatcacctc
tcaatgggaa
cttcatattt
aagcaacgat
ttgcttcctt
tggtgtagtt
cagacaattg
aagatttaat
tcagctcctc
ctttgatc
atattttgct
tattttattt
tttttgcact
tccattcaaa
aggccccacg
attgtctggt
tgctttttcc
ttcgatcgca
ctccaaatgc
cgtaatgatc
ttcaatgcat
taatttagaa
attaatggga
aggtgggtat
cagccacttc
ttcttggatc
ttctggaaaa
cgattgactg
tatttctcgc
catactattt
taaagagagg
aaaggatttg
cgttgccttt
tcataaattt
gctttggaat
ccttctaccc
cagtttggct
ctcattatta
actctctaac
ctcgttttct
atatttttct
SWISS-Prot
Release 53.0 of 29-May-07 of
UniProtKB/Swiss-Prot contains
269,293 sequence entries,
comprising 98,902,758 amino acids
abstracted from 156,204
references.
ID
AC
DT
DT
DT
DE
GN
OS
OC
OC
OC
OC
OX
RN
RP
RC
RX
RA
RA
RA
RT
RT
RL
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
DR
KW
KW
FT
FT
FT
FT
FT
FT
FT
FT
FT
DMI1_MEDTR
STANDARD;
PRT;
882 AA.
Q6RHR6;
29-MAR-2005, integrated into UniProtKB/Swiss-Prot.
05-JUL-2004, sequence version 1.
04-APR-2006, entry version 13.
Putative ion channel DMI-1 (Does not make infections protein 1).
Name=DMI1;
Medicago truncatula (Barrel medic).
Eukaryota; Viridiplantae; Streptophyta; Embryophyta; Tracheophyta;
Spermatophyta; Magnoliophyta; eudicotyledons; core eudicotyledons;
rosids; eurosids I; Fabales; Fabaceae; Papilionoideae; Trifolieae;
Medicago.
NCBI_TaxID=3880;
[1]
NUCLEOTIDE SEQUENCE [MRNA], INDUCTION, AND TISSUE SPECIFICITY.
TISSUE=Root;
PubMed=14963334; DOI=10.1126/science.1092986;
Ane J.-M., Kiss G.B., Riely B.K., Penmetsa R.V., Oldroyd G.E.,
Ayax C., Levy J., Debelle F., Baek J.-M., Kalo P., Rosenberg C.,
Roe B.A., Long S.R., Denarie J., Cook D.R.;
"Medicago truncatula DMI1 required for bacterial and fungal symbioses
in legumes.";
Science 303:1364-1367(2004).
-!- FUNCTION: Required for early signal transduction events leading to
endosymbioses. Acts early in a signal transduction chain leading
from the perception of Nod factor to the activation of calcium
spiking. Also involved in mycorrhizal symbiosis.
-!- SUBCELLULAR LOCATION: Plastid; chloroplast; chloroplast membrane;
multi-pass membrane protein (Potential).
-!- TISSUE SPECIFICITY: Mainly expressed in roots. Also detected in
pods, flowers, leaves, and stems.
-!- INDUCTION: Not induced after bacterial or Nod factor treatment.
-!- SIMILARITY: Belongs to the castor/pollux family.
----------------------------------------------------------------------Copyrighted by the UniProt Consortium, see http://www.uniprot.org/terms
Distributed under the Creative Commons Attribution-NoDerivs License
----------------------------------------------------------------------EMBL; AY497771; AAS49490.1; -; mRNA.
Chloroplast; Coiled coil; Ion transport; Ionic channel; Membrane;
Plastid; Transmembrane; Transport.
CHAIN
1
882
Putative ion channel DMI-1.
/FTId=PRO_0000165855.
TRANSMEM
129
149
Potential.
TRANSMEM
192
212
Potential.
TRANSMEM
255
275
Potential.
TRANSMEM
307
327
Potential.
COILED
378
403
Potential.
COMPBIAS
78
96
Pro-rich.
COMPBIAS
114
117
Poly-Ser.
XML
TGACATGCTAGCTAGCTAGCTAT
1356
#@$!$!%@&&!@
Data types
Scalar: a variable quantity
that cannot be resolved
into components.
List: a collection of items,
often stored in an array.
Hash: a dish of cooked
meat cut into small pieces
and re-cooked, usually
with potatoes.
Data types
Scalar: a variable quantity
that cannot be resolved
into components.
List: a collection of items,
often stored in an array.
Hash: like an array, but
instead of indexing values
by number, values are
accessed by name. Think
of them as name-value
pairs.
Data types
Scalar: my $var = a;
my $num = 10;
List: my @fruit_list = (apple,orange,banana);
Hash:
my %ip2hostname = (
160.94.109.65
=> leaf.cbri.umn.edu,
160.94.109.55
=> blastoma.cbri.umn.edu,
Math
Standard arithmetic: +, -, *, /
modulus operator: %
4 % 2 = 0 and 5 % 2 = 1
Operate in place: $num += 3;
Increment and decrement variable: $i++, $a- power: 2**5
Square-root: sqrt(9)
le, gt, ge
Testing equality
my $str1 = mumbo;
my $str2 = jumbo;
if( $str1 eq $str2 ) {
print strings are equal\n;
}
if( $str1 lt $str2 ) {
print less; }
} else {
print more\n;
}
Testing equality
my $str1 = mumbo;
my $str2 = jumbo;
if( $str1 eq $str2 ) {
print strings are equal\n;
}
if( $str1 lt $str2 ) {
print less; }
} else {
print more\n;
}
Testing equality
my $num1 = 10;
my $num2 = 100;
if( $num1 == $num2 ) {
print nums are equal\n;
}
if( $num1 < $num2 ) {
print less; }
} else {
print more\n;
}
Boolean Logic
AND: && and
OR: || or
NOT: !
not
Loops
while( TEST ) { }
until( ! TEST ) { }
for( $i = 0 ; $i < 10; $i++ ) {}
foreach $item ( @list ) { }
for $item ( @list ) { }
Using logic
for( $i = 0;
if( $i == 0
print $i
} elsif( $i
print $i
} else {
print $i
}
}
for( $i = 0;
if( $i == 0
print $i
} elsif( $i
print $i
} else {
print $i
}
}
for( $i = 0;
if( $i == 0
print $i
} elsif( $i
print $i
} else {
print $i
}
}
for( $i = 0;
if( $i == 0
print $i
} elsif( $i
print $i
} else {
print $i
}
}
What is truth?
True
if( zero ) {}
if( 23 || -1 || ! 0) {}
$x = 0 or none; if( $x )
False
if( 0 || undef || || 0 ) { }
Special variables
This is why many
people dislike Perl.
Too many little silly
things to remember.
One of the trade-offs
that make it harder to
learn and ultimately
easier to use.
perldoc perlvar
for more detailed
information.
LAB: Math
% pico pi.pl
#!/usr/bin/perl -w
#
# assign values
my $num1 = 22;
my $num2 = 7;
my $result = $num1 / $num2;
# print the result
print $result;
% chmod +x pi.pl
% ./pi.pl
LAB: Math
% pico pi.pl
#!/usr/bin/perl -w
#
# assign values
my $num1 = 22;
my $num2 = 7;
% chmod +x pi.pl
% ./pi.pl
LAB: Math
% pico pi.pl
#!/usr/bin/perl -w
#
# assign values
my $num1 = 22;
my $num2 = 7;
my $result = $num1 % $num2;
# print the result
print $result;
% chmod +x pi.pl
% ./pi.pl
2.You
3.You
4.Add
% pico loops-and-logic.pl
% chmod +x loops-and-logic.pl
% ./loops-and-logic.pl
#!/usr/bin/perl -w
for( $i = 0;
if( $i == 0
print $i
} elsif( $i
print $i
} else {
print $i
}
}
% pico foreach.pl
% chmod +x foreach.pl
% ./foreach.pl
#!/usr/bin/perl -w
% pico foreach.pl
% chmod +x foreach.pl
% ./foreach.pl
#!/usr/bin/perl -w
2.
3.
% pico transcribe.pl
% chmod +x transcribe.pl
% ./transcribe.pl
#!/usr/bin/perl -w
# Transcribing DNA into RNA
# The DNA
my $DNA = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';
# Print the DNA onto the screen
print "Here is the starting DNA:\n\n";
print "$DNA\n\n";
# Transcribe the DNA to RNA by substituting all T's with U's.
my $RNA = $DNA;
$RNA =~ s/T/U/g;
# Print the RNA onto the screen
print "Here is the result of transcribing the DNA to RNA:\n\n";
print "$RNA\n";
% pico transcribe.pl
% chmod +x transcribe.pl
% ./transcribe.pl
#!/usr/bin/perl -w
# Transcribing DNA into RNA
# The DNA
my $DNA = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';
# Print the DNA onto the screen
print "Here is the starting DNA:\n\n";
print "$DNA\n\n";
# Transcribe the DNA to RNA by substituting all T's with U's.
my $RNA = $DNA;
$RNA =~ s/T/U/g;
# Print the RNA onto the screen
print "Here is the result of transcribing the DNA to RNA:\n\n";
print "$RNA\n";
2.
3.You
Questions?
Thank You.