Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)

Slides:



Advertisements
Similar presentations
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Advertisements

Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C Programming
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Bioinformatics Lecture 7: Introduction to Perl. Introduction Basic concepts in Perl syntax: – variables, strings, input and output – Conditional and iteration.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Lecture 8: Basic concepts of subroutines. Functions In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements Return.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Lecture 7: Perl pattern handling features. Pattern Matching Recall =~ is the pattern matching operator A first simple match example print “An methionine.
Introduction to Shell Script Programming
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
E0001 Computers in Engineering
An Introduction to Unix Shell Scripting
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
CS0004: Introduction to Programming Variables – Strings.
Computer Science 101 Introduction to Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
Introduction to Unix – CS 21
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Variables, Expressions and Statements
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
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.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Perl Subroutines User Input Perl on linux Forks and Pipes.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 6 JavaScript: Introduction to Scripting
Perl Programming Language Design and Implementation (4th Edition)
Revision Lecture
Variables, Expressions, and IO
Introduction to Scripting
Perl for Bioinformatics
Introduction to C Programming
Tutorial 10: Programming with javascript
Presentation transcript:

Bioinformatics Introduction to Perl

Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables) and warnings – Basic input and output – Read and writing to a File

Computer programming This set of lectures will use the Active perl and notepad++ both of which are free.Active perl notepad++ Be aware: Some of the examples used in the perl lectures can be found in the accompanying zip file. Perl is a scripting interpreter language that has: – good string handling functionality; – pattern matching functionality; – other features, which we will cover later, This makes it suitable for bioinformatics

Variables: $variable_name In perl to declare a variable use: – $variable_name The $variable_name [memory location] can be assigned any value – There is no distinction between basic data types; the following are both valid: – $variable_name = “my name is Denis”; ( = is the assign operator) – $variable_name = 5.1;

“explicit” variable The $variable is referred to as a global variable and it may lead to problems; It is better to use an “explicit” variable using my $variable along with use strict; and use warnings. Consider the following examples:

Not using Strict and warnings Example 1: #!/usr/bin/perl # not using strict and warnings my $variable = 5; print "the value of the variable is: ",$varaible;

Using strict with semantic error Example 1: #!/usr/bin/perl # using strict and my $variables use strict; use warnings; my $variable = 5; print "the value of the variable is: ",$varaible;

Using Strict and no “semantic” error Example 3: (Write and Run Program) #!/usr/bin/perl # using strict and my $variables use strict; use warnings; my $variable = 5; print "the value of the variable is: ",$variable;

Variables: $variable_name The “value” associated with the variable can be assigned new values – $variable_name = 3.7; or $variable_name = “I like … “; If the value of the variable is a number Arithmetic operators can be applied: – +, – -, – *, – /, – **( exponential or “to the power” ); – % modulus (the remainder after dividing; 3%2 is 1)

Arithmetic example Code – #!/usr/bin/perl – #evaluating expressions in print (# comment line symbol) – $x = 15; – $y = 8; – print “the value of x is “, $x, “\n”; – print “the new value of x is “, $x + 3, “\n”; – print “the sum of x and y is “, $x + $y, “\n”; – print “the product of x and y is “, $x*$y, “\n”; – (ArithmeticExample.pl) output

Format output Double v single quotation marks – Sometimes we want to print a “ quotation“ so in perl it is done using ‘ ‘: Print ’ ”the end justifies the means “ \n’; More on output (refer to Output_Example.pl): – #!/usr/bin/perl – use strict; – use warnings – # formating output example – print ’ ”The secret to happiness is not doing what one likes to do but liking what one has to do “ \n’; – my $x = "I am from Cork "; #declare a string – my $y = "my name is Denis"; #declare another string – print "the value of \$x is $x\n"; # note the \$x – print "the value of $x is $x\n"; – print "the value of \$y concatenated to \$x is $y$x\n";

Output from OutputExample.pl

Inputting Data (assign data to a variable) Data can be typed in from the keyboard, read from a file or “hardcoded” to the end of the program Perl is good for reading text files – such as the Bioinfomatics “FASTA” file. Reads input one line at a time inclusive of carriage return/end of line marker Read data from the key board – #!/usr/bin/perl : This line must be at the start of each program. – use strict; use warnings; – $var = <> ; #(input a line of characters and assign it to $var) – chomp $var # removes the return character from the line. – Alternatively you can combine both statements together – chomp($var = <>);

Read data from a file (redirect input) Normally you open a file and read/write to the file. However perl can put the name of the file as one of the “arguments” in the command line; let us consider a file called text1.txt Perl code: – $variable = <> (same as that for inputting from the keyboard) At the Command line type – C:\directory> Input.pl text1.txt

Exercise 1 Declare 3 ($x, $y and $z) variables and assign them the following values: 12, 6, 8. Perform and print the results of the following arithmetic operations – $x to the power of $y – $x modulus % $y – $x modulus $z – &x plus $y plus $z and assign it to a new variable ($a) – Perform one other simple arithmetic operation of your choice

Exercise 2 Ask user to input a line of text from the keyboard and assign it to a variable then display the “value”. – Run the program – Re run the program but this time the input must come from a text file.

Useful link perl tutorial book Quick-Reference/ch3.htm Quick-Reference/ch3.htm This link covers all languages including perl