Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp

Similar presentations


Presentation on theme: "Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp"— Presentation transcript:

1 Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp http://bioinf.gen.tcd.ie/GE3M25/programming

2 Computer Programming for Biologists  Revision  Loop control  Project Overview

3 Computer Programming for Biologists  expressions 42 $base eq 'T' $num – 1 == 0  statements $seq = 'atgaacgt'; print "hello world!\n"; Revision: program components  operators +, -, *, /, +=, ++, …  built-in functions print, shift, length, …  key words foreach, while, if, …

4 Computer Programming for Biologists  ordered list of elements  indicated by 'at' symbol (@)  index starts at 0 @letters = ('a'..'z'); #  (a, b, c, d, e, …, x, y, z)  Use $ and [] when working on individual elements: $letters[0] = 'A'; $first = $letters[0]; $last = $letters[-1]; default: @ARGV Revision: Arrays Index: 0 1 2 3 4 23 24 25

5 Computer Programming for Biologists $upper = uc($in); $upper_first = uc_first($in); $backwards = reverse($in); $len = length($sequence); $num = scalar @ARGV; $file = shift @ARGV; push @prot, $aa; Revision: built-in functions @bases = split //, $seq; $out = join '_', @letters; @found = keys %found; @order = sort @letters; @out = sort { $a $b } @nums; $codon = substr $seq, 0, 3, ''; print "Hello world!\n";

6 Computer Programming for Biologists  branching: if ($base eq 't') { $base = 'u'; }  also unless () if ($base eq 't') { $base = 'a'; } elsif ($base eq 'a') { $base = 't'; } else { … } Revision: structures  loops: while ($in = <>) { $out.= uc($in); }  also until () foreach $element (@list) { $i++; print "$i) $element"; … }

7 Computer Programming for Biologists  Representative values:  Examples: while (1) {... } # endless loop if ($text) {... } # true if text neither '' nor 0 if (@rows) {... } # true if array is not empty until ($i > 100) {... } # comparison or expression while ($out = substr $seq, 0, 3, '') {... } Revision: conditions truefalse 10 'some characters''' ('some element')()

8 Computer Programming for Biologists  word(s) from list of command line parameters: $in = shift;  equivalent to the following:  $in = shift @ARGV; Revision: data input (command line arguments)

9 Reading from STDIN, default input stream: $in = <>;  equivalent to $in = ; Shell tries to stream from file(s) if command line argument(s) present: $ perl prog.pl input.txt STDIN Computer Programming for Biologists Revision: data input

10 Computer Programming for Biologists  Ways of breaking the loops: next; # continues with next loop last; # continues after loop exit; # exits program Structures: Breaks  example print "Type 'y' to continue, 'q' to quit: "; while (<>) { if ($_ eq 'y') { last; } elsif ($_ eq 'q') { exit; } else { next; }

11 Computer Programming for Biologists  start with pseudo code (comments)  code small bits and run  watch for warnings and errors  dare to try things out  check Perl documentation Programming Strategy

12 Computer Programming for Biologists Implement the following in a program: 1. Print a welcome message 2. Read input from a file 3. Separate header from sequence 4. Report length of sequence 5. Make sequence all upper case 6. Reformat sequence into 60 bp width 7. Reverse-complement the sequence 8. Provide position numbers at each line  Go to http://bioinf.gen.tcd.ie/GE3M25/programming/class4 Project


Download ppt "Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp"

Similar presentations


Ads by Google