Presentation is loading. Please wait.

Presentation is loading. Please wait.

Part 2 Biophysics 101 Jon Radoff, TF Teaching materials by Ivan Ovcharenko 84-234.

Similar presentations


Presentation on theme: "Part 2 Biophysics 101 Jon Radoff, TF Teaching materials by Ivan Ovcharenko 84-234."— Presentation transcript:

1 part 2 Biophysics 101 Jon Radoff, TF Teaching materials by Ivan Ovcharenko 84-234

2 Problem Set Policies Problem sets are due by 8pm of the appropriate Tuesday. Answers will be posted on the web 48 hours later. Late problem sets will have 5% deducted per day, with a maximum of 10%. No credit will be given to submissions made after answers are posted (i.e., after 8pm Thursday). We encourage you to work with other people but you must follow these two rules: –Put the names of those you worked with on your submitted problem set. –Neither the written answers nor code can be identical between any two submissions, i.e. put everything into your own words (or code). Local students: Hand in the assignment on paper at the beginning of lecture (either one) or to section (if by 8pm Tuesday). Submit code electronically as plain text. Distance students: Submit electronically as either a Microsoft Word document (preferred) or plain text, and code separately as plain text. All students: Begin filenames of all submitted files with your first name and last initial, e.g. JohnS_probset1.pl. We will answer questions and give advice on the problem sets but will not confirm particular answers before they are submitted.

3 part 2 Basics of Perl in examples: How to calculate 2+2 in Perl? Output the result to the screen? Make loops and cycles ?

4 part 2 2+2 = ? $a = 2; $b = 2; $c = $a + $b; $ - indicates a variable ; - ends every command = - assigns a value to a variable $c = 2 + 2; or $c = 2 * 2; or $c = 2 / 2; or $c = 2 ^ 4; or2^4 2 4 =16 $c = 1.35 * 2 - 3 / (0.12 + 1); or

5 part 2 Ok, $c is 4. How do we know it? print “Hello \n”; print command: $c = 4; print “$c”; “ ” - bracket output expression \n- print a end-of-the-line character (equivalent to pressing ‘Enter’) print “Hello everyone\n”; print “Hello”. ” everyone”. “\n”; Strings concatenation: Expressions and strings together: print “2 + 2 = “. (2+2). ”\n”; expression 2 + 2 = 4

6 part 2 Datatypes: # DEFINING NUMBERS $x = 4; $x = 1.25 $x = 2.345e-56; # DEFINING STRINGS $x = “ACTGGTA”; $y = “Hello everyone \n”; 2.345 * 10 -56 Valid Perl code: Gluing strings: #- comment line $z = “Hello everyone\n”; $x = “Hello “; $y = “everyone\n”; $z = $x. $y; $DNA = “AGTTATATATA”; print “DNA sequence: “. $DNA. ”\n”;

7 part 2 Loops and cycles (for statement): # Output all the numbers from 1 to 100 for ($n=1; $n<=100; $n+=1) { print “$n \n”; } 1. Initialization: for ( $n=1 ; ; ) { … } 2. Increment: for ( ; ; $n+=1 ) { … } 3. Termination (do until the criteria is satisfied): for ( ; $n<=100 ; ) { … } 4. Body of the loop - command inside curly brackets: for ( ; ; ) { … }

8 part 2 Triangle of A’s: # 6 lines loop for ($line=1; $line<=6; $line+=1) { # output $line ‘A’ symbols for ($n=1; $n<=$line; $n+=1) { print “A”; } # end the line print “\n”; } A AA AAA AAAA AAAAA AAAAAA Source code:

9 part 2 Conditional execution of commands: $x = -1; # check whether $x is positive or not if ($x > 0) { print “x = $x is positive\n”; } if ($x < 0) { print “x = $x is negative\n”; } if ($x == 0) { print “x is zero\n”; } X = -1 is negative Independent contols: if ($x > 0) { print “x = $x is positive\n”; } elsif ($x < 0) { print “x = $x is negative\n”; } else { print “x is zero\n”; }

10 part 2 FOR & IF -- all the even numbers from 1 to 100: for ($n=1; $n<=100; $n+=1) { if (($n % 2) == 0) { print “$n”; } Note: $a % $b -- Modulus -- Remainder when $a is divided by $b

11 part 2 Arrays: # array of 5 numbers @a = (7,3,4,-1,0); # array of strings @day = (“Mon”, “Tue”, “Wed”, “Thu”, “Fri”); First and $i-th elements of an array: $a[0] = 7; $a[3] = -1; # index of the last element in the array @a $#a = 4; # print all the elements in the array @a for ($i=0; $i<=$#a; $i+=1) { print “a[$i] = $a[$i] \n”; } a[0] = 7 a[1] = 3 a[2] = 4 a[3] = -1 a[4] = 0

12 part 2 Example. Weekdays of this week: # weekdays array @day = (“Sun”,“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”); # 7-days cycle for ($n=0; $n<=6; $n+=1) { print “June “. ($n+16). ”, 2002 - $day[$n]\n”; } June 16, 2002 - Sun June 17, 2002 - Mon June 18, 2002 - Tue June 19, 2002 - Wed June 20, 2002 - Thu June 21, 2002 - Fri June 22, 2002 - Sat

13 part 2 How does the real perl program look like: #!/usr/local/bin/perl print “Hello everyone\n”; Mandatory first line ! How to run it: 1. Save the text of your code as a file -- program.pl 2. Execute it: perl program.pl Hello everyone


Download ppt "Part 2 Biophysics 101 Jon Radoff, TF Teaching materials by Ivan Ovcharenko 84-234."

Similar presentations


Ads by Google