Teaching Materials by Ivan Ovcharenko

Slides:



Advertisements
Similar presentations
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
Advertisements

Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Perl I/O Learning Objectives: 1. To understand how to perform input from standard Input & how to process the input 2. To understand how to perform input.
Introduction to Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
Bioinformatics Lecture 7: Introduction to Perl. Introduction Basic concepts in Perl syntax: – variables, strings, input and output – Conditional and iteration.
Part 2 Biophysics 101 Jon Radoff, TF Teaching materials by Ivan Ovcharenko
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
4ex.1 More loops. 4ex.2 Loops Commands inside a loop are executed repeatedly (iteratively): my $num=0; print "Guess a number.\n"; while ($num != 31) {
5.1 Previously on... PERL course (let ’ s practice some more loops)
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Perl I/O Software Tools. Lecture 15 / Slide 2 Input from STDIN Reading from STDIN is easy, and we have done it many times. $a = ; In a scalar context,
Getting Started with Perl (and Excel) Biophysics 101 September 17, 2003 Griffin Weber (With material from Jon Radoff and Ivan Ovcharenko)
More Perl Control Flow Learning Objectives: 1. To learn more commands for control flow 2. To apply the new commands learnt for writing tidier program 3.
4.1 Revision. 4.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n"; my $number.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
5.1 Revision: Ifs and Loops. 5.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n";
4.1 More loops. 4.2 Loops Commands inside a loop are executed repeatedly (iteratively): my $num=0; print "Guess a number.\n"; while ($num != 31) { $num.
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
Python programs How can I run a program? Input and output.
Lecture 7: Perl pattern handling features. Pattern Matching Recall =~ is the pattern matching operator A first simple match example print “An methionine.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
Bioinformatics 生物信息学理论和实践 唐继军
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.
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Why Linux and Not Windows?
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
CPTG286K Programming - Perl Chapter 4: Control Structures.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
5.1 Revision: Ifs and Loops. 5.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n";
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.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
Part 4 Arrays: Stacks foreach command Regular expressions: String structure analysis and substrings extractions and substitutions Command line arguments:
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
The Scripting Programming Language
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.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Linux Administration Working with the BASH Shell.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
String and Lists Dr. José M. Reyes Álamo.
Introduction to Programming
Introduction to Bioinformatic Computation. Lecture #
Perl Programming Language Design and Implementation (4th Edition)
Chapter 13 - The Preprocessor
Basic operations in Matlab
Vi Editor.
Perl for Bioinformatics
String and Lists Dr. José M. Reyes Álamo.
Introduction to Programming
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Introduction to Computer Science
Introduction to Bioinformatic Computation. Lecture #
Introduction to Programming
Unit 1: Intro Lesson 4: Output.
Presentation transcript:

Teaching Materials by Ivan Ovcharenko <IVOvcharenko@lbl Teaching Materials by Ivan Ovcharenko <IVOvcharenko@lbl.gov> 84-234 part 3

part 2 File management: How to deal with files? Read data from a file? Write to a file? Regular expressions: How to compare strings? Extract substrings? Substitute characters? Practical example: reverse complement of a DNA sequence

Windows Graphical User Interface part 2 File management Windows Graphical User Interface 1. Open 2. Edit 3. Save

Edit Read or Write part 2 Perl file management structure is simplier 1. Open file 2. READ or WRITE data (line by line) 3. Close file

part 2 How to open and close a file “data.txt” from a perl program? # open data.txt file for READING open (FILE, “ < data.txt”); Direction of file data flow File handler. This name will be used everywhere later in the program, when we will deal with this file. < - READ from a file > - WRITE to a file # close a file specified by FILE file handler close (FILE);

part 2 Writing “Hello everyone” to the “tmp.txt” file: #!/usr/local/bin/perl open (FILE, “ > tmp.txt”); print FILE “Hello everyone\n”; close (FILE);

part 2 Reading data from a file #!/usr/local/bin/perl # open file data.txt for reading open (FILE, “ < data.txt”); # read file line by line and print it out to the screen while ($line = <FILE>) { print “$line”; } #close file close(FILE); while loop is analogous to the for loop. All the body statements of it are executed until the condition in parenthesis is correct (true). $line = <FILE> - read next line from a file specified by the file handler FILE

part 2 Example. Calculating a sum of numbers in the file data.txt 1 18 23 2 chomp command removes “\n” (new line) symbol from the string #!/usr/local/bin/perl $sum = 0; open (FILE, “ < data.txt”); while ($line = <FILE>) { chomp($line); $sum = $sum + $line; } close(FILE); print “Sum of the numbers in data.txt file is $sum\n”; Sum of the numbers in data.txt file is 44

part 2 Operations with strings $string = “Hello everybody\n”; # concatenating strings $strA = “Hello “; $strB = “everybody\n”; $string = $strA . $strB; # length of the string -> number of characters inside $strLen = length ($strA); # $strLen = 6; # extracting a part of a string $strA = “Hello everybody\n”; $strB = substr ($strA, 2, 5); print “$strB”; llo e substr substr ( $string, $offset, $n) -- extracts $n characters from the string $string, starting at the position $offset (first position in a string is 0, not 1!)

part 2 Calculate a length of every string in a file named a.txt #!/usr/local/bin/perl # open the a.txt file open (INP, “<a.txt”); # read the file line by line while ($line = <FILE>) { chomp($line); $lineLength = length($line); print “$lineLength\n”; } # close the file close (INP);

? ? part 2 Comparing strings $strA = “AAA”; $strB = “BBB”; $strC = “bbb” if ($strA eq $strB) { print “true\n”; } if ($strB ne $strC) { print “true\n”; ? $strA = “AAAbbb”; $strC = “bbb” if ($strC eq substr($strA,3,3)) { print “true\n”; } ?

part 2 Modifying strings $strA = “AAAxCTT”; # substitute ‘x’ symbol by ‘N’ symbol in string $strA $strA =~ s/x/N/; # substitute all ‘A’ symbols by ‘G’ symbols $strA =~ s/A/G/g; global substitution # substitute all ‘A’s by ‘G’s, all ‘T’s by ‘A’s $strA =~ tr/AT/GA/; print “$strA \n”; GGGxCAA Note: tr/// substitutes only symbols, while s/// substitutes strings $strA =~ s/AAA/123/; 123xCTT

part 2 Example Convert string “Robert has 2 brothers and 2 sisters” to “John has 3 brothers and 3 sisters” $string = “Robert has 2 brothers and 2 sisters”; # 2 --> 3 $string =~ tr/2/3/; # Robert --> John $string =~ s/Robert/John/;

part 2 Reverse complement of a DNA sequence. Input file “seq1.fasta”. Output file “RCseq1.fasta”. #!/usr/local/bin/perl # open file seq1.fasta for reading & RCseq1.fasta for # writing open (INP, “ < seq1.fasta”); open (OUT, “ > RCseq1.fasta”); # read the sequence and store it into the string # variable $seq, skip the header line $seq = “”; <INP>; # reading a header line and losing the data while ($line = <FILE>) { chomp($line); $seq = $seq . $line; } # reverse complement the sequence $seq = reverse($seq); $seq =~ tr/ACTGactg/TGACtgac/; # output the $seq sequence in fasta format $offset = 0; while ($offset < length($seq)) { $subSeq = substr ($seq, $offset, 50); $offset = $offset + 50; print OUT “$subSeq\n”; } #close files close (INP); close (OUT);