The Basics Getting started with Perl for Bioinformatics programming.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Iteration While / until/ for loop. Iteration: while/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initalise.
Roles of Variables with Examples in Scratch
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Chapter 2: Algorithm Discovery and Design
Loops – While, Do, For Repetition Statements Introduction to Arrays
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Copyright © Texas Education Agency, Computer Programming For Loops.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Python Control of Flow.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
An Introduction to Textual Programming
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Chapter 2 - Algorithms and Design
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
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.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Roles of Variables with Examples in Python ® © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
BY A Mikati & M Shaito Awk Utility n Introduction n Some basics n Some samples n Patterns & Actions Regular Expressions n Boolean n start /end n.
Course A201: Introduction to Programming 09/16/2010.
1 CS161 Introduction to Computer Science Topic #9.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
J AVA P ROGRAMMING 2 C H 03: C ONTROL STATEMENTS if, for loop (review) switch, while, do while break, continue Fall Java Programming.
Pascal Programming Pascal Loops and Debugging. Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
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.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
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.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
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.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Loop Structures.
Chapter 2.2 Control Structures (Iteration)
Python - Loops and Iteration
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Manipulating Pictures, Arrays, and Loops part 2
Arrays, For loop While loop Do while loop
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Control Structures: if Conditional
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Control Structures: for & while Loops
Computer Science Core Concepts
CISC101 Reminders All assignments are now posted.
Flowcharts and Pseudo Code
The structure of programming
Statements in C Programming
Just Enough Java 17-May-19.
Class code for pythonroom.com cchsp2cs
LOOP Basics.
Chapter 13 Control Structures
Presentation transcript:

The Basics Getting started with Perl for Bioinformatics programming

print "Welcome to the Wonderful World of Bioinformatics!\n"; Let's Get Started!

print "Welcome "; print "to "; print "the "; print "Wonderful "; print "World "; print "of "; print "Bioinformatics!"; print "\n"; Another version of welcome

Maxim 3.1 Programs execute in sequential order

Maxim 3.2 Less is better

Maxim 3.3 If you can say something with fewer words, then do so

$ perl -c welcome welcome syntax OK $ perl welcome Running Perl programs

String found where operator expected at welcome line 3, near "pint "Welcome to the Wonderful World of Bioinformatics!\n"" (Do you need to predeclare pint?) syntax error at welcome line 3, near "pint "Welcome to the Wonderful World of Bioinformatics!\n"" welcome had compilation errors. Running Perl – Syntax Errors

print ; "Welcome to the Wonderful World of Bioinformatics!\n"; Syntax and semantics $ perl whoops $ perl -c -w whoops Useless use of a constant in void context at whoops line 1. whoops syntax OK

$ chmod u+x welcome3 #! /usr/bin/perl -w $./welcome3 $ perl welcome3 Program: run thyself!

Maxim 3.4 There's more than one way to do it

Iteration

#! /usr/bin/perl -w # The 'forever' program - a (Perl) program, # which does not stop until someone presses Ctrl-C. use constant TRUE => 1; use constant FALSE => 0; while ( TRUE ) { print "Welcome to the Wonderful World of Bioinformatics!\n"; sleep 1; } Using the Perl while construct

$ chmod u+x forever $./forever Welcome to the Wonderful World of Bioinformatics!. Running forever...

Maxim 3.5 Add comments to make future maintenance of a program easier for other programmers and for you

Maxim 3.6 When using constant values, refer to them with a nice, human-friendly name as opposed to the actual value

Maxim 3.7 Use blocks to group program statements together

More Iterations

Maxim 3.8 A condition can result in a value of true or false

Introducing variable containers $name $_address $programming_101 $z $abc $count

Maxim 3.9 When you need to change the value of an item, use a variable container

Maxim 3.10 Don't be lazy: use good, descriptive names for variables

#! /usr/bin/perl -w # The 'tentimes' program - a (Perl) program, # which stops after ten iterations. use constant HOWMANY => 10; $count = 0; while ( $count < HOWMANY ) { print "Welcome to the Wonderful World of Bioinformatics!\n"; $count++; } Variable containers and loops

$ chmod u+x tentimes $./tentimes Welcome to the Wonderful World of Bioinformatics! Running tentimes...

Selection

#! /usr/bin/perl -w # The 'fivetimes' program - a (Perl) program, # which stops after five iterations. use constant TRUE => 1; use constant FALSE => 0; use constant HOWMANY => 5; $count = 0; while ( TRUE ) { $count++; print "Welcome to the Wonderful World of Bioinformatics!\n"; if ( $count == HOWMANY ) { last; } Using the Perl if construct

#! /usr/bin/perl -w # The 'oddeven' program - a (Perl) program, # which iterates four times, printing 'odd' when $count # is an odd number, and 'even' when $count is an even # number. use constant HOWMANY => 4; $count = 0; while ( $count < HOWMANY ) { $count++; if ( $count == 1 ) { print "odd\n"; } elsif ( $count == 2 ) { print "even\n"; } There Really Is MTOWTDI

elsif ( $count == 3 ) { print "odd\n"; } else # at this point $count is four. { print "even\n"; } The oddeven program, cont.

#! /usr/bin/perl -w # The 'terrible' program - a poorly formatted 'oddeven'. use constant HOWMANY => 4; $count = 0; while ( $count < HOWMANY ) { $count++; if ( $count == 1 ) { print "odd\n"; } elsif ( $count == 2 ) { print "even\n"; } elsif ( $count == 3 ) { print "odd\n"; } else # at this point $count is four. { print "even\n"; } } The terrible program

Maxim 3.11 Use plenty of whitespace, blank-lines and indentation to make your programs easier to read

#! /usr/bin/perl -w # The 'oddeven2' program - another version of 'oddeven'. use constant HOWMANY => 4; $count = 0; while ( $count < HOWMANY ) { $count++; if ( $count % 2 == 0 ) { print "even\n"; } else # $count % 2 is not zero. { print "odd\n"; } The oddeven2 program

print 5 % 2, "\n"; # prints a '1' on a line. print 4 % 2, "\n"; # prints a '0' on a line. print 7 % 4, "\n"; # prints a '3' on a line. Using the modulus operator

#! /usr/bin/perl -w # The 'oddeven3' program - yet another version of 'oddeven'. use constant HOWMANY => 4; $count = 0; while ( $count < HOWMANY ) { $count++; print "even\n" if ( $count % 2 == 0 ); print "odd\n" if ( $count % 2 != 0 ); } The oddeven3 program

<>; $line = <>; #! /usr/bin/perl -w # The 'getlines' program which processes lines. while ( $line = <> ) { print $line; } Processing Data Files

$ chmod u+x getlines $./getlines Running getlines...

$./getlines terrible $./getlines terrible welcome3 Asking getlines to do more

#! /usr/bin/perl -w # The 'patterns' program - introducing regular expressions. while ( $line = <> ) { print $line if $line =~ /even/; } Introducing Patterns

$./patterns terrible # The 'terrible' program - a poorly formatted 'oddeven'. { print "even\n"; } elsif ( $count == 3 ) { print "odd\n"; } { print "even\n"; } } $./patterns oddeven # The 'oddeven' program - a (Perl) program, # is an odd number, and 'even' when $count is an even print "even\n"; Running patterns...

Maxim 3.12 Patterns tell perl what to look for, not how to find it

Where To From Here