for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/)

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

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.
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.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
References and Data Structures. References Just as in C, you can create a variable that is a reference (or pointer) to another variable. That is, it contains.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Programming and Perl for Bioinformatics Part III.
Perl Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN , 302 pages. Second Edition, July 1997.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
5.1 Previously on... PERL course (let ’ s practice some more loops)
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.
Regular Expressions Regular Expression (or pattern) in Perl – is a template that either matches or doesn’t match a given string. if( $str =~ /hello/){
Shell Script Examples.
Lecture 8: Basic concepts of subroutines. Functions In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements Return.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Computer Programming for Biologists Class 8 Nov 28 th, 2014 Karsten Hokamp
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Sequences – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Sequences Reading: Kolman, Section 1.3.
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.
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
Data Structures and Debugging Dr. Nancy Warter-Perez June 18, 2003.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Sed, awk, & perl CS 2204 Class meeting 13 *Notes by Mir Farooq Ali and other members of the CS faculty at Virginia Tech. Copyright 2003.
Built-in Data Structures in Python An Introduction.
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.
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Optimizing in Perl By Peter Wad Sackett. Optimizing the code – minor gains 1 ++$i and $st.= $data instead of $i = $i+1 and $st = $st. $data Use index.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Perl Chapter 6 Functions. Subprograms In Perl, all subprograms are functions – returns 0 or 1 value – although may have “side-effects” optional function.
CPTG286K Programming - Perl Chapter 4: Control Structures.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
8.1 Common Errors – Exercise #3 Assuming something on the variable part of the input file. When parsing a format file (genebank, fasta or any other format),
ALGORITHMS.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
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.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
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.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
PERL SCRIPTING. COMPUTER BASICS CPU, RAM, Hard drive CPU can only use data in the register directly CPU RAM HARD DRIVE.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Scripts & Functions Scripts and functions are contained in .m-files
Perl Variables: Array Web Programming.
Introduction to Perl Jarrad Battaglia.
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
PERL: part II hashes, foreach control statements, and the split function By: Kevin Walton.
Presentation transcript:

for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/) ){ split(//, $line); } if( ($line =~ />/) or ($i == $#input)) { #new sequence #print previous sequence if($#seq >0 ){ print reverse "\n\n"; } if($i != print $line, "\n"; #print header } Reverse FASTA sequence

Packages package Utilities; sub checkInput{ my … } our $path=“/home/usr/local/”; my $var=“”; #local definition #last evaluated value must be #positive = #successful package load 1; Utilities.pm use Utilities; Utilities::checkInput(“for check”); print $Utilities::path; my $path=“/locale/”; #local definition some.pl

Debugger On Unix: “perldoc perldebug” Invoke Perl with the -d switch: perl –d your_code.pl arg1 arg2 …

Debugger (2) always displays the line it's about to execute Any command not recognized by the debugger is directly executed (eval'd) as Perl code (for example you can print out some variables). p expr (as “print expr”) x expr - Nested data structures are printed out recursively, unlike the real print function in Perl

Debugger (3) s [expr] Single step. Executes until the beginning of another statement, descending into subroutine calls. If an expression is supplied that includes function calls, it too will be single-stepped. n [expr] Next. Executes over subroutine calls, until the beginning of the next statement. If an expression is supplied that includes function calls, those functions will be executed with stops before each statement. Repeat last n or s command.

Debugger (4) r Continue until the return from the current subroutine. c [line|sub] Continue, optionally inserting a one-time-only breakpoint at the specified line or subroutine. w [line] List window (a few lines) around the current/[line] line

Debugger (5) b subname [condition] b [line] [condition] Set a breakpoint before the given line. If line is omitted, set a breakpoint on the line about to be executed. If a condition is specified, it's evaluated each time the statement is reached: a breakpoint is taken only if the condition is true. Breakpoints may only be set on lines that begin an executable statement. b 237 $x > 30 b $count237 < 11 b 33 /pattern/i

Debugger (6) W expr Add a global watch-expression.

Associative Arrays (Hashes) Keys are strings For each unique key there is one element (data) Array - $color[1]=“green”; Assoc. Array- $color{“green”}=1;

Associative Arrays (Hashes) (2) # list of pairs can be transformed into hash (and vice versa) % assray =(“one”, 1, “refresh”, “ctrl-alt-del”, “search”,”google”); #or % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => = %assray;

Associative Arrays (Hashes) (3) % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => = keys = values %assray; #the keys and values are in corresponding order $keys_num = keys %assray; #returns 3 #remember – Perl is context dependent

Associative Arrays (Hashes) (4) % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => ”google”); while ( ($key, $value) = each (%assray) ){ print “$key => $value \n”; } #access elements in sorted order foreach $key (sort keys %assray){ $value = $assray{$key}; }

Associative Arrays (5) # this sorts the %table hash by # value instead of = sort { $table{$b} $table{$a} } keys %table;

Associative Arrays (5)

Associative Arrays (Hashes) (6) #Exists function if(exists $assray{“circle”}){ … } #delete function (according to key) delete $assray{“circle”};

Associative Arrays (7) defined $i; defined $hash{$key}; # is not the same as exists( $hash{$key} ) undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};

Nested Data Structures Lists of Lists (arrays of arrays) Hashes of Arrays Arrays of Hashes Hashes of Hashes

Lists of Lists while( <> split; #split /\s/, $_; ]; } print $lol[ $i ][ $j ;

Lists of Lists (2) [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ); print $lol[ 0 ][ 1 ]; print ${ $lol[ 0 ] }[ 1 ]; print $lol[ 0 ]->[ 1 ]; #but not print $lol->[ 0 ][ 1 ];

Lists of Lists (3) [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ]); print ARRAY(0x80d5010) ARRAY(0x80d5070) ARRAY(0x80d5094) foreach $list print \n"; } foreach print \n"; }

Lists of Lists (4) [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ); print ARRAY(0x80d5010) ARRAY(0x80d5070) ARRAY(0x80d5094) print $rlol; ARRAY(0x80d4eb4) $lol[0][1]; $rlol->[0][1]; $lol[0]->[1]; $rlol->[0]->[1]; my $rlol=[ [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ];

Lists of Lists (5) foreach ( 0..9 = split /\s/, <>; $lol[ $_ size assignment } foreach ( 0..9 = split /\s/, <>; $lol[ $_ ]= #wrong, assignment of reference to a local value } foreach ( 0..9 = split /\s/, <>; $lol[ $_ ]= ]; }

Hashes of Arrays my %hoa=( color => [ “red”, “white”, “green” ], lang => [ “perl”], record => [ “list”, “of”, “lists” ] ); $hoa{ “another” } = ]; print $hoa{ “color” }[0];

Arrays of Hashes { color => “red”, lang => “perl” }, { color => “green”, lang => “c++” } ); print $hoa[0]{ “color” }; $hoa[0] = { %hash };

Hashes of Hashes my %hoa=( record1 => { color => “red”, lang => “perl” }, record2 => { color => “green”, lang => “c++” } ); print $hoa{“record1”}{ “color” }; $hoa{“newrecord”} = { %hash };

HomeWork (a) Compute the percentage of nucleotides/amino-acids. Input: file(s) in the FASTA format. Output: percentage of sequence symbols. (b) Sort protein/dna sequences according to sequence length. Input: file(s) in the FASTA format. Output: The same sequences (with descriptors) ordered from the longest sequence to the shortest. [use ‘sort’ perl function]