Bioinformatica 29-09-2011-p1-introduction

1,014 views
943 views

Published on

Bioinformatica Practicum I

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,014
On SlideShare
0
From Embeds
0
Number of Embeds
40
Actions
Shares
0
Downloads
54
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Bioinformatica 29-09-2011-p1-introduction

  1. 2. FBW 30-09-2010 Wim Van Criekinge
  2. 4. Practicum Bioinformatica <ul><li>Practicum </li></ul><ul><ul><li>Inleiding tot Perl </li></ul></ul><ul><ul><li>Write your first PERL program ! </li></ul></ul><ul><ul><li>Execute your first.pl </li></ul></ul>
  3. 5. <ul><li>Perl is a High-level Scripting language </li></ul><ul><li>Larry Wall created Perl in 1987 </li></ul><ul><ul><li>P ractical E xtraction ( a )nd R eporting L anguage </li></ul></ul><ul><ul><li>(or Pathologically Eclectic Rubbish Lister) </li></ul></ul><ul><li>Born from a system administration tool </li></ul><ul><li>Faster than sh or csh </li></ul><ul><li>Sslower than C </li></ul><ul><li>No need for sed, awk, tr, wc, cut, … </li></ul><ul><li>Perl is open and free </li></ul><ul><li>http://conferences.oreillynet.com/eurooscon/ </li></ul>What is Perl ?
  4. 6. <ul><li>Perl is available for most computing platforms: all flavors of UNIX (Linux), MS-DOS/Win32, Macintosh, VMS, OS/2, Amiga, AS/400, Atari </li></ul><ul><li>Perl is a computer language that is: </li></ul><ul><ul><li>Interpreted, compiles at run-time (need for perl.exe !) </li></ul></ul><ul><ul><li>Loosely “typed” </li></ul></ul><ul><ul><li>String/text oriented </li></ul></ul><ul><ul><li>Capable of using multiple syntax formats </li></ul></ul><ul><li>In Perl, “there’s more than one way to do it” </li></ul>What is Perl ?
  5. 7. <ul><li>Ease of use by novice programmers </li></ul><ul><li>Flexible language: Fast software prototyping (quick and dirty creation of small analysis programs) </li></ul><ul><li>Expressiveness . Compact code, Perl Poetry: @{$_[$#_]||[]} </li></ul><ul><li>Glutility : Read disparate files and parse the relevant data into a new format </li></ul><ul><li>Powerful pattern matching via “regular expressions” (Best Regular Expressions on Earth) </li></ul><ul><li>With the advent of the WWW, Perl has become the language of choice to create Common Gateway Interface (CGI) scripts to handle form submissions and create compute severs on the WWW. </li></ul><ul><li>Open Source – Free . Availability of Perl modules for Bioinformatics and Internet. </li></ul>Why use Perl for bioinformatics ?
  6. 8. <ul><li>Some tasks are still better done with other languages (heavy computations / graphics) </li></ul><ul><ul><li>C(++),C#, Fortran, Java (Pascal,Visual Basic) </li></ul></ul><ul><li>With perl you can write simple programs fast, but on the other hand it is also suitable for large and complex programs. (yet, it is not adequate for very large projects) </li></ul><ul><ul><li>Python </li></ul></ul><ul><li>Larry Wall: “For programmers, laziness is a virtue” </li></ul>Why NOT use Perl for bioinformatics ?
  7. 9. <ul><li>Sequence manipulation and analysis </li></ul><ul><li>Parsing results of sequence analysis programs (Blast, Genscan, Hmmer etc) </li></ul><ul><li>Parsing database (eg Genbank) files </li></ul><ul><li>Obtaining multiple database entries over the internet </li></ul><ul><li>… </li></ul>What bioinformatics tasks are suited to Perl ?
  8. 10. Example of problems we will be solving <ul><li>Primary Sequence analysis </li></ul><ul><li>Perform alignments </li></ul><ul><li>Simulation experiments to explain Blast statistics </li></ul><ul><li>Predicting protein topology </li></ul><ul><li>Predicting secondary structures </li></ul><ul><li>“ Real-life” problems </li></ul><ul><ul><li>Proteomics: Given aa masses find protein in database </li></ul></ul><ul><ul><li>… </li></ul></ul>
  9. 11. <ul><li>Perl (op CD-ROM): </li></ul><ul><ul><li>Perl is available for various operating systems. To download Perl and install it on your computer, have a look at the following resources: </li></ul></ul><ul><ul><li>www.perl.com (O'Reilly). </li></ul></ul><ul><ul><ul><li>Downloading Perl Software </li></ul></ul></ul><ul><ul><li>ActiveState . ActivePerl for Windows , as well as for Linux and Solaris. </li></ul></ul><ul><ul><ul><li>ActivePerl binary packages . </li></ul></ul></ul><ul><ul><li>CPAN </li></ul></ul><ul><li>PHPTriad: </li></ul><ul><ul><li>bevat Apache/PHP en MySQL: http://sourceforge.net/projects/phptriad </li></ul></ul>Perl installation
  10. 12. Check installation <ul><li>Command-line flags for perl </li></ul><ul><ul><li>Perl – v </li></ul></ul><ul><ul><ul><li>Gives the current version of Perl </li></ul></ul></ul><ul><ul><li>Perl –e </li></ul></ul><ul><ul><ul><li>Executes Perl statements from the comment line. </li></ul></ul></ul><ul><ul><ul><ul><li>Perl –e “print 42;” </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Perl –e “print ”Twonlinesn”;” </li></ul></ul></ul></ul><ul><ul><li>Perl –we </li></ul></ul><ul><ul><ul><li>Executes and print warnings </li></ul></ul></ul><ul><ul><ul><ul><li>Perl –we “print ‘hello’;x++;” </li></ul></ul></ul></ul>
  11. 13. How to enter your first program ? <ul><li>Gebruik een editor </li></ul><ul><ul><li>DOS: EDIT </li></ul></ul><ul><ul><li>Windows: </li></ul></ul><ul><ul><ul><li>NOTEPAD (Let op!) </li></ul></ul></ul><ul><ul><ul><li>Word(Pad) -> TEXT FILE </li></ul></ul></ul><ul><ul><li>TextPad en/of VIM </li></ul></ul><ul><ul><li>Scite: http://www.scintilla.org/SciTE.html </li></ul></ul>
  12. 14. <ul><li>To start the DOS editor type EDIT at the command prompt </li></ul><ul><li>Edit text editor: </li></ul><ul><ul><li>Command line interface text editor </li></ul></ul><ul><ul><li>Not a word processor </li></ul></ul><ul><ul><ul><li>Cannot format data in documents </li></ul></ul></ul><ul><ul><ul><li>Cannot manipulate environment </li></ul></ul></ul>The Command Prompt Text Editor
  13. 15. <ul><li>CD: Change Direcory ! </li></ul><ul><li>DIR myfile.* - show a listing of any file with the name myfile, ending in ANY extension </li></ul><ul><li>DIR *file.dat - show a listing of files beginning with any characters, ending in file and having a .dat extension </li></ul><ul><li>DIR *.* - show a listing of ALL files in current directory </li></ul>Some MSDOS commands
  14. 16. <ul><li>Program files: </li></ul><ul><ul><li>Named by programmer </li></ul></ul><ul><ul><li>Commonly have .COM, .EXE, or .BAT extensions </li></ul></ul><ul><ul><li>It is these that do not require the user to use the extension when executing. </li></ul></ul>Review of File-Naming Rules
  15. 17. <ul><li>Conceptually the syntax is: </li></ul><ul><li>COPY source destination </li></ul><ul><li>For example: </li></ul><ul><li>Copy myfile.doc yourfile.doc </li></ul><ul><li>This will make a duplicate of the source file, myfile.doc with the name yourfile.doc </li></ul>The COPY Command
  16. 18. <ul><li>DOSKEY: </li></ul><ul><ul><li>Recalls and edits command lines </li></ul></ul><ul><ul><li>Keeps command history </li></ul></ul><ul><ul><li>Used to write a macro-can record strokes to perform a series of operations, then copy the “history” to a file and execute it at a later date. </li></ul></ul>DOSKEY
  17. 19. <ul><li>Path: </li></ul><ul><ul><li>Route followed by OS to locate, save, and/or retrieve a file </li></ul></ul>Brief Introduction to Subdirectories—The Path
  18. 20. <ul><li>Probleem </li></ul><ul><ul><li>Ofwel kan je perl starten </li></ul></ul><ul><ul><li>Ofwel kan je het script niet vinden </li></ul></ul><ul><ul><li>Ofwel kan je een file nodig in het script niet vinden </li></ul></ul><ul><li>Oplossing </li></ul><ul><ul><li>Don’t panic ! </li></ul></ul><ul><ul><li>Gebruikt absolute path-namen </li></ul></ul><ul><ul><ul><li>D:Perlbinperl.exe D:tempTest.pl </li></ul></ul></ul><ul><ul><li>Let wel in je script met je de slash “escape” </li></ul></ul><ul><ul><ul><li>$filename = “d:Temppdb.fasta” </li></ul></ul></ul>Het absolute pad probleem …
  19. 21. <ul><li>Oplossingen (II) </li></ul><ul><ul><li>Kopieer al de files in dezelfde directory ! </li></ul></ul><ul><ul><li>Dus als je perl start vanuit D:Perlbin met perl kan je wel verwijzen naar D:Temptest.pl maar dan moet ook de absolute verwijzing gebruikt worden voor $filename ofwel moet je pdb.fasta copieren naar D:PerlBin </li></ul></ul><ul><ul><li>Pas het zoekpad aan zodat je perl overal kan starten </li></ul></ul><ul><ul><ul><li>Path (geeft het zoekpad) </li></ul></ul></ul><ul><ul><ul><li>Set Path (past het pad aan, Voorzichtig !). Gebruik de dos environment variabele %path% om een directory toe te voegen </li></ul></ul></ul><ul><ul><ul><li>Set path=%path%;d:Perlbin </li></ul></ul></ul><ul><ul><ul><li>(nadien kan de aanpassing controleren door “path” uit te voeren) </li></ul></ul></ul>Het absolute pad probleem …
  20. 22. <ul><li>Keyboard: </li></ul><ul><ul><li>Standard input device </li></ul></ul><ul><li>Screen: </li></ul><ul><ul><li>Standard output device </li></ul></ul>Redirection <ul><li>Redirection . . . </li></ul><ul><ul><li>changes output from monitor to somewhere else ( usually file or printer ). </li></ul></ul>
  21. 23. <ul><li>Redirecting output to a File </li></ul><ul><li>The command: dir > directfile.txt will send the output of the dir command to a text file NOT to the screen. There is NO response on the screen. You can then print the contents of the file. </li></ul>Redirection
  22. 24. Perl
  23. 25. <ul><li>Perl is mostly a free format language: add spaces, tabs or new lines wherever you want. </li></ul><ul><li>For clarity, it is recommended to write each statement in a separate line, and use indentation in nested structures. </li></ul><ul><li>Comments: Anything from the # sign to the end of the line is a comment. (There are no multi-line comments). </li></ul><ul><li>A perl program consists of all of the Perl statements of the file taken collectively as one big routine to execute. </li></ul>General Remarks
  24. 26. How does the real perl program look like: #!/usr/local/bin/perl print “Hello everyonen”; Mandatory first line (on UNIX) How to run it: 1. Save the text of your code as a file -- program.pl 2. Execute it: perl program.pl Hello everyone
  25. 27. Three Basic Data Types <ul><li>Scalars - $ </li></ul><ul><li>Arrays of scalars - @ </li></ul><ul><li>Associative arrays of scalers or Hashes - % </li></ul>
  26. 28. 2+2 = ? $a = 2; $b = 2; $c = $a + $b; $ - indicates a variable ; - ends every command = - assigns a value to a variable $c = 2 + 2; or $c = 2 * 2; or $c = 2 / 2; or $c = 2 ^ 4; or 2^4 <-> 2 4 =16 $c = 1.35 * 2 - 3 / (0.12 + 1); or
  27. 29. Ok, $c is 4. How do we know it? print “Hello n”; print command: $c = 4; print “$c”; “ ” - bracket output expression n - print a end-of-the-line character (equivalent to pressing ‘Enter’) print “Hello everyonen”; print “Hello” . ” everyone” . “n”; Strings concatenation: Expressions and strings together: print “2 + 2 = “ . (2+2) . ”n”; expression 2 + 2 = 4
  28. 30. Loops and cycles ( for statement): # Output all the numbers from 1 to 100 for ($n=1; $n<=100; $n+=1) { print “$n n”; } 1. Initialization : for ( $n=1 ; ; ) { … } 2. Increment : for ( ; ; $n+=1 ) { … } 3. Termination (do until the criteria is satisfied) : for ( ; $n<=100 ; ) { … } 4. Body of the loop - command inside curly brackets : for ( ; ; ) { … }
  29. 31. FOR & IF -- all the even numbers from 1 to 100: for ($n=1; $n<=100; $n+=1) { if (($n % 2) == 0) { print “$n”; } } Note: $a % $b -- Modulus -- Remainder when $a is divided by $b
  30. 32. Two brief diversions (warnings & strict) <ul><li>Use warnings </li></ul><ul><li>strict – forces you to ‘declare’ a variable the first time you use it. </li></ul><ul><ul><li>usage: use strict; (somewhere near the top of your script) </li></ul></ul><ul><li>declare variables with ‘ my ’ </li></ul><ul><ul><li>usage: my $variable; </li></ul></ul><ul><ul><li>or: my $variable = ‘value’; </li></ul></ul><ul><li>my sets the ‘scope’ of the variable. Variable exists only within the current block of code </li></ul><ul><li>use strict and my both help you to debug errors, and help prevent mistakes. </li></ul>
  31. 33. Grabbing user input <ul><li>#!... </li></ul><ul><li>Use strict; </li></ul><ul><li>Print “Enter a greeting: “; </li></ul><ul><li>My $greeting = <>; </li></ul><ul><li>Print $greeting; </li></ul><ul><li><> operator, also called the “diamond operator”. This accesses what the usr types at the keyboard and brings it into the program for use </li></ul>
  32. 34. Voorbeeldprogramma: DNA-invoer.pl <ul><li>#!e:perlbinperl.exe –w </li></ul><ul><li>use strict; </li></ul><ul><li>print &quot;Voer in DNA in:n&quot;; </li></ul><ul><li>while (my $dna=<>) { </li></ul><ul><li>chomp($dna); </li></ul><ul><li>my $l = length($dna); </li></ul><ul><li>print &quot;DNA: &quot;.$dna.&quot;n&quot;; </li></ul><ul><li>$dna =~ s/[^atcgATCG]//g; </li></ul><ul><li>my $l2 = length($dna); </li></ul><ul><li>if ($l2 < $l) { </li></ul><ul><ul><li>print &quot;removed &quot;.($l-$l2).&quot; illegal charactersn&quot;; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>else </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>print &quot;OKn&quot;; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>print &quot;Lengte van het DNA: &quot;.$l2.&quot;n&quot;; </li></ul><ul><li>} </li></ul>
  33. 35. Unary Arithmetic Operators eg. Autoincrement ++ <ul><li>If you place one of the auto operators before the variable, it is known as a pre-incremented (pre-decremented) variable. Its value will be changed before it is referenced. If it is placed after the variable, it is known as a post-incremented (post-decremented) variable and its value is changed after it is used </li></ul><ul><li>For example: </li></ul><ul><li>$a = 5; # $a is assigned 5 </li></ul><ul><li>$b = ++$a; # $b is assigned the incremented value of $a, 6 </li></ul><ul><li>$c = $a--; # $c is assigned 6, then $a is decremented to 5 </li></ul><ul><li>#!e:perlbinperl.exe </li></ul><ul><li>$getal1 = 5; </li></ul><ul><li>print $getal1.&quot;n&quot;; </li></ul><ul><li>print $getal1++.&quot;n&quot;; </li></ul><ul><li>print ++$getal1.&quot;n&quot;; </li></ul>
  34. 36. Logical and Comparison operators <ul><li>Equal (True if $a is equal to $b) </li></ul><ul><ul><li>Numeric: == </li></ul></ul><ul><ul><li>String: eq </li></ul></ul><ul><li>And: && </li></ul><ul><li>Or: || </li></ul>
  35. 37. Schuifoperatoren <ul><li>Schuifoperatoren zijn handing voor manipulaties op bit-niveau: bv 40 </li></ul><ul><li>256 128 64 32 16 8 4 2 1 </li></ul><ul><li> 0 0 0 1 0 1 0 0 0 </li></ul><ul><li> 0 0 0 1 0 1 0 00 </li></ul><ul><li>000 1 0 1 0 0 0 </li></ul><ul><li>Program </li></ul><ul><li>$getal1 = 40; </li></ul><ul><li>print &quot;/4 &quot;.($getal1 >> 2).&quot;n&quot;; </li></ul><ul><li>print &quot;*8 &quot;.($getal1 << 3).&quot;n&quot;; </li></ul>>>2 <<3
  36. 38. Text Processing Functions <ul><li>The substr function </li></ul><ul><li>Definition </li></ul><ul><li>The substr function extracts a substring out of a string and returns it. The function receives 3 arguments: a string value, a position on the string (starting to count from 0) and a length. </li></ul><ul><li>Example: </li></ul><ul><li>$a = &quot;university&quot;; </li></ul><ul><li>$k = substr ( $a, 3, 5 ) ; </li></ul><ul><li>$k is now &quot;versi&quot; $a remains unchanged. </li></ul><ul><li>If length is omitted, everything to the end of the string is returned. </li></ul>
  37. 39. Random <ul><li>#!c:perlbinperl.exe -w </li></ul><ul><li>#srand(time|$$); </li></ul><ul><li>$x = rand(1); </li></ul><ul><li>srand </li></ul><ul><ul><li>The default seed for srand , which used to be time , has been changed. Now it's a heady mix of difficult-to-predict system-dependent values, which should be sufficient for most everyday purposes. Previous to version 5.004, calling rand without first calling srand would yield the same sequence of random numbers on most or all machines. Now, when perl sees that you're calling rand and haven't yet called srand , it calls srand with the default seed. You should still call srand manually if your code might ever be run on a pre-5.004 system, of course, or if you want a seed other than the default </li></ul></ul>
  38. 40. <ul><li>Oefening hoe goed zijn de random nummers ? </li></ul><ul><li>Als ze goed zijn kan je er Pi mee berekenen … </li></ul><ul><li>Een goede random generator is belangrijk voor goede randomsequenties die we nadien kunnen gebruiken in simulaties </li></ul>
  39. 41. Bereken Pi aan de hand van twee random getallen 1 x y
  40. 42. Textpad <ul><li>Debugging </li></ul><ul><ul><li>Tools </li></ul></ul><ul><li>Syntax Highlighting </li></ul><ul><ul><li>Document Class </li></ul></ul>

×