Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
Computer Programming for Biologists Pragmas Project Overview
Instructions to Perl interpreter Changes behaviour when running your script Helps avoiding mistakes and writing better code! Safer Programming Adding pragmas use warnings; use strict; my $input = shift; declare variables at FIRST occurrence require declaration of variables turn on warning messages
Safer Programming Adding pragmas use warnings; use strict; my $dna = ''; while (my $input = <>) { chomp my $input; my $dna.= $input; }
Safer Programming Adding pragmas use warnings; use strict; my $dna = ''; while (my $input = <>) { chomp my $input; my $dna.= $input; } correct – first occurrence wrong – subsequent occurrence
Safer Programming Adding pragmas use warnings; use strict; my $dna = ''; while (my $input = <>) { chomp $input; $dna.= $input; }
Functions split turn a string into a list split at regular expression join combine a list into a string join using specified character(s) split and join
Functions Example = split //, $string; Turn string into an array Example = split /$motif/i, $sequence; Simulate enzyme digestion Example 3: $output = join Connect elements with TAB for printing split and join
Practical
Computer Programming for Biologists Extend your sequence analysis tool: -add warnings and strict pragmas -add 'my' to variable initialisation -add capability to report GC content -count number of G's and C's (using substr or split to access one nucleotide at a time) -divide by length of sequence me at with questions or Exercises