Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dept. of Animal Breeding and Genetics www.hgen.slu.se Programming basics & introduction to PERL Mats Pettersson.

Similar presentations


Presentation on theme: "Dept. of Animal Breeding and Genetics www.hgen.slu.se Programming basics & introduction to PERL Mats Pettersson."— Presentation transcript:

1 Dept. of Animal Breeding and Genetics www.hgen.slu.se Programming basics & introduction to PERL Mats Pettersson

2 Dept. of Animal Breeding and Genetics www.hgen.slu.se Some jargon: Source code – plain text files with commands Language – collection of definition Compiler – “translator” from text to binary files Interpreter – executes a source file line by line Algorithm – a “recipe” to get from input to output Variable – data “container” Assignment – putting data into a variable

3 Dept. of Animal Breeding and Genetics www.hgen.slu.se Algorithms Define the task Break it down to small steps Find a way to achieve each step - implementation

4 Dept. of Animal Breeding and Genetics www.hgen.slu.se Fundamental operations Reading input Manipulating data - Math - Data reshuffling - Flow control Writing output

5 Dept. of Animal Breeding and Genetics www.hgen.slu.se Control statements Conditional statements - if – elseif – else Loops - for – foreach – while

6 Dept. of Animal Breeding and Genetics www.hgen.slu.se Data manipulation Extracting subsets of data - pattern matching Data structures - connecting different types of data - representing matrices or tables

7 Dept. of Animal Breeding and Genetics www.hgen.slu.se The PERL language Primarily for text manipulation - Deals very well with large files High-level language - Very concise scripts - Readability is an issue Large amounts of existing modules - BioPerl

8 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL data types Scalar($) Single value variable Array(@) Ordered collection of values (“row”) Hash(%) Unordered, but names, collection of values

9 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL data types $scalar = 5 @array = (1, 2, 3) $array[0] %hash = (“key1” => 3, “key2” => 4) $hash{“key1”}

10 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL I/O operations Open - modes (>/<) - file handle Read - <> operator Close

11 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL I/O operations open HANDLE “>filename” print HANDLE “Hello world!” close HANDLE

12 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL string manipulation Split - creates an array from a string Join - reverse split Chomp - removes trailing newline symbol (\n)

13 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL string matching Regular expressions - generalized string patterns - character groups [] - special symbols (^, $,., \, +, ?,/) The =~ operator - “binds” the string of interest to the pattern - modifiers (s, g)

14 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL references Scalar that “point” to arrays or hashes $aref = \@array $href = \@hash $aref = [1,2,3] $href = {“key1” => 3, “key2” => 4} Useful for 2D structures

15 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL references Dereferencing @{$aref} %{$href} $aref->[0] $href->{“key1”}

16 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL oddities The default variable ($_) - stores latest result - default argument for methods Implicit declaration - variable type deduced from context Very flexible syntax - hard to read - mistakes happen

17 Dept. of Animal Breeding and Genetics www.hgen.slu.se PERL tutorials http://perldoc.perl.org/index-tutorials.html http://www.bioperl.org/wiki/HOWTOs

18 Dept. of Animal Breeding and Genetics www.hgen.slu.se BioPerl A larger collection of modules intended for use in bioinformatics - Sequence retrieval - Database searches - Alignment


Download ppt "Dept. of Animal Breeding and Genetics www.hgen.slu.se Programming basics & introduction to PERL Mats Pettersson."

Similar presentations


Ads by Google