Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson
Dept. of Animal Breeding and Genetics 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
Dept. of Animal Breeding and Genetics Algorithms Define the task Break it down to small steps Find a way to achieve each step - implementation
Dept. of Animal Breeding and Genetics Fundamental operations Reading input Manipulating data - Math - Data reshuffling - Flow control Writing output
Dept. of Animal Breeding and Genetics Control statements Conditional statements - if – elseif – else Loops - for – foreach – while
Dept. of Animal Breeding and Genetics Data manipulation Extracting subsets of data - pattern matching Data structures - connecting different types of data - representing matrices or tables
Dept. of Animal Breeding and Genetics 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
Dept. of Animal Breeding and Genetics PERL data types Scalar($) Single value variable Ordered collection of values (“row”) Hash(%) Unordered, but names, collection of values
Dept. of Animal Breeding and Genetics PERL data types $scalar = = (1, 2, 3) $array[0] %hash = (“key1” => 3, “key2” => 4) $hash{“key1”}
Dept. of Animal Breeding and Genetics PERL I/O operations Open - modes (>/<) - file handle Read - <> operator Close
Dept. of Animal Breeding and Genetics PERL I/O operations open HANDLE “>filename” print HANDLE “Hello world!” close HANDLE
Dept. of Animal Breeding and Genetics PERL string manipulation Split - creates an array from a string Join - reverse split Chomp - removes trailing newline symbol (\n)
Dept. of Animal Breeding and Genetics 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)
Dept. of Animal Breeding and Genetics PERL references Scalar that “point” to arrays or hashes $aref = $href = $aref = [1,2,3] $href = {“key1” => 3, “key2” => 4} Useful for 2D structures
Dept. of Animal Breeding and Genetics PERL references %{$href} $aref->[0] $href->{“key1”}
Dept. of Animal Breeding and Genetics 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
Dept. of Animal Breeding and Genetics PERL tutorials
Dept. of Animal Breeding and Genetics BioPerl A larger collection of modules intended for use in bioinformatics - Sequence retrieval - Database searches - Alignment