96-Summer 生物資訊程式設計實習 ( 二 ) Bioinformatics with Perl 8/13~8/22 蘇中才 8/24~8/29 張天豪 8/31 曾宇鳯.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
The Basics Getting started with Perl for Bioinformatics programming.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Perl Functions Software Tools. Slide 2 Defining a Function l A user-defined function or subroutine is defined in Perl as follows: sub subname{ statement1;
CSC3530 Software Technology Tutorial Two PERL Basics.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Practical Extraction & Report Language PERL Joseph Beltran.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 7: One More Loop Problem, Generating “random” values, Midterm Review.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Programming Languages Meeting 14 December 9/10, 2014.
Chapter 3 Flow Control By C. Shing ITEC Dept Radford University.
Introduction to Unix – CS 21
Introduction to Programming
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Perl Basics. sh-bang !!!! Every perl program starts with a sh-bang line #!/usr/bin/perl # hello.pl printf “Hello, world!\n”; printf STDOUT “Hello, world!\n”;
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
CSE1301 Computer Programming: Lecture 6 Input/Output.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
BINF 634 Fall LECTURE061 Outline Lab 1 (Quiz 3) Solution Program 2 Scoping Algorithm efficiency Sorting Hashes Review for midterm Quiz 4 Outline.
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
The Scripting Programming Language
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
CPTG286K Programming - Perl Chapter 9: Misc. Control Structures Chapter 10: Filehandles & File tests.
96-Summer 生物資訊程式設計實習 ( 二 ) Bioinformatics with Perl 8/13~8/22 蘇中才 8/24~8/29 張天豪 8/31 曾宇鳯.
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
COMP234-Perl Variables, Literals Context, Operators Command Line Input Regex Program template.
Formatted Input and Output
A bit of C programming Lecture 3 Uli Raich.
ECE Application Programming
Programming in C Input / Output.
Input and Output Lecture 4.
CSI 121 Structured Programming Language Lecture 7: Input/Output
Programming in Perl Introduction
Writing Portable and Robust Firmware in C
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Your questions from last session
Programming Languages
Programming in C Input / Output.
By C. Shing ITEC Dept Radford University
The structure of programming
Presentation transcript:

96-Summer 生物資訊程式設計實習 ( 二 ) Bioinformatics with Perl 8/13~8/22 蘇中才 8/24~8/29 張天豪 8/31 曾宇鳯

Schedule DateTimeSubjectSpeak er 8/13 一 13:30~17:30Perl Basics 蘇中才 8/15 三 13:30~17:30Programming Basics 蘇中才 8/17 五 13:30~17:30Regular expression 蘇中才 8/20 一 13:30~17:30Retrieving Data from Protein Sequence Database 蘇中才 8/22 三 13:30~17:30Perl combines with Genbank, BLAST 蘇中才 8/24 五 13:30~17:30PDB database and structure files 張天豪 8/27 一 8:30~12:30Extracting ATOM information 張天豪 8/27 一 13:30~17:30Mapping of Protein Sequence IDs and Structure IDs 張天豪 8/31 五 13:30~17:30Final and Examination 曾宇鳳

Programming Basic Subroutine

#!/usr/bin/perl -w # hello1.pl : say hello sub hello { print "Hello\n"; } &hello; &hello();

Quiz – the identical function name ? #!/usr/bin/perl -w sub hello { print "Hello\n"; } sub hello { print "HELLO\n"; } &hello;

Subroutine – with a counter #!/usr/bin/perl -w # hello2.pl : say hello with a counter my $counter=0; sub hello { $counter++; print "Hello ($counter)\n"; } &hello; &hello();

Subroutine - parameters #!/usr/bin/perl -w # hello3.pl : say hello to someone with a counter my $counter=0; sub hello { my $name = $_[0]; #all arguments are stored $counter++; print "Hello,$name ($counter)\n"; } &hello( 'Wang’ ); &hello( "Kuo” ); &hello( "Tsao” );

Subroutine – value return #!/usr/bin/perl -w # hello4.pl : value return my $counter=0; sub hello { my $name = $_[0]; # all parameters are stored $counter++; return "Hello,$name ($counter)\n"; } my $ret = &hello('Wang'); print "$ret"; $ret = &hello("Kuo"); print $ret; $ret = &hello("Tsao"); print $ret;

Quiz – what is $ret ? #!/usr/bin/perl -w sub hello { print "Hello\n"; } my $ret = &hello; print “\$ret = $ret\n”;

Variable – global/local #!/usr/bin/perl -w # variable.pl : global/local variable my $a = 0; sub max { my ($a, $b); ($a, $b) print "\$a in &max = $a\n"; if ($a > $b) { $a; } else { $b; } print "\$a before calling &max = $a\n"; $a = &max(3,5); print "\$a after calling &max = $a\n";

Maximum #!/usr/bin/perl -w # max.pl : get the largest number among a list of numbers my $maximum = &max(1, 10, 5, 7, 4); print "the largest number is $maximum\n"; sub max { my $max_number = while ($number = { if ($number > $max_number) { $max_number = $number; } $max_number; }

Return #!/usr/bin/perl # return.pl : use 'return' to stop the subroutine and assign the return value = qw / Wang Kuo Tsao Keng Lo Huang/; my $result = if ($result eq -1) { print "Tsao isn't a pitcher\n"; } else { $result++; print "Tsao is the $result-th pitcher\n"; } sub which_one_is { my foreach $idx (0..$#list) { if ($name eq $list[$idx]) { return $idx; } -1; # $name can't be found }

declaration of variable #!/usr/bin/perl -w $counter = 1; sub hello { print "$counter\n"; } sub a { local $counter = 2; &hello; } sub b { my $counter = 3; &hello; } sub c { $counter = 4; &hello; } &hello; &a; &hello; &b; &hello; &c; &hello;

strict #!/usr/bin/perl -w # strict.pl : use strict to enhance the error checking power of compiler use strict; $taipei101 = 509.2; print "Taipei 101 has $taipei1O1 meter\n";

Programming Basic Control statement

if unless ?: while until for foreach

Control statement - if #!/usr/bin/perl -w # if1.pl : if statement my $proteinA = 300; #protein volume my $proteinB = 200; if ($proteinA == $proteinB) { print "Protein A is the same as Protein B\n"; } else { print "Protein A isn't the same as Protein B\n"; } if (true) { # true } else { # false }

Control statement - if #!/usr/bin/perl -w # if2.pl : if statement my $proteinA = 300; #protein volume my $proteinB = 200; if ($proteinA > $proteinB) { print "Protein A is larger than Protein B\n"; } elsif ($proteinA < $proteinB) { print "Protein A is smaller than Protein B\n"; } else { print "Protein A is the same as Protein B\n"; } if (...) {... } elsif (...) {... } else {... }

Control statement - if #!/usr/bin/perl -w # if3.pl : if statement my $proteinA = 300; #protein volume my $proteinB = 200; print "A is the same as B\n" if ($proteinA == $proteinB);... if (true);

Control statement - unless #!/usr/bin/perl -w # unless.pl : unless statement my $proteinA = 300; #protein volume my $proteinB = 200; unless ($proteinA == $proteinB) { print "Protein A isn't the same as Protein B\n"; } else { print "Protein A is the same as Protein B\n"; } unless (true) { # false } else { # true }

Control statement - ?: #!/usr/bin/perl -w # if4.pl : if statement my $type = "DNA"; # "DNA" or "RNA" my $bp; if ($type eq "DNA") { $bp = "ATCG"; } else { $bp = "AUCG"; } print "$type : $bp\n"; $bp = ($type eq "DNA") ? "ATCG" : "AUCG"; print "$type : $bp\n";

Control statement - while #!/usr/bin/perl -w # while1.pl : count 1 to 10 with while statement my $sum = 0; my $current = 1; while ($current <= 10) { $sum = $sum + $current; $current++; } print "The summary from 1 to 10 is $sum\n";

Control statement - while #!/usr/bin/perl -w # while2.pl : count 1 to 10 with while statement my $sum = 0; my $current = 1; do { $sum = $sum + $current; $current++; } while ($current <= 10); print "The summary from 1 to 10 is $sum\n";

Control statement - while #!/usr/bin/perl -w # while3.pl : count 1 to 10 with while statement my $sum = 0; my $current = 1; $sum = $sum + $current++ while ($current <= 10); print "The summary from 1 to 10 is $sum\n";

Control statement - while #!/usr/bin/perl -w # while4.pl : count 1 to 10 with while statement my $sum = 0; my $current = 1; while ($current <= 10) { $sum = $sum + $current; } continue { $current++; } print "The summary from 1 to 10 is $sum\n";

Control statement - until #!/usr/bin/perl -w # until.pl : count 1 to 10 with until statement my $sum = 0; my $current = 1; until ($current > 10) { $sum = $sum + $current; $current++; } print "The summary from 1 to 10 is $sum\n";

Control statement - for #!/usr/bin/perl -w # for1.pl : count 1 to 10 with for statement my $sum = 0; for(my $current=1;$current<=10;$current++) { $sum = $sum + $current; } print "The summary from 1 to 10 is $sum\n"; for ( initialise; test; increment ) { statement(s); }

Control statement - for #!/usr/bin/perl -w # for2.pl : show each pitcher by for statement = qw / Wang Kuo Tsao Keng Lo Huang/; for(my $idx=0;$idx<=$#names;$idx++) { print "$idx : $names[$idx]\n"; }

Control statement - foreach #!/usr/bin/perl -w # foreach.pl : show each pitcher by foreach statement = qw / Wang Kuo Tsao Keng Lo Huang/; my $idx = 0; foreach $name { print "$idx : $name\n"; $idx++; }

Control statement - foreach #!/usr/bin/perl -w # for3.pl : show each pitcher by foreach statement = qw / Wang Kuo Tsao Keng Lo Huang/; my $idx = 0; for $name { print "$idx : $name\n"; $idx++; }

Infinite control statement #!/usr/bin/perl -w # infinite.pl : infinite loop, and Ctrl+C to stop it for(;;) { print "for\n"; } while (1) { print "while\n"; } until (0) { print "until\n"; }

Loop control - last #!/usr/bin/perl -w # last.pl : stop infinite loop by last while(1) { if ($counter++ >= 10) { last; } print "while($counter)\n"; } #################################### $counter=0; while ($counter++ < 10) { print "while($counter)\n"; }

Loop control - next #!/usr/bin/perl -w # next.pl : skip loop control by next $counter=0; while ($counter++ < 10) { if ($counter == 5) { next; } print "while($counter)\n"; }

Loop control - redo #!/usr/bin/perl -w # redo.pl : redo loop control by redo $counter=0; while ($counter++ < 10) { if ($counter == 5) { $counter++; redo; } print "while($counter)\n"; }

Exercise Control statement

Exercise 1+2+…+1000 = ?  Using “while”  Using “until”  Using “for”  Using “foreach”

Programming Basic Logical operator

and : && or : || not : ! Examples  while (($a > 10) && ($a % 2 == 0)) { …}  If (($a > 10) || ($a % 2 == 0)) { … }  If (! defined($a)) { … }

Logical operator – and/or/not #!/usr/bin/perl -w # logical.pl : if statement my $proteinA = 300; #protein volume my $proteinB = 300; my $proteinC; if (($proteinA > 200)&&($proteinA eq $proteinB)) { print "Protein A is larger than 200 and the same as Protein B\n"; } if (($proteinA > 400)||($proteinA eq $proteinB)) { print "Protein A is larger than 400 or the same as Protein B\n"; } if (! defined($proteinC)) { print "Protein C isn't declared\n"; }

Programming Basic INPUT/OUTPUT

Standard Input/Output Input  STDIN OUTPUT  STDOUT ERROR  STDERR Don’t need to open or close it

Standard Input - #! /usr/bin/perl -w # getlines1.pl : like the Unix-command 'cat' while ( $line = ) { print $line; }./getline1.pl < logical.pl cat logical.pl |./getlines1.pl -

Diamond - <> #! /usr/bin/perl -w # getlines2.pl : like the Unix-command 'cat' while ( $line = <> ) { print $line; }./getline2.pl logical.pl or./getline2.pl < logical.pl

$_ #! /usr/bin/perl -w # getlines3.pl : like the Unix-command 'cat' while ( <> ) { print $_; }./getline3.pl logical.pl while.pl redo.pl or./getline3.pl *.pl

Invocation argument #! /usr/bin/perl -w # getlines4.pl : like the Unix-command 'cat' foreach { print "[$_]\n"; } while ( <> ) { print $_; }./getline4.pl logical.pl while.pl redo.pl Or./getline4.pl *.pl

Standard Input/Output #!/usr/bin/perl -w # stdin.pl : read information from STDIN, and output them into STDOUT and STDERR while ($line = ) { if ($line eq "ERROR\n") { print STDERR “STDERR:$line"; } elsif ($line eq "QUIT\n") { last; } else { print STDOUT “STDOUT:$line"; }

Standard Input/Output #!/usr/bin/perl -w # chomp.pl : read information from STDIN, and output them into STDOUT and STDERR while ($line = ) { chomp($line); if ($line eq "ERROR") { print STDERR "$line\n"; } elsif ($line eq "QUIT") { last; } else { print STDOUT "$line\n"; }

parameters of printf specifierOutputExample c Character a d or i Signed decimal integer 392 e Scientific notation (mantise/exponent) using e character e+2 E Scientific notation (mantise/exponent) using E character E+2 f Decimal floating point g Use the shorter of %e or %f G Use the shorter of %E or %f o Signed octal 610 s String of characters sample u Unsigned decimal integer 7235 x Unsigned hexadecimal integer 7fa X Unsigned hexadecimal integer (capital letters) 7FA p Pointer address B800:0000 n Nothing printed. The argument must be a pointer to a signed int, where the number of characters written so far is stored. % A % followed by another % character will write % to stdout.

printf #! /usr/bin/perl -w # printf.pl : user-defined type for variable output my $var1 = 1; my $var2 = 1.2; my $var3 = 3.2E10; my $var4 = 65; my $var5 = 'ABC'; print ("$var1 $var2 $var3 $var4 $var5\n"); printf("%d %f %e %c %s\n",$var1, $var2, $var3, $var4, $var5); printf("[%5d] [%5.2f] [%10.2e] [%5c] [%5s]\n",$var1, $var2, $var3, $var4, $var5); printf("[%-5d] [%-5.2f] [%-10.2e] [%-5c] [%- 5s]\n",$var1, $var2, $var3, $var4, $var5);

printf - output ABC e+10 A ABC [ 1] [ 1.20] [ 3.20e+10] [ A] [ ABC]

Exercise Control statement

Exercise #! /usr/bin/perl -w # printf.pl : user-defined type for variable output my $var1 = 1; my $var2 = 1.2; my $var3 = 3.2E10; my $var4 = 65; my $var5 = 'ABC'; printf("%s %s %s %s %s\n",$var1, $var2, $var3, $var4, $var5); printf("%f %f %f %f %f\n",$var1, $var2, $var3, $var4, $var5);

An example for CGI : env.pl #!/usr/bin/perl print "Content-type: text/html\n\n"; print "\n"; foreach (keys %ENV) { print $_." ===> ".$ENV{$_}." \n"; } print "\n";

env.pl procedures  mkdir ~/public_html  cd ~/public_html  mkdir cgi-bin  cd cgi-bin  cp.  chmod +x ~/ Results 