370 likes | 542 Views
Computer Programming for Biologists. Oct 30 th – Dec 11 th , 2014 Karsten Hokamp ( kahokamp@tcd.ie ) http://bioinf.gen.tcd.ie/GE3M25/programming Fill out survey, please!. Computer Programming for Biologists. Organisation. Classes: Lectures i nterspersed with
E N D
Computer Programming for Biologists Oct 30th – Dec 11th, 2014 Karsten Hokamp (kahokamp@tcd.ie) http://bioinf.gen.tcd.ie/GE3M25/programming Fill out survey, please!
Computer Programming for Biologists Organisation Classes: Lectures interspersed with excercises and practicals Exam: 2-hour exam during last double lecture (11th Dec)
Class I: Overview and Motivation Questions • What is computer programming? • Why do we need computer programming? • How do we program computers?
Class I: Overview and Motivation What is and what is not computer programming? • Write shell scripts • Write programs • Write one-liners • Automate tasks • E-mailing • Web browsing • Run programs
Class I: Overview and Motivation The greater context: Bioinformatics Increase of data led to greater need for computational methods Informatics (computer science) + Biology = Bioinformatics also: Computational Biology
Class I: Overview and Motivation Why do we need computer programming? • Automate tasks • Modify existing programs • Combine programs • Increase control • New ‘laboratory’ skill
Class I: Overview and Motivation Use of programming • Scientific research • Efficiency • Not only for biological data • Data (re-)formatting and extraction • File organization, backups, etc.
Class I: Overview and Motivation How do we program computers? • Pick a programming language • Learn the basics • Start writing programs • Practice and improve
Practical! Example programming with Scratch http://scratch.mit.edu
Class I: Overview and Motivation Programming languages (examples) Faster development, slower execution Slower development, faster execution
Class I: Overview and Motivation Advantages of Perl • Quick development cycle • Easy to learn • Wide-spread use • Great for text processing • Many bioinformatics extensions
shell prompt Class I: Overview and Motivation The command line • Access through console or terminal • Use of keyboard instead of mouse
Next Unix Basics
Unix File Hierarchy bin etc data Users lib root (/) sbin sw tmp usr var
User-related folders bin core programs etc data Users home directories lib root (/) sbin sw tmp temporary storage space user programs and packages usr var
Home directories bin user1 etc data user2 Users user3 lib root (/) sbin user4 sw tmp usr var
Login location bin user1 etc data user2 Users user3 lib root (/) prompt sbin user4 sw user2 $ tmp usr var
Print working directory (pwd) bin user1 etc data user2 Users user3 lib root (/) command sbin user4 sw user2 $ pwd tmp usr var
Print working directory (pwd) bin user1 etc data user2 Users user3 lib root (/) output: full path sbin user4 sw user2 $ user2 $ pwd pwd tmp user2 $ /home/user2 /Users/user2 usr var separator
Change directory bin user1 etc Desktop data user2 Documents Users user3 lib command root (/) sbin argument user4 sw user2 $ change to new location in file hierarchy cd Desktop tmp pwd user2 $ usr /Users/user2/Desktop var
cd go to home directory cd - go to previous directory cd .. go to upper directory Change directories bin user1 etc Desktop data user2 Documents Users user3 lib root (/) sbin user4 sw tmp usr var
Path specifications bin user1 etc Desktop data user2 Documents Users user3 lib root (/) sbin user4 sw tmp usr var
Create new directory bin user1 etc Desktop data user2 Users user3 lib root (/) sbin user4 sw user2 $ mkdir class1 user2 $ pwd user2 $ mkdir class1 tmp user2$ /home/user2 user2 $ mkdir ‘test dir’ usr var
Create new directory bin class1 user1 etc Desktop test dir data user2 Users user3 lib root (/) sbin user4 sw Two new directories (or folders) created tmp usr var
. (single dot) current directory .. (two dots) upper directory ~ (tilde) home directory Special directories bin class1 user1 etc Desktop test dir data user2 Users user3 lib root (/) sbin user4 sw tmp usr var
cd change directory (defaults to home directory) ls listing of directory (defaults to current directory) mkdir create a directory mv move or rename file or directory rm remove file rmdir remove empty directory Other commands
Find more information! Manual pages for Unix tools: man ls ls –h ls –help ls --help EMBnet Quick Guides: • A Quick Guide to UNIX • A Quick Guide to PERL • A Quick Guide to PERL Regular Expressions http://www.embnet.org/embnet-quickguides
Practical! A few exercises to get you familiar with the command line and the Unix environment…. Go to: http://bioinf.gen.tcd.ie/GE3M25/programming/class1 and click on the ‘UNIX’ topic. I hear and I forget. I see and I remember. I do and I understand. Confucius, Chinese philosopher & reformer (551 BC - 479 BC)
Class I: First Program Perl example # My first Perl program # define the message $text = "Hello World!\n"; # print message to screen print $text; exit;
Class I: First Program Perl example # My first Perl program # define the message $text="Hello World!\n"; # print message to screen print$text; exit; comments variable assignment string special character built-in function Statements end with semicolon!
Class I: First Program Running the script • Save script to a file (e.g. hello.pl) • Pass on to interpreter: $ perl hello.pl Hello World! $
Class I: First Program Perl flow • Shell calls interpreter (perl) • Passes on code (script) • Syntax check • Translation into operational code • Execution
Class I: First Program Perl errors What to do when things go wrong, e.g. • Take a good look at the error message • Check syntax syntax error at hello.pl line 7, near "print" Execution of hello.pl aborted due to compilation errors.
Practical! A few exercises to get you started with writing and running Perl scripts …. Go to: http://bioinf.gen.tcd.ie/GE3M25/programming/class1 and click on the ‘Editor’ topic.
Perl on a Windows PC • Perl Installations • CygWin (http://www.cygwin.com) Unix environment for Windows, includes Perl • ActiveState Perl http://www.activestate.com/activeperl/downloads any version 5.x c) Strawberry Perl: (http://strawberryperl.com) Perl Source and Binaries: http://www.perl.org/get.html
Computer Programming for Biologists References R.L. Schwartz, Learning Perl, O’Reilly James Tisdall, Beginning Perl for Bioinformatics, O’Reilly Free online books: http://www.perl.org/books/library.html
Next week: • A short online quiz • Introduction of the course project • More Perl