Download presentation
Presentation is loading. Please wait.
Published byBarnaby Gibson Modified over 9 years ago
1
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp http://bioinf.gen.tcd.ie/GE3M25/programming
2
Computer Programming for Biologists Pragmas Project Overview
3
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
4
Safer Programming Adding pragmas use warnings; use strict; my $dna = ''; while (my $input = <>) { chomp my $input; my $dna.= $input; }
5
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
6
Safer Programming Adding pragmas use warnings; use strict; my $dna = ''; while (my $input = <>) { chomp $input; $dna.= $input; }
7
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
8
Functions Example 1: @chars = split //, $string; Turn string into an array Example 2: @frags = split /$motif/i, $sequence; Simulate enzyme digestion Example 3: $output = join "\t", @list; Connect elements with TAB for printing split and join
9
Practical http://bioinf.gen.tcd.ie/GE3M25/programming/class6
10
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 e-mail me at kahokamp@tcd.ie with questions or problemskahokamp@tcd.ie Exercises
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.