Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.1 Ifs and Loops. 3.2 Revision: variables Scalar variables can store scalar values: Variable declaration my ($priority); Numerical assignment $priority.

Similar presentations


Presentation on theme: "3.1 Ifs and Loops. 3.2 Revision: variables Scalar variables can store scalar values: Variable declaration my ($priority); Numerical assignment $priority."— Presentation transcript:

1 3.1 Ifs and Loops

2 3.2 Revision: variables Scalar variables can store scalar values: Variable declaration my ($priority); Numerical assignment $priority = 1; String assignment $priority = 'high';

3 3.3 Revision: arrays Array List value variable @a = (1,2,3,"hi"); Array element: print $a[1]; 2 $a[0] = "*"; Array size: print scalar(@b); 4 Reading a list of lines: @a = ;

4 3.4 Revision: arrays Push & pop push(@a,6); print @a; 123hi6 my $x = pop(@a); print @a; 123hi print $x; 6 Unshift & shift unshift(@a,0); print @a; 0123hi my $x = shift(@a); print @a; 123hi print $x; 0 @a=(1,2,3,"hi"); 3210 "hi"321

5 3.5 Revision: arrays $str = "So-long-and-thanks-for-all-the-fish"; @a = split("-", $str); $str = join("!! ", @a ); print "$str\n"; So!! Long!! and!! thanks!! for!! all!! the!! fish reverse(1,2,3);sort("b","a","d","c",);

6 3.6 Controls: Ifs and Loops

7 3.7 Controls: if ? Controls allow non-sequential execution of commands, and responding to different conditions. else { print "Are you doing anything tomorrow night?\n"; } print "How old are you?\n"; my $age = ; if ($age < 18) { print "Sorry, I’m not allowed to chat with minors\n"; }

8 3.8 if, elsif, else It’s convenient to test several conditions in one if structure: if ($age < 18) { print "Sorry, I’m not allowed to chat with minors\n"; } elsif ($age < 25) { print "Are you doing anything tomorrow night?\n"; } elsif ($age < 35) { print "Are you married?\n"; } else { print "Do you need help crossing the street?\n"; }

9 3.9 Comparison operators StringNumericComparison eq==Equal ne!=Not equal lt<Less than gtgt>Greater than le<= Less than or equal to ge>= Greater than or equal to if ($age == 18){... } if ($name eq "Yossi")... if ($name ne "Yossi")... if ($name lt "n")... NumericComparison ==Equal !=Not equal <Less than >Greater than <= Less than or equal to >= Greater than or equal to Found = in conditional, should be == at

10 3.10 Boolean operators if (($age==18) || ($name eq "Yossi")){... } if (($age==18) && ($name eq "Yossi")){... } if (!($name eq "Yossi")){... } And && Or || Not !

11 3.11 Controls: Loops Commands inside a loop are executed repeatedly (iteratively): while ($name ne "Yossi") { chomp($name = ); print "Hello $name!\n"; } @names = ; foreach $name (@names) { print "Hello $name!\n"; } * There are also until, do-while and do-until loops

12 3.12 Loops $i=0; while ($i<scalar(@names)) { $name = $names[$i]; print "Hello $name!\n"; $i++; } for ($i=0; $i<scalar(@names); $i++) { $name = $names[$i]; print "Hello $name!\n"; } A for loop is controlled by three statements: 1 st is executed before the first iteration 2 nd is the stop condition 3 rd is executed before every re-iteration These are equivalent foreach $name (@names) { print "Hello $name!\n" }

13 3.13 Breaking out of loops next – skip to the next iteration last – skip out of the loop my @lines = ; foreach $line (@lines) { if (substr($line,0,1) ne ">") { next; } print(substr($line,1)); if (substr($line,0,4) eq ">ehd") { last; } }

14 3.14 Breaking out of loops die – end the program and print an error message to the standard error if ($score < 0) { die "score must be positive"; } score must be positive at test.pl line 8. Note: if you end the string with a "\n" then only your message will be printed * warn does the same thing as die without ending the program

15 3.15 “ The Programming Process ”

16 3.16 The programming process It pays to plan ahead before writing a computer program: 1.Define the purpose of the program 2.Identify the required inputs 3.Decide how to present the outputs 4.Make an overall design of the program 5.Refine the design, specify more details 6.Write the code – one stage at a time and test each stage 7.Debug…

17 3.17 An example: SAGE libraries 1.Double-stranded cDNA is generated from cell extracts 2.The cDNA is cleaved with a restriction enzyme (NlaIII) 3.The most 3'-end of the cDNA is then collected by their poly-A 4.The fragments are ligated to linkers containing a recognition site for a type IIS restriction enzyme and a PCR primer site 5.This restriction enzyme cuts 20bp away from its recognition site 6.Ligation, PCR, cleavage, concatenation, cloning, sequencing…  A 10bp tag sequence from each mRNA 7.10bp sequences are searched in an mRNA database and the corresponding genes are identified SAGE (Serial Analysis of Gene Expression) is used to identify all transcripts that are expressed in a tissue: (1) (2&3) (4&5)

18 3.18 An example: SAGE libraries SAGE (Serial Analysis of Gene Expression) is used to identify all transcripts that are expressed in a tissue:

19 3.19 Predicting the SAGE tag of an mRNA It would be useful to know what tag to expect for each mRNA in the database. So lets write a script: 1. Purpose: To predict the 10bp sequence of the SAGE tag of a given mRNA 2. Inputs: A list of mRNA sequences in FASTA format >gi|24646380|ref|NM_079608.2| Mus musculus EH-domain containing 4 (EHD4), mRNA GTGGTATTTCTTCGTTGTCTCTGGCGTGGTCACGTTGATTGGTCCGCTATCTGGACCGAAAAAAGTCGTA...... GTCGACGGCGATGGGTTCCTGGACTCTGACGAGTTCGCGCTGGCCTTGCACTTAATCAACGTCAAGCTGG AAGGCTGCGAGCTGCCCACCGTGCTGCCGGAGCACTTAGTACCGCCGTCGAAGCGCTATGACTAGTGTCC TGTAGCATACGCATACGCACACTAGATCACACAGCCTCACAATTCCCAAAAAAAAAAAAAAAA >gi|71895640|ref|NM_001031040.1| Mus musculus EH-domain containing 3 (EHD3), mRNA GGTAGGGCGCTACCGCCTCCGCCCGCCTCTCGCGCTGTTCCTCCGCGGTATGCCCGCGCCGGCAGCCGGC...... TATTATATAGAGAAATATATTGTGTATGTAGGATGTGCTTATTGCATTACATTTATCACTTGTCTTAACT AGAATGCATTAACCTTTTTTGTACCCTGGTCCTAAAACATTATTAAAAAGAAAGGCTAAAAAAAAAAAAA AAAA >gi|55742710|ref|NM_153068.2| Mus musculus EH-domain containing 2 (Ehd2), mRNA TGAGGGGGCCTGGGGCCCGCCCTGCTCGCCGCTCCTAGCGCACGCGGCCCCACCCGTCTCACTCCACTGC......

20 3.20 Predicting the SAGE tag of an mRNA 3. Decide how to present the results Simply print the header line of each mRNA and then it’s predicted 10bp tag, like so: > gi|24646380|ref|NM_079608.2| Mus musculus EH-domain containing 4 (EHD4), mRNA ATCACACAGC >gi|71895640|ref|NM_001031040.1| Mus musculus EH-domain containing 3 (EHD3), mRNA AATGCATTAA...

21 3.21 Predicting the SAGE tag of an mRNA 4. Overall design: 1.For each mRNA in the input: 1.Read the sequence 2.Find the most downstream recognition site of NlaII (CTAG) 3.Get the 10bp tag after that site 4.Print it

22 3.22 Predicting the SAGE tag of an mRNA 5.Refine the design, specify more details: 1.For each mRNA in the input (use a loop): 1.Read the sequence 1.Store its header line in one string variable 2.Concatenate all lines of the sequence and store it in another string variable 2.Find the most downstream recognition site of NlaII (CTAG) 1.Go over the sequence with a loop, starting from the 3’ tail, and going back until the first CTAG is found 3.Get the 10bp tag after that site 1.Take a substr of length 10 4.Print it 6.Write the code


Download ppt "3.1 Ifs and Loops. 3.2 Revision: variables Scalar variables can store scalar values: Variable declaration my ($priority); Numerical assignment $priority."

Similar presentations


Ads by Google