Programming and Perl for Bioinformatics Part I. A Taste of Perl: print a message perltaste.pl: Greet the entire world. #!/usr/bin/perl #greet the entire.

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

1/12 Steven Leung Very Basic Perl Tricks A Few Ground Rules File I/O and Formatting Operators, Flow Control Statements Regular Expression Subroutines Hash.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
PL/SQL.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
R&D Group 开发 以人为本 交流 创造价值 Liqi Gao Text Operations.
Practical Extraction & Report Language PERL Joseph Beltran.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
2440: 211 Interactive Web Programming Expressions & Operators.
Introduction To Perl Susan Lukose. Introduction to Perl Practical Extraction and Report Language Easy to learn and use.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Perl By Gabe and Ted. History Perl was created by Larry Wall while working at NASA’s Jet Propulsion Labs. Larry Wall also created patch which is in widespread.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Perl Practical(?)‏ Extraction and Report Language.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Bioinformatics 生物信息学理论和实践 唐继军
Introduction to Perl Giorgos Georgakilas Graduated from C.E.I.D.Graduated from C.E.I.D. M.Sc. degree in ITMBM.Sc. degree in ITMB Ph.D. student in DIANA-LabPh.D.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
1 Introduction to Perl CIS*2450 Advanced Programming Techniques.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
CPTG286K Programming - Perl Chapter 4: Control Structures.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
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.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Interpolation Variable Interpolation, Backslash Interpolation.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
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.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
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.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
>> Fundamental Concepts in PHP
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Perl for Bioinformatics
Arrays, For loop While loop Do while loop
Control Structures: if Conditional
Control Structures: for & while Loops
The Selection Structure
INTRODUCTION to PERL PART 1.
Presentation transcript:

Programming and Perl for Bioinformatics Part I

A Taste of Perl: print a message perltaste.pl: Greet the entire world. #!/usr/bin/perl #greet the entire world $x = 6e9; print “Hello world!\n”; print “All $x of you!\n”; } - function calls (output statements) - command interpretation header - variable assignment statement - a comment

Basic Syntax and Data Types whitespace doesn’t matter to Perl. One can write all statements on one line whitespace doesn’t matter to Perl. One can write all statements on one line All Perl statements end in a semicolon ; just like C All Perl statements end in a semicolon ; just like C Comments begin with ‘#’ and Perl ignores everything after the # until end of line. Comments begin with ‘#’ and Perl ignores everything after the # until end of line. Example: #this is a comment Example: #this is a comment Perl has three basic data types: Perl has three basic data types: scalar scalar array (list) array (list) associative array (hash) associative array (hash)

Scalars Scalar variables begin with ‘$’ followed by an identifier Scalar variables begin with ‘$’ followed by an identifier Example: $this_is_a_scalar; Example: $this_is_a_scalar; An identifier is composed of upper or lower case letters, numbers, and underscore '_'. Identifiers are case sensitive (like all of Perl) An identifier is composed of upper or lower case letters, numbers, and underscore '_'. Identifiers are case sensitive (like all of Perl) $progname = “first_perl”; $progname = “first_perl”; $numOfStudents = 4; $numOfStudents = 4; = sets the content of $progname to be the string “first_perl” & $numOfStudents to be the integer 4 = sets the content of $progname to be the string “first_perl” & $numOfStudents to be the integer 4

Scalar Values Numerical Values Numerical Values integer:5, “3”, 0, -307 integer:5, “3”, 0, -307 floating point: 6.2e9, floating point: 6.2e9, hexadecimal/octal:0xd4f, 0477 hexadecimal/octal:0xd4f, 0477 Binary: 0b Binary: 0b NOTE: all numerical values stored as floating-point numbers (“double” precision)

Do the Math Mathematical functions work pretty much as you would expect: Mathematical functions work pretty much as you would expect:4+76* /122/(3-5) Example Example#!/usr/bin/perl print "4+5\n"; print 4+5, "\n"; print "4+5=", 4+5, "\n"; $myNumber = 88; Note: use commas to separate multiple items in a print statement Note: use commas to separate multiple items in a print statement What will be the output? =9

Scalar Values String values String values Example: Example: $day = "Monday "; print "Happy Monday!\n"; print "Happy $day!\n"; print 'Happy Monday!\n'; print 'Happy $day!\n'; Double-quoted: interpolates (replaces variable name/control character with it’s value) Double-quoted: interpolates (replaces variable name/control character with it’s value) Single-quoted: no interpolation done (as-is) Single-quoted: no interpolation done (as-is) Happy Monday! Happy Monday!\n Happy Monday! Happy $day!\n What will be the output?

String Manipulation Concatenation $dna1 = “ACTGCGTAGC”; $dna2 = “CTTGCTAT”; juxtapose in a string assignment or print statement juxtapose in a string assignment or print statement $new_dna = “$dna1$dna2”; Use the concatenation operator ‘.’ Use the concatenation operator ‘.’ $new_dna = $dna1 $dna2; $new_dna = $dna1. $dna2;Substring $dna = “ACTGCGTAGC”; $exon1 = substr($dna,2,5); 02 # TGCGT Length of the substring

Substitution DNA transcription: T  U Substitution operator s/// : $dna = “GATTACATACACTGTTCA”; $rna = $dna; $rna =~ s/T/U/g ; #“GAUUACAUACACUGUUCA” =~ is a binding operator indicating to exam the contents of $ rna for a match pattern Ex: Start with $dna =“gaTtACataCACTgttca”; and do the same as above. What will be the output?

Example transcribe.pl: transcribe.pl: $dna ="gaTtACataCACTgttca"; $rna = $dna; $rna =~ s/T/U/g; print "DNA: $dna\n"; print "RNA: $rna\n"; Does it do what you expect? If not, why not? Patterns in substitution are case-sensitive! What can we do? Convert all letters to upper/lower case (preferred when possible) If we want to retain mixed case, use transliteration/translation operator tr/// $rna =~ tr/tT/uU/; #replace all t by u, all T by U

Case conversion $string = “acCGtGcaTGc”; Upper case: $dna = uc($string);# “ACCGTGCATGC” or $dna = uc $string; or $dna = uc $string; or $dna = “\U$string”; or $dna = “\U$string”; Lower case: $dna = lc($string);# “accgtgcatgc” or $dna = “\L$string”; or $dna = “\L$string”; Sentence case: $dna = ucfirst($string) # “Accgtgcatgc” or $dna = “\u\L$string”; or $dna = “\u\L$string”;

Reverse Complement 5’- A C G T C T A G C.... G C A T -3’ 3’- T G C A G A T C G.... C G T A -5’ Reverse: reverses a string Reverse: reverses a string $string = "ACGTCTAGC"; $string = reverse($string); "CGATCTGCA“ Complementation: use transliteration operator Complementation: use transliteration operator $string =~ tr/ACGT/TGCA/;

More on String Manipulation String length: length($dna)Index: # index STR,SUBSTR,POSITION index($strand, $primer, 2) optional

Flow Control Conditional Statements parts of code executed depending on truth value of a logical statement parts of code executed depending on truth value of a logical statement “truth” (logical) values in Perl: false = {0, 0.0, 0e0, “”, undef}, default “” true = anything else, default 1 ($a, $b) = (75, 83); if ( $a < $b ) { $a = $b; print “Now a = b!\n”; } if ( $a > $b ) { print “Yes, a > b!\n” } # Compact

Comparison Operators ComparisonStringNumber Equalityeq== Inequalityne!= Greater than gt> Greater than or equal to ge>= Less than lt< Less than or equal to return 1/null le<= Comparison: Returns -1, 0, 1 cmp<=>

Logical Operators OperationComputerese English version AND&&and OR||or NOT!not

if/else/elsif allows for multiple branching/outcomes allows for multiple branching/outcomes $a = rand(); if ( $a <0.25 ) { print “A”; } elsif ($a <0.50 ) { print “C”; } elsif ( $a < 0.75 ) { print “G”; } else { print “T”; }

Conditional Loops while ( statement ) { commands … } repeats commands until statement is no longer true repeats commands until statement is no longer true do { commands } while ( statement ); same as while, except commands executed as least once same as while, except commands executed as least once NOTE the ‘;’ after the while statement!! NOTE the ‘;’ after the while statement!! Short-circuiting commands: next and last next; #jumps to end, do next iteration next; #jumps to end, do next iteration last; #jumps out of the loop completely last; #jumps out of the loop completely

while Example: while ($alive) { if ($needs_nutrients) { print “Cell needs nutrients\n”; }} Any problem?

for and foreach loops Execute a code loop a specified number of times, or for a specified list of values Execute a code loop a specified number of times, or for a specified list of values for and foreach are identical: use whichever you want for and foreach are identical: use whichever you want Incremental loop (“C style”): for ( $i=0 ; $i < 50 ; $i++ ) { $x = $i*$i; $x = $i*$i; print "$i squared is $x.\n"; print "$i squared is $x.\n";} Loop over list (“foreach” loop): foreach $name ( "Billy", "Bob", "Edwina" ) { foreach $name ( "Billy", "Bob", "Edwina" ) { print "$name is my friend.\n"; print "$name is my friend.\n";}

Basic Data Types Perl has three basic data types: Perl has three basic data types: scalar scalar array (list) array (list) associative array (hash) associative array (hash)