SlideShare a Scribd company logo
1 of 30
FBW
5-11-2013

Wim Van Criekinge
Programming

• Variables
• Flow control (if, regex …)
• Loops
• input/output
• Subroutines/object
Three Basic Data Types

• Scalars - $
• Arrays of scalars - @
• Associative arrays of
scalers or Hashes - %
• [m]/PATTERN/[g][i][o]
• s/PATTERN/PATTERN/[g][i][e][o]
• tr/PATTERNLIST/PATTERNLIST/[c][d][s]
The „structure‟ of a Hash

• An array looks something like this:
0

@array =

1

2

'val1' 'val2' 'val3'

Index
Value

• A hash looks something like this:
Rob

Matt

Joe_A

%phone =
353-7236 353-7122 555-1212

Key (name)

Value
Printing a hash (continued)

• First, create a list of keys. Fortunately, there is
a function for that:
– keys %hash (returns a list of keys)

• Next, visit each key and print its associated
value:
foreach (keys %hash){
print “The key $_ has the value $hash{$_}n”;
}

• One complication. Hashes do not maintain any
sort of order. In other words, if you put
key/value pairs into a hash in a particular
order, you will not get them out in that order!!
my %AA1 = (
'UUU','F',
'UUC','F',
'UUA','L',
'UUG','L',
'UCU','S',
'UCC','S',
'UCA','S',
'UCG','S',
'UAU','Y',
'UAC','Y',
'UAA','*',
'UAG','*',
'UGU','C',
'UGC','C',
'UGA','*',
'UGG','W',

'CUU','L',
'CUC','L',
'CUA','L',
'CUG','L',
'CCU','P',
'CCC','P',
'CCA','P',
'CCG','P',
'CAU','H',
'CAC','H',
'CAA','Q',
'CAG','Q',
'CGU','R',
'CGC','R',
'CGA','R',
'CGG','R',

'AUU','I',
'AUC','I',
'AUA','I',
'AUG','M',
'ACU','T',
'ACC','T',
'ACA','T',
'ACG','T',
'AAU','N',
'AAC','N',
'AAA','K',
'AAG','K',
'AGU','S',
'AGC','S',
'AGA','R',
'AGG','R',

'GUU','V',
'GUC','V',
'GUA','V',
'GUG','V',
'GCU','A',
'GCC','A',
'GCA','A',
'GCG','A',
'GAU','D',
'GAC','D',
'GAA','E',
'GAG','E',
'GGU','G',
'GGC','G',
'GGA','G',
'GGG','G' );
Programming in general and Perl in particular
• There is more than one right way to do it. Unfortunately, there are also
many wrong ways.
– 1. Always check and make sure the output is correct and logical
• Consider what errors might occur, and take steps to ensure that you are
accounting for them.

– 2. Check to make sure you are using every variable you declare.
• Use Strict !

– 3. Always go back to a script once it is working and see if you can
eliminate unnecessary steps.
• Concise code is good code.
• You will learn more if you optimize your code.
• Concise does not mean comment free. Please use as many comments as
you think are necessary.
• Sometimes you want to leave easy to understand code in, rather than
short but difficult to understand tricks. Use your judgment.
• Remember that in the future, you may wish to use or alter the code you
wrote today. If you don‟t understand it today, you won‟t tomorrow.
Programming in general and Perl in particular

Develop your program in stages. Once part of it works, save the
working version to another file (or use a source code control
system like RCS) before continuing to improve it.
When running interactively, show the user signs of activity.
There is no need to dump everything to the screen (unless
requested to), but a few words or a number change every few
minutes will show that your program is doing something.
Comment your script. Any information on what it is doing or why
might be useful to you a few months later.
Decide on a coding convention and stick to it. For example,
– for variable names, begin globals with a capital letter and privates
(my) with a lower case letter
– indent new control structures with (say) 2 spaces
– line up closing braces, as in: if (....) { ... ... }
– Add blank lines between sections to improve readibility
>ultimate-sequence
ACTCGTTATGATATTTTTTTTGAACGTGAAAATACTTTTCGTGC
TATGGAAGGACTCGTTATCGTGAAGTTGAACGTTCTGAATG
TATGCCTCTTGAAATGGAAAATACTCATTGTTTATCTGAAAT
TTGAATGGGAATTTTATCTACAATGTTTTATTCTTACAGAAC
ATTAAATTGTGTTATGTTTCATTTCACATTTTAGTAGTTTTTT
CAGTGAAAGCTTGAAAACCACCAAGAAGAAAAGCTGGTAT
GCGTAGCTATGTATATATAAAATTAGATTTTCCACAAAAAAT
GATCTGATAAACCTTCTCTGTTGGCTCCAAGTATAAGTACG
AAAAGAAATACGTTCCCAAGAATTAGCTTCATGAGTAAGAA
GAAAAGCTGGTATGCGTAGCTATGTATATATAAAATTAGATT
TTCCACAAAAAATGATCTGATAA
File input / output
Opening a filehandle
• In order to use a filehandle other than STDIN,
STDOUT and STDERR, the filehandle needs to be
opened. The open function opens a file or device and
associates it with a filehandle.
• It returns 1 upon success and undef otherwise.
Examples
• # open a filehandle for reading: open
(SOURCE_FILE, "filename");
• # or open (SOURCE_FILE, "<filename");
• # open a filehandle for writing: open (RESULT_FILE,
">filename");
• # open a filehandle for appending: open (LOGFILE,
">>filename";
File input / output

Closing a filehandle
• When you are finished with a filehandle, you
may close it with the close function. The close
function closes the file or device associated
with the filehandle.
Example:
• close (MY_FILE_HANDLE); Filehandles are
automatically closed when the program exits,
or when the filehandle is reopened.
File input / output
The die function
• Sometimes the open function fails. For example, opening a file
for input might fail because the file does not exist, and opening a
file for output might fail because the file does not have a write
permission. A perl program will nevertheless use the filehandle,
and will not warn you that all input and output activities are
actually meaningless.
• Therefore, it is recommended to explicitly check the result of the
open command, and if it fails to print an error message and exit
the program.
• This is easily done using the die function.
Example:
• my $k = open (FILEHANDLE, "filename"); unless ($k) { die
("cannot open file filename: $!"); } # in case file "filename"
cannot be opened, # the argument of die will be printed on # the
screen and the program will exit. # $! is a special variable that
contains the respective # error message sent by the operating
system.. A short hand:
• open (FILEHANDLE, "filename") || die "cannot open file
filename: $!";
Using filehandles for writing
Example:
#!/usr/local/bin/perl use strict;
use warnings;
open (OUTF, ">out_file") || die "cannot open out_file:
$!"; open (LOGF, ">>log_file") || die "cannot open
log_file: $!";
print OUTF "Here is my program outputn";
print LOGF "First task of my program completedn";
print "Nice, isn't it?n"; # will be printed on the screen
close (OUTF);
close (LOGF);
Using filehandles for reading (2/3)
When <FILEHANDLE> is assigned into an array variable, all lines up to the end of
the file are read at once. Each line becomes a separate element of the array.
#!/usr/local/bin/perl
use strict;
use warnings;
my $infile = "CEACAM3.txt";
open (FH, $infile) || die "cannot open "$infile": $!";
my @lines = <FH>;
chomp (@lines); # chomp each element of @lines
close (FH);
# to process the lines you might wish to iterate
# over the @lines array with a foreach loop:
my $line;
foreach $line (@lines) {
# process $line. here we just print it.
print "$linen";
}
Using filehandles for reading (1/3)
#!/usr/local/bin/perl
use strict;
use warnings;
my $infile = "CEACAM3.txt";
my ($line1, $line2, $line3);
open (FH, $infile) || die "cannot open "$infile": $!";
$line1 = <FH>; # read first line
print $line1; # proccess line (here we only print it)
$line2 = <FH>; # read next line
print $line2; # proccess line (here we only print it)
$line3 = <FH>; # read next line
print $line3; # proccess line (here we only print it)
close (FH);
Using filehandles for reading (3/3)
Using a while loop, read one line at a time and assign it into a scalar variable, as
long as the variable is not an empty string (which will happen at end-of-file).
Note that a blank line read from the file will not result in an empty string, since it still
contains the terminating n.
#!/usr/local/bin/perl
use strict;
use warnings;
my $infile = "CEACAM3.txt";
open (FH, $infile) || die "cannot open "$infile": $!";
my $line;
# or, in one line:
while ($line = <FH>) { # while (my $line = <FH>) {
chomp ($line);
print "$linen"; # process line. here we just print it.

}
close (FH);
• Demo: Prosite Parser
1. Swiss-Knife.pl

• Database
– http://www.ebi.ac.uk/swissprot/FTP/ftp.html
– How many entries are there ?
– Average Protein Length (in aa and MW)
– Relative frequency of amino acids
• Compare to the ones used to construct the PAM
scoring matrixes from 1978 – 1991
Amino acid frequencies

Secondstep: Frequencies of Occurence
L
A
G
S
V
E
T
K
I
D
R
P
N
Q
F
Y
M
H
C
W

1978
0.085
0.087
0.089
0.070
0.065
0.050
0.058
0.081
0.037
0.047
0.041
0.051
0.040
0.038
0.040
0.030
0.015
0.034
0.033
0.010

1991
0.091
0.077
0.074
0.069
0.066
0.062
0.059
0.059
0.053
0.052
0.051
0.051
0.043
0.041
0.040
0.032
0.024
0.023
0.020
0.014
Parser.pl
•
•

#! C:Perlbinperl.exe -w
# (Vergeet niet het pad van perl.exe hierboven aan te passen aan de plaats op je eigen computer)

•
•

# Voorbeeld van het gebruik van substrings en files
# in een parser van sequentie-informatie-records

•
•

use strict;
use warnings;

•

my ($sp_file,$line,$id,$ac,$de);

•
•

$sp_file= "sp.txt";
open (SP,$sp_file) || die "cannot open "$sp_file":$!";

•
•

while ($line=<SP>){
chomp($line);

•
•

my $field = substr ($line,0,2);
my $value = substr ($line,5);

•
•
•
•
•
•
•
•
•
•

if ($field eq "ID"){e
$id = $value
}
if ($field eq "AC"){
$ac = $value
}
if ($field eq "DE"){
$de = $value
}
}

•
•
•

print "Identification: $idn";
print "Accession No.: $acn";
print "Description: $den";
2. PAM-simulator.pl
– Check transition matrix with and without randomizing the
rows of evolutions

– Adapt the program to simulate evolving DNA
– Adapt the program so it generates random proteins taking
into account the relative frequences found in step 1
– Write the output to a multi-fasta file
>PAM1
AHFALKJHFDLKFJHALSKJFH
>PAM2
AHGALKJHFDLKFJHALSKJFH
>PAM3
AHGALKJHFDLKFJHALSKJFH
Experiment: pam-simulator.pl

• Initialize:
– Generate Random protein (1000 aa)

• Simulate evolution (eg 250 for PAM250)
– Apply PAM1 Transition matrix to each amino
acid
– Use Weighted Random Selection

• Iterate
– Measure difference to orginal protein
Dayhoff’s PAM1 mutation probability matrix (Transition Matrix)

A
Ala
A
R
N
D
C
Q
E
G
H
I

R
N
D
C
Q
E
G
H
Arg Asn Asp Cys Gln Glu Gly His

I
Ile

9867

2

9

10

3

8

17

21

2

6

1

9913

1

0

1

10

0

0

10

3

4

1

9822

36

0

4

6

6

21

3

6

0

42

9859

0

6

53

6

4

1

1

1

0

0

9973

0

0

0

1

1

3

9

4

5

0

9876

27

1

23

1

10

0

7

56

0

35

9865

4

2

3

21

1

12

11

1

3

7

9935

1

0

1

8

18

3

1

20

1

0

9912

0

2

2

3

1

2

1

2

0

0

9872
Weighted Random Selection

• Ala => Xxx (%)
A
R
N
D
C
Q
E
G
H
I
L
K
M
F
P
S
T
W
Y
V
PAM-Simulator
PAM-simulator
120

100

%identity

80

60

40

20

0
0

50

100

150
PAM

200

250

300
3. Palindromes

What is the longest palindroom in palin.fasta ?
Why are restriction sites palindromic ?
How long is the longest palindroom in the genome ?
Hints:
http://www.man.poznan.pl/cmst/papers/5/art_2/vol5a
rt2.html
Palingram.pl
Palin.fasta
• >palin.fasta
• ATGGCTTATTTATTTGCCCACAAGAACTTAGGTGCATTGAAATCTAAA
GCTAATTGCTTATTTAGCTTTGCTTGGCCTTTTCACTTAAATAAAACA
TAGCATCAACTTCAGCAGGAATGGGTGCACATGCTGATCGAGGTGG
AAGAAGGGCACATATGGCATCGGCATCCTTATGGCTAATTTTAAATG
GAGAACTTTCTAAAGTCACGTTTTCACATGCAATATTCTTAACATTTT
CAATTTTTTTTGTAACTAATTCTTCCCATCTACTATGTGTTTGCAAGAC
AATCTCAGTAGCAAACTCCTTATGCTTAGCCTCACCGTTAAAAGCAA
ACTTATTTGGGGGATCTCCACCAGGCATTTTATATATTTTGAACCACT
CTACTGACGCGTTAGCTTCAAGTAAACCAGGCATCACTTCTTTTACG
TCATCAATATCATTAAGCTTTGAAGCTAGAGGATCATTTACATCAATT
GCTATTACTTAGCTTAGCCCTTCAAGTACTTGAAGGGCTAAGCTTCC
AATCTGTTTCACCATTGTCAATCATAGCTAAGACACCCAGCAACTTAA
CTTGCAAAACAGATCCTCTTTCTGCAACTTTGTAACCTATCTCTATTA
CATCAACAGGATCACCATCACCAAATGCATTAGTGTGCTCATCAATA
AGATTTGGATCCTCCCAAGTCTGTGGCAAAGCTCCATAATTCCAAGG
ATAACC
Palingram.pl
#!E:perlbinperl -w
$line_input = "edellede parterretrap trap op sirenes en er is popart test";
$line_input =~ s/s//g;
$l = length($line_input);
for ($m = 0;$m<=$l-1;$m++)
{
$line = substr($line_input,$m);
print "length=$m:$lt".$line."n";
for $n (8..25)
{
print "Set van palingramn";
$re = qr /[a-z]{$n}/;
while(($key, $value) = each
print "pattern ($n) = $ren";
$regexes[$n-8] = $re;
{
}
print "$key => $valuen";
foreach (@regexes)
{
}
while ($line =~ m/$_/g)
{
$endline = $';
$match = $&;
$all = $match.$endline;
$revmatch = reverse($match);
if ($all =~ /^($revmatch)/)
{
$palindrome = $revmatch . "*" . $1 ;
$palhash{$palindrome}++;
}
}
}
}

(%palhash))

More Related Content

What's hot (20)

Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php
PhpPhp
Php
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
Php(report)
Php(report)Php(report)
Php(report)
 
PHP
PHPPHP
PHP
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php basics
Php basicsPhp basics
Php basics
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
php basics
php basicsphp basics
php basics
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Hack and HHVM
Hack and HHVMHack and HHVM
Hack and HHVM
 
tools
toolstools
tools
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
 

Viewers also liked

Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014Prof. Wim Van Criekinge
 
Bioinformatica 29-09-2011-t1-bioinformatics
Bioinformatica 29-09-2011-t1-bioinformaticsBioinformatica 29-09-2011-t1-bioinformatics
Bioinformatica 29-09-2011-t1-bioinformaticsProf. Wim Van Criekinge
 
Bioinformatics t1-introduction wim-vancriekinge_v2013
Bioinformatics t1-introduction wim-vancriekinge_v2013Bioinformatics t1-introduction wim-vancriekinge_v2013
Bioinformatics t1-introduction wim-vancriekinge_v2013Prof. Wim Van Criekinge
 
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vwebProf. Wim Van Criekinge
 
Bioinformatics t6-phylogenetics v2013-wim_vancriekinge
Bioinformatics t6-phylogenetics v2013-wim_vancriekingeBioinformatics t6-phylogenetics v2013-wim_vancriekinge
Bioinformatics t6-phylogenetics v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Van criekinge next_generation_epigenetic_profling_vvumc_uploaded
Van criekinge next_generation_epigenetic_profling_vvumc_uploadedVan criekinge next_generation_epigenetic_profling_vvumc_uploaded
Van criekinge next_generation_epigenetic_profling_vvumc_uploadedProf. Wim Van Criekinge
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekingeProf. Wim Van Criekinge
 
2015 bioinformatics databases_wim_vancriekinge
2015 bioinformatics databases_wim_vancriekinge2015 bioinformatics databases_wim_vancriekinge
2015 bioinformatics databases_wim_vancriekingeProf. Wim Van Criekinge
 

Viewers also liked (20)

Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Bioinformatics t4-alignments v2014
Bioinformatics t4-alignments v2014Bioinformatics t4-alignments v2014
Bioinformatics t4-alignments v2014
 
Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014
 
Bioinformatica t3-scoringmatrices v2014
Bioinformatica t3-scoringmatrices v2014Bioinformatica t3-scoringmatrices v2014
Bioinformatica t3-scoringmatrices v2014
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Bioinformatica p1-perl-introduction
Bioinformatica p1-perl-introductionBioinformatica p1-perl-introduction
Bioinformatica p1-perl-introduction
 
Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
 
Bioinformatica t6-phylogenetics
Bioinformatica t6-phylogeneticsBioinformatica t6-phylogenetics
Bioinformatica t6-phylogenetics
 
Molecular profiling 2012
Molecular profiling 2012Molecular profiling 2012
Molecular profiling 2012
 
Molecular profiling 2013
Molecular profiling 2013Molecular profiling 2013
Molecular profiling 2013
 
Bioinformatica 29-09-2011-t1-bioinformatics
Bioinformatica 29-09-2011-t1-bioinformaticsBioinformatica 29-09-2011-t1-bioinformatics
Bioinformatica 29-09-2011-t1-bioinformatics
 
2012 12 12_adam_v_final
2012 12 12_adam_v_final2012 12 12_adam_v_final
2012 12 12_adam_v_final
 
Bioinformatics t1-introduction wim-vancriekinge_v2013
Bioinformatics t1-introduction wim-vancriekinge_v2013Bioinformatics t1-introduction wim-vancriekinge_v2013
Bioinformatics t1-introduction wim-vancriekinge_v2013
 
Bioinformatica t5-database searching
Bioinformatica t5-database searchingBioinformatica t5-database searching
Bioinformatica t5-database searching
 
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb
2014 03 28_next_generation_epigenetic_profling_v_les_epigenetica_vweb
 
Bioinformatics t6-phylogenetics v2013-wim_vancriekinge
Bioinformatics t6-phylogenetics v2013-wim_vancriekingeBioinformatics t6-phylogenetics v2013-wim_vancriekinge
Bioinformatics t6-phylogenetics v2013-wim_vancriekinge
 
Van criekinge next_generation_epigenetic_profling_vvumc_uploaded
Van criekinge next_generation_epigenetic_profling_vvumc_uploadedVan criekinge next_generation_epigenetic_profling_vvumc_uploaded
Van criekinge next_generation_epigenetic_profling_vvumc_uploaded
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
2015 03 13_puurs_v_public
2015 03 13_puurs_v_public2015 03 13_puurs_v_public
2015 03 13_puurs_v_public
 
2015 bioinformatics databases_wim_vancriekinge
2015 bioinformatics databases_wim_vancriekinge2015 bioinformatics databases_wim_vancriekinge
2015 bioinformatics databases_wim_vancriekinge
 

Similar to Bioinformatics p4-io v2013-wim_vancriekinge

Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Prof. Wim Van Criekinge
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
php fundamental
php fundamentalphp fundamental
php fundamentalzalatarunk
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of phppooja bhandari
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercisesrICh morrow
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C LanguageMohamed Elsayed
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903DouglasPickett
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationMohammed Farrag
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxalfred4lewis58146
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 

Similar to Bioinformatics p4-io v2013-wim_vancriekinge (20)

Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises
 
tools
toolstools
tools
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docx
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
CInputOutput.ppt
CInputOutput.pptCInputOutput.ppt
CInputOutput.ppt
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Shell programming
Shell programmingShell programming
Shell programming
 

More from Prof. Wim Van Criekinge

2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_uploadProf. Wim Van Criekinge
 
2019 03 05_biological_databases_part4_v_upload
2019 03 05_biological_databases_part4_v_upload2019 03 05_biological_databases_part4_v_upload
2019 03 05_biological_databases_part4_v_uploadProf. Wim Van Criekinge
 
2019 03 05_biological_databases_part3_v_upload
2019 03 05_biological_databases_part3_v_upload2019 03 05_biological_databases_part3_v_upload
2019 03 05_biological_databases_part3_v_uploadProf. Wim Van Criekinge
 
2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_upload2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_uploadProf. Wim Van Criekinge
 
2019 02 12_biological_databases_part1_v_upload
2019 02 12_biological_databases_part1_v_upload2019 02 12_biological_databases_part1_v_upload
2019 02 12_biological_databases_part1_v_uploadProf. Wim Van Criekinge
 
Bio ontologies and semantic technologies[2]
Bio ontologies and semantic technologies[2]Bio ontologies and semantic technologies[2]
Bio ontologies and semantic technologies[2]Prof. Wim Van Criekinge
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_uploadProf. Wim Van Criekinge
 
2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_uploadProf. Wim Van Criekinge
 
2018 02 20_biological_databases_part1_v_upload
2018 02 20_biological_databases_part1_v_upload2018 02 20_biological_databases_part1_v_upload
2018 02 20_biological_databases_part1_v_uploadProf. Wim Van Criekinge
 

More from Prof. Wim Van Criekinge (20)

2020 02 11_biological_databases_part1
2020 02 11_biological_databases_part12020 02 11_biological_databases_part1
2020 02 11_biological_databases_part1
 
2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload
 
2019 03 05_biological_databases_part4_v_upload
2019 03 05_biological_databases_part4_v_upload2019 03 05_biological_databases_part4_v_upload
2019 03 05_biological_databases_part4_v_upload
 
2019 03 05_biological_databases_part3_v_upload
2019 03 05_biological_databases_part3_v_upload2019 03 05_biological_databases_part3_v_upload
2019 03 05_biological_databases_part3_v_upload
 
2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_upload2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_upload
 
2019 02 12_biological_databases_part1_v_upload
2019 02 12_biological_databases_part1_v_upload2019 02 12_biological_databases_part1_v_upload
2019 02 12_biological_databases_part1_v_upload
 
P7 2018 biopython3
P7 2018 biopython3P7 2018 biopython3
P7 2018 biopython3
 
P6 2018 biopython2b
P6 2018 biopython2bP6 2018 biopython2b
P6 2018 biopython2b
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
T1 2018 bioinformatics
T1 2018 bioinformaticsT1 2018 bioinformatics
T1 2018 bioinformatics
 
P1 2018 python
P1 2018 pythonP1 2018 python
P1 2018 python
 
Bio ontologies and semantic technologies[2]
Bio ontologies and semantic technologies[2]Bio ontologies and semantic technologies[2]
Bio ontologies and semantic technologies[2]
 
2018 05 08_biological_databases_no_sql
2018 05 08_biological_databases_no_sql2018 05 08_biological_databases_no_sql
2018 05 08_biological_databases_no_sql
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload
 
2018 03 20_biological_databases_part3
2018 03 20_biological_databases_part32018 03 20_biological_databases_part3
2018 03 20_biological_databases_part3
 
2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload
 
2018 02 20_biological_databases_part1_v_upload
2018 02 20_biological_databases_part1_v_upload2018 02 20_biological_databases_part1_v_upload
2018 02 20_biological_databases_part1_v_upload
 
P7 2017 biopython3
P7 2017 biopython3P7 2017 biopython3
P7 2017 biopython3
 
P6 2017 biopython2
P6 2017 biopython2P6 2017 biopython2
P6 2017 biopython2
 

Recently uploaded

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 

Recently uploaded (20)

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 

Bioinformatics p4-io v2013-wim_vancriekinge

  • 1.
  • 3. Programming • Variables • Flow control (if, regex …) • Loops • input/output • Subroutines/object
  • 4. Three Basic Data Types • Scalars - $ • Arrays of scalars - @ • Associative arrays of scalers or Hashes - %
  • 6. The „structure‟ of a Hash • An array looks something like this: 0 @array = 1 2 'val1' 'val2' 'val3' Index Value • A hash looks something like this: Rob Matt Joe_A %phone = 353-7236 353-7122 555-1212 Key (name) Value
  • 7. Printing a hash (continued) • First, create a list of keys. Fortunately, there is a function for that: – keys %hash (returns a list of keys) • Next, visit each key and print its associated value: foreach (keys %hash){ print “The key $_ has the value $hash{$_}n”; } • One complication. Hashes do not maintain any sort of order. In other words, if you put key/value pairs into a hash in a particular order, you will not get them out in that order!!
  • 8. my %AA1 = ( 'UUU','F', 'UUC','F', 'UUA','L', 'UUG','L', 'UCU','S', 'UCC','S', 'UCA','S', 'UCG','S', 'UAU','Y', 'UAC','Y', 'UAA','*', 'UAG','*', 'UGU','C', 'UGC','C', 'UGA','*', 'UGG','W', 'CUU','L', 'CUC','L', 'CUA','L', 'CUG','L', 'CCU','P', 'CCC','P', 'CCA','P', 'CCG','P', 'CAU','H', 'CAC','H', 'CAA','Q', 'CAG','Q', 'CGU','R', 'CGC','R', 'CGA','R', 'CGG','R', 'AUU','I', 'AUC','I', 'AUA','I', 'AUG','M', 'ACU','T', 'ACC','T', 'ACA','T', 'ACG','T', 'AAU','N', 'AAC','N', 'AAA','K', 'AAG','K', 'AGU','S', 'AGC','S', 'AGA','R', 'AGG','R', 'GUU','V', 'GUC','V', 'GUA','V', 'GUG','V', 'GCU','A', 'GCC','A', 'GCA','A', 'GCG','A', 'GAU','D', 'GAC','D', 'GAA','E', 'GAG','E', 'GGU','G', 'GGC','G', 'GGA','G', 'GGG','G' );
  • 9. Programming in general and Perl in particular • There is more than one right way to do it. Unfortunately, there are also many wrong ways. – 1. Always check and make sure the output is correct and logical • Consider what errors might occur, and take steps to ensure that you are accounting for them. – 2. Check to make sure you are using every variable you declare. • Use Strict ! – 3. Always go back to a script once it is working and see if you can eliminate unnecessary steps. • Concise code is good code. • You will learn more if you optimize your code. • Concise does not mean comment free. Please use as many comments as you think are necessary. • Sometimes you want to leave easy to understand code in, rather than short but difficult to understand tricks. Use your judgment. • Remember that in the future, you may wish to use or alter the code you wrote today. If you don‟t understand it today, you won‟t tomorrow.
  • 10. Programming in general and Perl in particular Develop your program in stages. Once part of it works, save the working version to another file (or use a source code control system like RCS) before continuing to improve it. When running interactively, show the user signs of activity. There is no need to dump everything to the screen (unless requested to), but a few words or a number change every few minutes will show that your program is doing something. Comment your script. Any information on what it is doing or why might be useful to you a few months later. Decide on a coding convention and stick to it. For example, – for variable names, begin globals with a capital letter and privates (my) with a lower case letter – indent new control structures with (say) 2 spaces – line up closing braces, as in: if (....) { ... ... } – Add blank lines between sections to improve readibility
  • 12. File input / output Opening a filehandle • In order to use a filehandle other than STDIN, STDOUT and STDERR, the filehandle needs to be opened. The open function opens a file or device and associates it with a filehandle. • It returns 1 upon success and undef otherwise. Examples • # open a filehandle for reading: open (SOURCE_FILE, "filename"); • # or open (SOURCE_FILE, "<filename"); • # open a filehandle for writing: open (RESULT_FILE, ">filename"); • # open a filehandle for appending: open (LOGFILE, ">>filename";
  • 13. File input / output Closing a filehandle • When you are finished with a filehandle, you may close it with the close function. The close function closes the file or device associated with the filehandle. Example: • close (MY_FILE_HANDLE); Filehandles are automatically closed when the program exits, or when the filehandle is reopened.
  • 14. File input / output The die function • Sometimes the open function fails. For example, opening a file for input might fail because the file does not exist, and opening a file for output might fail because the file does not have a write permission. A perl program will nevertheless use the filehandle, and will not warn you that all input and output activities are actually meaningless. • Therefore, it is recommended to explicitly check the result of the open command, and if it fails to print an error message and exit the program. • This is easily done using the die function. Example: • my $k = open (FILEHANDLE, "filename"); unless ($k) { die ("cannot open file filename: $!"); } # in case file "filename" cannot be opened, # the argument of die will be printed on # the screen and the program will exit. # $! is a special variable that contains the respective # error message sent by the operating system.. A short hand: • open (FILEHANDLE, "filename") || die "cannot open file filename: $!";
  • 15. Using filehandles for writing Example: #!/usr/local/bin/perl use strict; use warnings; open (OUTF, ">out_file") || die "cannot open out_file: $!"; open (LOGF, ">>log_file") || die "cannot open log_file: $!"; print OUTF "Here is my program outputn"; print LOGF "First task of my program completedn"; print "Nice, isn't it?n"; # will be printed on the screen close (OUTF); close (LOGF);
  • 16. Using filehandles for reading (2/3) When <FILEHANDLE> is assigned into an array variable, all lines up to the end of the file are read at once. Each line becomes a separate element of the array. #!/usr/local/bin/perl use strict; use warnings; my $infile = "CEACAM3.txt"; open (FH, $infile) || die "cannot open "$infile": $!"; my @lines = <FH>; chomp (@lines); # chomp each element of @lines close (FH); # to process the lines you might wish to iterate # over the @lines array with a foreach loop: my $line; foreach $line (@lines) { # process $line. here we just print it. print "$linen"; }
  • 17. Using filehandles for reading (1/3) #!/usr/local/bin/perl use strict; use warnings; my $infile = "CEACAM3.txt"; my ($line1, $line2, $line3); open (FH, $infile) || die "cannot open "$infile": $!"; $line1 = <FH>; # read first line print $line1; # proccess line (here we only print it) $line2 = <FH>; # read next line print $line2; # proccess line (here we only print it) $line3 = <FH>; # read next line print $line3; # proccess line (here we only print it) close (FH);
  • 18. Using filehandles for reading (3/3) Using a while loop, read one line at a time and assign it into a scalar variable, as long as the variable is not an empty string (which will happen at end-of-file). Note that a blank line read from the file will not result in an empty string, since it still contains the terminating n. #!/usr/local/bin/perl use strict; use warnings; my $infile = "CEACAM3.txt"; open (FH, $infile) || die "cannot open "$infile": $!"; my $line; # or, in one line: while ($line = <FH>) { # while (my $line = <FH>) { chomp ($line); print "$linen"; # process line. here we just print it. } close (FH);
  • 20. 1. Swiss-Knife.pl • Database – http://www.ebi.ac.uk/swissprot/FTP/ftp.html – How many entries are there ? – Average Protein Length (in aa and MW) – Relative frequency of amino acids • Compare to the ones used to construct the PAM scoring matrixes from 1978 – 1991
  • 21. Amino acid frequencies Secondstep: Frequencies of Occurence L A G S V E T K I D R P N Q F Y M H C W 1978 0.085 0.087 0.089 0.070 0.065 0.050 0.058 0.081 0.037 0.047 0.041 0.051 0.040 0.038 0.040 0.030 0.015 0.034 0.033 0.010 1991 0.091 0.077 0.074 0.069 0.066 0.062 0.059 0.059 0.053 0.052 0.051 0.051 0.043 0.041 0.040 0.032 0.024 0.023 0.020 0.014
  • 22. Parser.pl • • #! C:Perlbinperl.exe -w # (Vergeet niet het pad van perl.exe hierboven aan te passen aan de plaats op je eigen computer) • • # Voorbeeld van het gebruik van substrings en files # in een parser van sequentie-informatie-records • • use strict; use warnings; • my ($sp_file,$line,$id,$ac,$de); • • $sp_file= "sp.txt"; open (SP,$sp_file) || die "cannot open "$sp_file":$!"; • • while ($line=<SP>){ chomp($line); • • my $field = substr ($line,0,2); my $value = substr ($line,5); • • • • • • • • • • if ($field eq "ID"){e $id = $value } if ($field eq "AC"){ $ac = $value } if ($field eq "DE"){ $de = $value } } • • • print "Identification: $idn"; print "Accession No.: $acn"; print "Description: $den";
  • 23. 2. PAM-simulator.pl – Check transition matrix with and without randomizing the rows of evolutions – Adapt the program to simulate evolving DNA – Adapt the program so it generates random proteins taking into account the relative frequences found in step 1 – Write the output to a multi-fasta file >PAM1 AHFALKJHFDLKFJHALSKJFH >PAM2 AHGALKJHFDLKFJHALSKJFH >PAM3 AHGALKJHFDLKFJHALSKJFH
  • 24. Experiment: pam-simulator.pl • Initialize: – Generate Random protein (1000 aa) • Simulate evolution (eg 250 for PAM250) – Apply PAM1 Transition matrix to each amino acid – Use Weighted Random Selection • Iterate – Measure difference to orginal protein
  • 25. Dayhoff’s PAM1 mutation probability matrix (Transition Matrix) A Ala A R N D C Q E G H I R N D C Q E G H Arg Asn Asp Cys Gln Glu Gly His I Ile 9867 2 9 10 3 8 17 21 2 6 1 9913 1 0 1 10 0 0 10 3 4 1 9822 36 0 4 6 6 21 3 6 0 42 9859 0 6 53 6 4 1 1 1 0 0 9973 0 0 0 1 1 3 9 4 5 0 9876 27 1 23 1 10 0 7 56 0 35 9865 4 2 3 21 1 12 11 1 3 7 9935 1 0 1 8 18 3 1 20 1 0 9912 0 2 2 3 1 2 1 2 0 0 9872
  • 26. Weighted Random Selection • Ala => Xxx (%) A R N D C Q E G H I L K M F P S T W Y V
  • 28. 3. Palindromes What is the longest palindroom in palin.fasta ? Why are restriction sites palindromic ? How long is the longest palindroom in the genome ? Hints: http://www.man.poznan.pl/cmst/papers/5/art_2/vol5a rt2.html Palingram.pl
  • 30. Palingram.pl #!E:perlbinperl -w $line_input = "edellede parterretrap trap op sirenes en er is popart test"; $line_input =~ s/s//g; $l = length($line_input); for ($m = 0;$m<=$l-1;$m++) { $line = substr($line_input,$m); print "length=$m:$lt".$line."n"; for $n (8..25) { print "Set van palingramn"; $re = qr /[a-z]{$n}/; while(($key, $value) = each print "pattern ($n) = $ren"; $regexes[$n-8] = $re; { } print "$key => $valuen"; foreach (@regexes) { } while ($line =~ m/$_/g) { $endline = $'; $match = $&; $all = $match.$endline; $revmatch = reverse($match); if ($all =~ /^($revmatch)/) { $palindrome = $revmatch . "*" . $1 ; $palhash{$palindrome}++; } } } } (%palhash))