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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Scalar Data Types and Basic I/O
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
COMP234 Perl Printing Special Quotes File Handling.
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
Introduction to Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
CS 330 Programming Languages 10 / 11 / 2007 Instructor: Michael Eckmann.
1.1 Perl Programming for Biology The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman and Dudu.
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.
1 Perl Programming for Biology The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel October 2009 By Eyal Privman and Dudu.
Introduction to Python
1 Perl Programming for Biology The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel January 2009 By Eyal Privman
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Guide To UNIX Using Linux Third Edition
1.1 Perl Programming for Biology G.S. Wise Faculty of Life Science Tel Aviv University, Israel October 2009 David Burstein and Ofir Cohen.
5.1 Revision: Ifs and Loops. 5.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n";
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
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.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Computational Linguistics Programming I.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Introduction to Perl Yupu Liang cbio at MSKCC
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Variables, Expressions and Statements
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
1 Introduction to Perl CIS*2450 Advanced Programming Techniques.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
1.1 Perl Programming for Biology G.S. Wise Faculty of Life Science Tel Aviv University, Israel October 2012 Eli Levy Karin and Haim Ashkenazy
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
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.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
2.1 Lesson 2: Scalar Functions and Arrays “Perl programming is an empirical science!” - Larry Wall.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
Perl Subroutines User Input Perl on linux Forks and Pipes.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
Scripting Languages Course 7 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Chapter 2 part #1 C++ Program Structure
Shell Scripting March 1st, 2004 Class Meeting 7.
Perl A simple test.
Introduction to C++ Programming
Run Java file with Window cmd
Introduction to Perl Learning Objectives:
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Presentation transcript:

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 and Dudu Burstein

1ex.2 Running Perl at the DOS command prompt Traditionally, Perl scripts are run from a command prompt (a DOS window). (Start it by clicking: Start  Accessories  Command Prompt or: Start  Run…  cmd ) Running a Perl script perl -w YOUR_SCRIPT_NAME (To check if Perl is installed in your computer use the ‘perl -v’ command)

1ex.3 Running Perl at the DOS command prompt Common DOS commands: d: change to other drive (d in this case) md my_dir make a new directory cd my_dir change directory cd.. move one directory up dir list files (dir /p to view it page by page) help list all dos commands help dir get help on a dos command

1ex.4 A first Perl script print "Hello world!"; A Perl statement must end with a semicolon “ ; ” The print function outputs some information to the terminal screen Try it yourself! Use Notepad to write the script in a file named “ hello.pl ” (Save it in D:\perl_ex) Run it! Click Start  Programs  Accessories  Command Prompt (opens a DOS prompt) Change to the right drive ( "D:" ) and change directory to the directory that holds the Perl script ( "cd perl_ex" ). Type perl -w script_name.pl (replace script_name.pl with the name of the script)

1ex.5 Scalar Data

1ex.6 A scalar is either a string or a number. Numerical values e4 (= 1.3 × 10 4 = 1,300)‏ 6.35e-14 ( = 6.35 × )‏ Scalar values

1ex.7 Single-quoted strings print 'hello world'; hello world Double-quoted strings print "hello world"; hello world print "hello\tworld"; helloworld print 'a backslash-t: \t '; a backslash-t: \t MeaningConstruct Newline\n Tab\t Backslash\\ Double quote\”\” Strings Backslash is an “escape” character that gives the next character a special meaning: print "a backslash: \\ "; a backslash: \ print "a double quote: \" "; a double quote: " Scalar values

1ex.8 Operators An operator takes some values (operands), operates on them, and produces a new value. Numerical operators: + - * / ** (exponentiation) (autoincrement)‏ print 1+1; 2 print ((1+1)**3); 8

1ex.9 Operators An operator takes some values (operands), operates on them, and produces a new value. String operators:. (concatenate) x (replicate)‏ e.g. print ('swiss'.'prot'); swissprot print (('swiss'.'prot')x3); swissprotswissprotswissprot

1ex.10 String or number? Perl decides the type of a value depending on its context: (9+5).'a' 14.'a' '14'.'a' '14a' Warning: When you use parentheses in print make sure to put one pair of parantheses around the WHOLE expression: print (9+5).'a'; # wrong print ((9+5).'a'); # right You will know that you have such a problem if you see this warning: print (...) interpreted as function at ex1.pl line 3. (9x2)+1 ('9'x2)+1 '99'

1ex.11 Class exercise 1 Write a Perl script that prints the following lines: 1.The string “hello world! hello Perl!” 2.Use the operator “.” to concatenate the words “apple”, “orange” and “banana”‏ 3*. Produce the line: “ 666:666:666:god help us! ” without any 6 and with only one : in your script! Like so: hello world! hello Perl! apple orange banana 666:666:666:god help us!

1ex.12 Variables Scalar variables can store scalar values. Variable declaration my $priority; Numerical assignment $priority = 1; String assignment $priority = 'high'; Assign the value of variable $b to $a $a = $b; Note: Here we make a copy of $b in $a.

1ex.13 Variables - notes and tips Tips: Give meaningful names to variables: e.g. $studentName is better than $n Always use an explicit declaration of the variables using the my function Note: Variable names in Perl are case-sensitive. This means that the following variables are different (i.e. they refer to different values): $varname = 1; $VarName = 2; $VARNAME = 3; Note: Perl has a long list of scalar special variables ($_, $1, $2,…) So please don’t use them!

1ex.14 Variables - always use strict! Always include the line: use strict; as the first line of every script. “Strict” mode forces you to declare all variables by my. This will help you avoid very annoying bugs, such as spelling mistakes in the names of variables.

1ex.15 Interpolating variables into strings $a = 9.5; print "a is $a!\n"; a is 9.5! Reminder: print 'a is $a!\n'; a is $a!\n

1ex.16 $name: "Shmulik\n" Reading input Use the chomp function to remove the “new-line” from the end of the string (if there is any): print "What is your name?\n"; my $name = <STDIN>; chomp $name; # Remove the new-line print "Hello $name!"; Here is a test run: What is your name? Shmulik Hello Shmulik! $name: "Shmulik"

1ex.17 Built-in Perl functions: The length function The length function returns the length of a string: print length("hi you"); 6

1ex.18 The substr function The substr function extracts a substring out of a string. It receives 3 arguments: substr(EXPR,OFFSET,LENGTH) For example: $str = "university"; $sub = substr ($str, 3, 5); $sub is now "versi", and $str remains unchanged. Note: If length is omitted, everything to the end of the string is returned. You can use variables as the offset and length parameters. The substr function can do a lot more, google it and you will see…

1ex.19 Documentation of perl functions A good place to start is the list of All basic Perl functions in the Perl documentation site: Click the link “Functions” on the left.

1ex.20 Home exercise 1 – submit by until next class 1.Install Perl on your computer. Use Notepad to write scripts, or optionally - install the Perl Express editor (this you should do at home). 2.Write a script that prints "I will submit my homework on time" 100 times. 3.Write a script that assigns your address into the variable $ and then prints it. 4.Write a script that reads a line and prints the length of it. 5.Write a script that reads a line and prints the first 3 characters. 6*.Write a script that reads a line and three numbers, and then prints the letters between the positions given by the first two numbers, duplicated as many times as indicated by the third number. * Kohavit questions are a little tougher, and are not mandatory