Where to get Perl ? www.perl.com / www.perl.org Unix/Linux/Solaris Unix/Linux/Solaris Interpreter (called “perl”) comes pre-installed usually Interpreter.

Slides:



Advertisements
Similar presentations
A primer on Perl programming First structures (with examples)
Advertisements

Perl Practical Extration and Reporting Language An Introduction by Shwen Ho.
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
A Guide to Unix Using Linux Fourth Edition
The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
● Perl reference
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
4.1 Reading and writing files. 4.2 Open a file for reading, and link it to a filehandle: open(IN, "
Perl for Bioinformatics Lecture 4. Variables - review A variable name starts with a $ It contains a number or a text string Use my to define a variable.
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.
5.1 Previously on... PERL course (let ’ s practice some more loops)
Practical Extraction & Report Language Picture taken from
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
Perl File I/O Software Tools. Slide 2 Filehandles l A filehandle is the name for an I/O connection between your Perl program and the outside world. STDIN.
Getting Started with Perl (and Excel) Biophysics 101 September 17, 2003 Griffin Weber (With material from Jon Radoff and Ivan Ovcharenko)
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
Guide To UNIX Using Linux Third Edition
2ex.1 Lists and Arrays. 2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Python programs How can I run a program? Input and output.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Practical Extraction & Report Language PERL Joseph Beltran.
Computer Programming for Biologists Class 7 Nov 27 th, 2014 Karsten Hokamp
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Computer Programming for Biologists Class 8 Nov 28 th, 2014 Karsten Hokamp
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.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Why? – Examples Speaking Computer-ise – How – What – Environment (windows) Basic Instructions – Declare – Conditional – Loop – Input Write a quiz game.
Bioinformatics 生物信息学理论和实践 唐继军
1 Perl Syntax: control structures Learning Perl, Schwartz.
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.
3.1 Revision: variables & arrays Array declaration Array = ('A','B','C','D'); = = (); Array.
Introduction to Unix – CS 21
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
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
5 1 Data Files CGI/Perl Programming By Diane Zak.
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
Introduction to Perl William G. Dishman CUR/516 November 5, 2014.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
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.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 4 Karsten Hokamp, PhD Genetics TCD, 01/12/2015.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
CSI605 perl. Perl Facts Perl = Pathologically Eclectic Rubbish Lister Perl is highly portable across many different platforms and operating systems Perl.
File Handle and conditional Lecture 2. File Handling The Files associated with Perl are often text files: e.g. text1.txt Files need to be “opened for.
The Scripting Programming Language
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Introduction to Perl: Practical extraction and report language
Perl Variables: Array Web Programming.
Basic Input/Output Web Programming.
Pemrosesan Teks Herika Hayurani Sept 19, 2006
Presentation transcript:

Where to get Perl ? / Unix/Linux/Solaris Unix/Linux/Solaris Interpreter (called “perl”) comes pre-installed usually Interpreter (called “perl”) comes pre-installed usually Get source from Get source from Win32 Win32 Get source distribution from Get source distribution from Have to compile Have to compile Get binary from Get binary from No need to compile, runs pretty well No need to compile, runs pretty well Macintosh Macintosh Perl IDE (integrated development environment) Perl IDE (integrated development environment) Open Perl IDE (Jurgen Guntherodt) Open Perl IDE (Jurgen Guntherodt) It’s mainly an editor. It’s mainly an editor. ActiveState Komodo 3.0 (IDE for Perl, Python, Tcl, …) ActiveState Komodo 3.0 (IDE for Perl, Python, Tcl, …) $29.95 for a student license $29.95 for a student license Visit the class web site for the links!

Running Perl: Windows Open a text editor such as Notepad Open a text editor such as Notepad 1. write your perl code 2. save your code with an extension “.pl” Open MS-DOS/Command window Open MS-DOS/Command window 1. go to your folder in which your code is saved 2. make a shortcut to the command window (enter “cmd” to make the shortcut) 3. right click on the icon and go to properties 4. clear the “start in” field 5. Run your code as “perl ” or 1. go to Start → run → “cmd”, … 2. run your code as “perl ”

Programming and Perl for Bioinformatics Part II

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)

Arrays An array (list) is an ordered group of scalar values. is used to refer to the entire array is used to refer to the entire array Example: Example: (1,2,3) # Array of three values 1, 2, and 3 ("one","two","three") # Array of 3 values "one", "two", = ("mary", "tom", "mark", "john", = ("mary", "tom", "mark", "john", "jane"); $names [1] ;? $names [1] [1..4]; Extract 2 nd item the sublist # “tom”

More on = ();# empty = ();# empty = (1,2,3);# three = (1,2,3);# three = ("Jan","Joe","Marie");# three = ("Jan","Joe","Marie");# three = ("Dirk",1.92,46," ");# a mixed = ("Dirk",1.92,46," ");# a mixed list Variables and sublists are interpolated in a list Variables and sublists are interpolated in a = ($a,$a+1,$a+2);# variable = ($a,$a+1,$a+2);# variable = ("Jan",("Joe","Marie"));# list = ("Jan",("Joe","Marie"));# list = ("Dirk",1.92,46,()," ");# empty list = ("Dirk",1.92,46,()," ");# empty list );# same as );# same as (1,2,3,"Jan","Joe","Marie") Practical construction operators ($x..$y) Practical construction operators = (1..6) # same as (1, 2, 3, 4, 5, = (1..6) # same as (1, 2, 3, 4, 5, = ( ) # same as (1.2, 2.2, 3.2, 4.2, = ( ) # same as (1.2, 2.2, 3.2, 4.2, = (2..5,8,11..13) # same as = (2..5,8,11..13) # same as (2,3,4,5,8,11,12,13)

Array Manipulations reverse Reverses the order of array = (1, 2, = = (3, 2, 1); splitSplits a string into a list/array $line = "John Smith 28"; ($first, $last, $age) = split /\s/, $line; $DNA = = split ('', $DNA); joinJoins a list/array into a string $gene = join "", ($exon1, $exon3); $gene = join "", ($exon1, $exon3); $name = join "-", ("Zhong", "Hui"); scalar Returns the number of elements sort Return sorted elements sort { $a $b # numerical sort sort { $a cmp $b # ASCII-betical sort

Exercise #Determine freq of nucleotides $dna ="gaTtACataCACTgttca"; ?

Ex: Determine freq of nucleotides $dna ="gaTtACataCACTgttca"; $dna = uc($dna); #GATTACATACACTGTTCA $count_A = 0; $count_C = 0; $count_G = 0; $count_T = = split '', $dna; foreach $base { if ($base eq 'A') {$count_A++;} elsif ($base eq 'C') {$count_C++;} elsif ($base eq 'G') {$count_G++;} elsif ($base eq 'T') {$count_T++;} else {print "error!\n";} } print "count of A = $count_A \n"; print "count of C = $count_C \n"; print "count of G = $count_G \n"; print "count of T = $count_T \n";

Filehandles File I/O (input/output): reading from/writing to files Files represented in Perl by a filehandle variable Files represented in Perl by a filehandle variable (for clarity, usu. written as a bare word in UPPERCASE) Open a file on a filehandle using the open function Open a file on a filehandle using the open function for reading (input): for reading (input): open INFILE, “< datafile.txt”; or open (INFILE, “< datafile.txt”); or open (INFILE, “< datafile.txt”); for writing (output), overwriting the file: for writing (output), overwriting the file: open OUTFILE, “> output”; for appending to the end of the file: for appending to the end of the file: open OUTFILE, “>> output”; Close a file on a filehandle Close a file on a filehandle Close (OUTFILE); Close (OUTFILE);

Special Filehandles Special “files” that are always “open” STDIN (standard input) STDIN (standard input) input from command window read only input from command window read only STDOUT (standard output) STDOUT (standard output) output to command window write only output to command window write only print STDOUT “Have fun with Perl!\n”; or just print “Have fun with Perl!\n”;

Input from Filehandles “Angle Bracket” input operator reads one line of input (up to newline/carriage return) reads one line of input (up to newline/carriage return) from STDIN: from STDIN: print "Enter name of protein: "; $line = ; chomp $line; # removes \n from end of $line print “\nYou entered $line.\n”; from a file: from a file: open (INPUT, “aminos.txt”); $amino1 = ; $amino2 = ; chomp ($amino1, $amino2);

sequences.fasta >gi|145536|gb|L |Escherichia coli DNA polymerase III chi subunit (holC) gene, complete cds TAACGGCGAAGAGTAATTGCGTCAGGCAAGGCTGTTATTGCCGGATGCGGCGTGAACGCCTTATCCGACCTACACAGCACTGAACTCGTAGGCCTGATAAGACACAACAGCGTCGCATCAGGCGCTGCGGTGTATACCTGATGCGTATTTAAATCCACCACAAGAAGCCCCATTTATGAAAAACGCGACGTTCTACCTTCTGGACAATGACACCACCGTCGATGGCTTAAGCGCCGTTGAGCAACTGGTGTGTGAAATTGCCGCAGAACGTTGGCGCAGCGGTAAGCGCGTGCTCATCGCCTGTGAAGATGAAAAGCAGGCTTACCGGCTGGATGAAGCCCTGTGGGCGCGTCCGGCAGAAAGCTTTGTTCCGCATAATTTAGCGGGAGAAGGACCGCGCGGCGGTGCACCGGTGGAGATCGCCTGGCCGCAAAAGCGTAGCAGCAGCCGGCGCGATATATTGATTAGTCTGCGAACAAGCTTTGCAGATTTTGCCACCGCTTTCACAGAAGTGGTAGACTTCGTTCCTTATGAAGATTCTCTGAAACAACTGGCGCGCGAACGCTATAAAGCCTACCGCGTGGCTGGTTTCAACCTGAATACGGCAACCTGGAAATAATGGAAAAGACATATAACCCACAAGATATCGAACAGCCGCTTTACGAGCACTGGGAAAAGCAGGGCTACTTTAAGCCTAATGGCGATGAAAGCCAGGAAAGTTTCTGCATCATGATCCCGCCGCCGAA

Determine frequency of nucleotides Input file: Input file: open (INPUT, "sequences.fasta"); #open file for sequence $line1 = ; $line2 = ; $line3 = ; chomp ($line2, $line3); $dna = $line2.$line3; $count_A = 0; $count_C = 0; $count_G = 0; $count_T = = split '', $dna; foreach $base { if ($base eq 'A') {$count_A++;} elsif ($base eq 'C') {$count_C++;} elsif ($base eq 'G') {$count_G++;} elsif ($base eq 'T') {$count_T++;} else {print "error!\n";} } print "count of A = $count_A \n"; print "count of C = $count_C \n"; print "count of G = $count_G \n"; print "count of T = $count_T \n";