SlideShare a Scribd company logo
1 of 5
Download to read offline
Common Programming Language Constructs
                    Lecture 4: Perl Tutorial
                                                                       • Variables and Assignment
                                                                       • Variable types: Arrays, Hashes, Scalars, and Strings
                 • Tutorial on Programming in Perl
                                                                       • Arithmetic Operators
                                                                       • Logical Operators
                                                                       • Conditional Statements
                                                                       • Loops
                                                                       • Input/Output
                                                                       • Array and Hash Functions
                                                                       • Regular Expressions
                                                                       • Database Functions




                           Why Perl?                                                    Perl: Basic Syntax Rules

                                                                     § Statements are terminated by a semi-colon
§ Perl = Practical Extraction and Report Language                            • Print (“Hello!n”);

§ Advantages:                                                        § Text blocks are demarcated by curly brackets
       • Scripting Language: fast to write                                    • If ($a == $b) {
       • Relatively easy first language to learn                                        print (“a=b!n”);
       • Built-in tools: Regular Expressions, etc.                               }
       • Runs on most operating systems: Linux, Mac, Windows
       • Perl community: CPAN, modules.                              § Comments are indicated by a sharp sign (rest of line is a comment)
                                                                           • $a = 10; # Set $a equal to ten.
       • Bioinformatics tools: Bioperl
       • Web programming: CGI.pm or mod_perl                         § Separate variable names and tokens with spaces, otherwise space
                                                                       has no meaning.
§ To learn more about Perl:                                                  • $a + $b; is the same as $a   +     $b;
        • Learning Perl by Randal L. Schwartz and Tom Christiansen
        • Beginning Perl for Bioinformatics by James Tisdall         § Common conventions: n = newline, t = tab, “ ” = string
        • Programming Perl by Larry Wall and Tom Christiansen
        • www.perl.com/perl and www.perl.com/cpan                    § Order matters: statements are evaluated in descending order
Perl: Assignment                                                    Perl: Variable types

                                                            § Dollar-sign ($) variable represents a scalar or string
Assignment:
                                                                     • $DNA_length = 20;
§ Equal sign represents variable assignment
                                                                     • $DNA_sequence = “ATTAGCCGAATTGGCCAAGG”;
         • $A = “B”;
                                                            § At-sign (@) variable represents an array
§ Binary assignment operators:                                Dollar-sign ($) sign represents individual array element
         • $A = $A + 5; => $A += 5;
                                                                     • @DNA = (A,T,T,A,G,C,C,G,A,A,T,T,G,G,C,C,A,A,G,G);
         • $B = $B - 6; => $B -= 6;                                  • $DNA[0] is equal to “A”; $DNA[1] is equal to “T”; etc.

                                                            § Percent sign (%) variable represents a hash.
                                                              Dollar-sign ($) represents individual hash element
                                                                     • %DNA = (“First” => “A”, “Second” => “T”);
                                                                     • $DNA[“First”] is equal to “A”;




      Perl: Arithmetic Operators                                              Perl: Logical Operators


Arithmetic Operators:
                                                     Logical Operators:
§ Addition: $a = 5 + 6; # $a equals 11
                                                     § Identity test: if ($a == 6); # $a is equal to 6?
§ Subtraction: $a = 6 - 4; # $a equals 2
                                                     § Not equals test: if ($a != 6); # $a is not equal to 6?
§ Multiplication: $a = 3 * 2; # $a equals 6
                                                     § Less than, greater than: $a < 6; $b > 5
§ Division: $a = 6 / 2; # $a equals 3
                                                     § AND operator: $a == 6 && $b > 5; # $a is equal to 6 AND $b is greater than 5
§ Modulus: $a = 3 % 2 = 1
                                                     § OR operator: $a == 6 || $b < 4; # $a is equal to 6 OR $b is less than 4
§ Auto-increment: $a = 0; $a++; # $a is equal to 1
                                                     § Comparing strings: if ($a eq “Hello”); # $a is the string “Hello”?
Perl: String Functions                                                    Perl: Array Functions
                                                                 § Split function: splits a string into an array of letters
String functions:
                                                                     • $seq = “ATAGCCAT”;
§ String concatenate operator is a period (.)
                                                                       @DNA = split(//, $seq);            # $DNA[0] is “A”, $DNA[1] is “T”, etc.
   • $a = “Hello”; $b = “World”;
                                                                 § Push/Pop: Push adds value to end of array; pop removes last value of array
   • $c = $a . $b;          # $c is “HelloWorld”
                                                                     • push (@DNA, “G”);                 # @DNA is {A,T,A,G,C,C,A,T,G}
§ String length: $length = length($string)
                                                                     • $last = pop (@DNA);               # $last is “G”, @DNA is {A,T,A,G,C,C,A,T}
   • $text_length = length($c);       # $text_length is 10
                                                                 § Reverse: reverses order of the array
§ String reverse operator: $rev_string = reverse($string);
                                                                     • @DNA = reverse (@DNA);                      # @DNA is {T,A,C,C,G,A,T,A}
   • $rev_c = reverse ($string);      # $rev_c is “dlroWolleH”
                                                                 § Length of array: scalar @array
                                                                     • $size_of_array = scalar @DNA;               # $size_of_array is 8




             Perl: Conditional statements                                                             Perl: Loops

                                                                       § for statements:
   § if/else statements:
                                                                           • for (initial expression; test expression; increment expression) {
       • if (statement) {do if statement is true}                               do statement}
       • else {do if statement is false}
                                                                           • for ($i = 0; $i < 100; $i++) {
                                                                                 $DNA[$i] = “A”;
       • if ( $DNA eq “A”) { print (“DNA is equal to An”); }
                                                                                 }
         elsif ($DNA eq “T”) { print (“DNA is equal to Tn”);}
                                                                       § foreach statements:
         else { print (“DNA is not A or Tn”);}
                                                                           • foreach $i (@some_list) {do statement}

                                                                           • foreach $i (@DNA) {
                                                                                $i = “T”;
                                                                                }
Perl Loops (continued)                                                    Perl: Input/Output

                                                                                  § Standard input: <STDIN>
   § while statements:
                                                                                     • $a = <STDIN>;
       • while (statement) {do if statement is true, evaluate while again}
                                                                                       # $a equals line of text inputted by user
       • $i = 0;
                                                                                  § Standard output: print statement
         while ($i < 100) {
            $DNA[$i] = “A”;                                                          • print “hello $an”;
            $i++;                                                                      # prints: hello [value of $a]
            }
                                                                                  § Opening File: open (FILEHANDLE, “filename”);
                                                                                     • open (DNASEQ, “dnaseq.txt”);

                                                                                  § Reading File: single line => $DNA = <FILEHANDLE>;
                                                                                                  whole file => @DNA = <FILEHANDLE>;
                                                                                     • $DNA = <DNASEQ>;
                                                                                       # Reads single line from dnaseq.txt file




                     Perl: Regular Expressions                                       Perl: Regular Expressions (continued)

§ Matching: $string =~ /pattern/
                                                                               § Wildcards:
   • $DNA = “ATATAAAGA”;
     if ($DNA =~ /TATA/) {                                                        • [ATGC] matches A or T or G or C
          print (“Contains TATA elementn”);
          }                                                                       • [^0-9] matches all non-digit characters

§ Substitution: $string =~ s/pattern/replacement pattern/(g)                      • A{1,5} matches a stretch of 1 to 5 “A” characters

(note: g results in global replacement, otherwise just replaces first match)   Example:
   • $DNA =~ s/TATA/GGGG/g;          # $DNA is now “AGGGGAAGA”                    • $DNA = ““TCCCCTTCT”;

§ Transliteration: $string =~ tr/ATCG/TAGC/                                       • $DNA =~ /[AT]C{1,4}T/;             # Does this find a match?
   • Will replace “A” with “T”, “T” with “A”, “C” with “G”, and “G” with “C”

   • $DNA =~ tr/ATCG/TAGC/;          # $DNA is now “TCCCCTTCT”;
Example Perl Program: ReverseComp.pl                                           Implementing Reverse Complement Algorithm in Perl

§ Want to write a Perl program that will calculate the reverse
   complement of a DNA sequence provided by the software user.                                # ReverseComp.pl => takes DNA sequence from user
                                                                                              # and returns the reverse complement
§ Program tasks:                                                                              print (“Please input DNA sequence:n”);
  (1) Obtain DNA sequence from user.                                                          $DNA = <STDIN>;

                                                                                              $DNA =~ tr/ATGC/TACG/; # Find complement of DNA sequence
  (2) Calculate the complement of the DNA sequence.
          • A => T; T => A; G => C; C => G                                                    $DNA = reverse($DNA);              # Reverse DNA sequence

  (3) Reverse the order of the DNA sequence.                                                  print (“Reverse complement of sequence is:n”);

                                                                                              print $DNA . “n”;
  (4) Output the calculated reverse complement DNA sequence
       to user.




              Exact Sequence Matching Algorithm in Perl
 Perl code:
 # @DNA_Q is an array containing each nucleotide of the query sequence as an
 # array element (from user)
 # @DNA_T is an array containing each nucleotide of the chromosome sequence as
 # an array element.

 # Find length of Query and Template (Chromosome) arrays
 $length_Q = scalar @DNA_Q;
 $length_T = scalar @DNA_T;

 # Initialize number of matches counting variable
 $num_matches = 0;

 # Search for sequence match and print position of match if found.
 for ($i = 0; $i < = ($length_T - $length_Q); $i++) {
             for ($j = 0; $j < $length_Q && $DNA_Q[$j] eq $DNA_T[($i + $j)]; $j++) {
                         if ($j == ($length_Q - 1)) {
                                     print ("Found match at position $i in chromosomen");
                                     $num_matches++;
                         }
             }
 }

More Related Content

What's hot

Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics McSoftsis
 
Advance java session 14
Advance java session 14Advance java session 14
Advance java session 14Smita B Kumar
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)jaxLondonConference
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern PerlDave Cross
 
PHP 8: What's New and Changed
PHP 8: What's New and ChangedPHP 8: What's New and Changed
PHP 8: What's New and ChangedAyesh Karunaratne
 

What's hot (7)

Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
Using PHP 5.3 Namespaces for Fame and Fortune
Using PHP 5.3 Namespaces for Fame and FortuneUsing PHP 5.3 Namespaces for Fame and Fortune
Using PHP 5.3 Namespaces for Fame and Fortune
 
Ravi software faculty
Ravi software facultyRavi software faculty
Ravi software faculty
 
Advance java session 14
Advance java session 14Advance java session 14
Advance java session 14
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
PHP 8: What's New and Changed
PHP 8: What's New and ChangedPHP 8: What's New and Changed
PHP 8: What's New and Changed
 

Viewers also liked

"Покажи мне свою сумочку - и я скажу, кто ты"
"Покажи мне свою сумочку - и я скажу, кто ты""Покажи мне свою сумочку - и я скажу, кто ты"
"Покажи мне свою сумочку - и я скажу, кто ты"инна ветрова
 
EXAMEN PRACTICO DE COMPUTACION 2DO BIM
EXAMEN PRACTICO DE COMPUTACION 2DO BIMEXAMEN PRACTICO DE COMPUTACION 2DO BIM
EXAMEN PRACTICO DE COMPUTACION 2DO BIMJonathan Medina
 
Madasamy Raja-Assign #6-GSCM
Madasamy Raja-Assign #6-GSCMMadasamy Raja-Assign #6-GSCM
Madasamy Raja-Assign #6-GSCMDm Raja
 
papaya colombiana de exportacion
papaya colombiana de exportacionpapaya colombiana de exportacion
papaya colombiana de exportacionJOSEGONZALEZ02
 
Великие художники. Альбрехт Дюрер
Великие художники. Альбрехт ДюрерВеликие художники. Альбрехт Дюрер
Великие художники. Альбрехт Дюреринна ветрова
 
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3FGV | Fundação Getulio Vargas
 
Servicios portuarios, operaciones en muelles y tarifas
Servicios portuarios, operaciones en muelles y tarifasServicios portuarios, operaciones en muelles y tarifas
Servicios portuarios, operaciones en muelles y tarifasJorge Monserratte
 
Hard Rock presentation
Hard Rock presentationHard Rock presentation
Hard Rock presentationTyler Szilagyi
 

Viewers also liked (12)

TonyGoodmanResume(1)
TonyGoodmanResume(1)TonyGoodmanResume(1)
TonyGoodmanResume(1)
 
"Покажи мне свою сумочку - и я скажу, кто ты"
"Покажи мне свою сумочку - и я скажу, кто ты""Покажи мне свою сумочку - и я скажу, кто ты"
"Покажи мне свою сумочку - и я скажу, кто ты"
 
Śniadanie Daje Moc
Śniadanie Daje MocŚniadanie Daje Moc
Śniadanie Daje Moc
 
Seo
SeoSeo
Seo
 
EXAMEN PRACTICO DE COMPUTACION 2DO BIM
EXAMEN PRACTICO DE COMPUTACION 2DO BIMEXAMEN PRACTICO DE COMPUTACION 2DO BIM
EXAMEN PRACTICO DE COMPUTACION 2DO BIM
 
Madasamy Raja-Assign #6-GSCM
Madasamy Raja-Assign #6-GSCMMadasamy Raja-Assign #6-GSCM
Madasamy Raja-Assign #6-GSCM
 
papaya colombiana de exportacion
papaya colombiana de exportacionpapaya colombiana de exportacion
papaya colombiana de exportacion
 
Великие художники. Альбрехт Дюрер
Великие художники. Альбрехт ДюрерВеликие художники. Альбрехт Дюрер
Великие художники. Альбрехт Дюрер
 
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3
FGV - RAE Revista de Administração de Empresas, 2015. Volume 55, Número 3
 
Servicios portuarios, operaciones en muelles y tarifas
Servicios portuarios, operaciones en muelles y tarifasServicios portuarios, operaciones en muelles y tarifas
Servicios portuarios, operaciones en muelles y tarifas
 
Hard Rock presentation
Hard Rock presentationHard Rock presentation
Hard Rock presentation
 
Tema 5 d 2.1 power point
Tema  5 d 2.1 power pointTema  5 d 2.1 power point
Tema 5 d 2.1 power point
 

Similar to Lecture4

Similar to Lecture4 (20)

tutorial7
tutorial7tutorial7
tutorial7
 
tutorial7
tutorial7tutorial7
tutorial7
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Scripting3
Scripting3Scripting3
Scripting3
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Perl_Tutorial_v1
Perl_Tutorial_v1Perl_Tutorial_v1
Perl_Tutorial_v1
 
Perl_Tutorial_v1
Perl_Tutorial_v1Perl_Tutorial_v1
Perl_Tutorial_v1
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programming
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 
Perl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingPerl Intro 3 Datalog Parsing
Perl Intro 3 Datalog Parsing
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Lecture4

  • 1. Common Programming Language Constructs Lecture 4: Perl Tutorial • Variables and Assignment • Variable types: Arrays, Hashes, Scalars, and Strings • Tutorial on Programming in Perl • Arithmetic Operators • Logical Operators • Conditional Statements • Loops • Input/Output • Array and Hash Functions • Regular Expressions • Database Functions Why Perl? Perl: Basic Syntax Rules § Statements are terminated by a semi-colon § Perl = Practical Extraction and Report Language • Print (“Hello!n”); § Advantages: § Text blocks are demarcated by curly brackets • Scripting Language: fast to write • If ($a == $b) { • Relatively easy first language to learn print (“a=b!n”); • Built-in tools: Regular Expressions, etc. } • Runs on most operating systems: Linux, Mac, Windows • Perl community: CPAN, modules. § Comments are indicated by a sharp sign (rest of line is a comment) • $a = 10; # Set $a equal to ten. • Bioinformatics tools: Bioperl • Web programming: CGI.pm or mod_perl § Separate variable names and tokens with spaces, otherwise space has no meaning. § To learn more about Perl: • $a + $b; is the same as $a + $b; • Learning Perl by Randal L. Schwartz and Tom Christiansen • Beginning Perl for Bioinformatics by James Tisdall § Common conventions: n = newline, t = tab, “ ” = string • Programming Perl by Larry Wall and Tom Christiansen • www.perl.com/perl and www.perl.com/cpan § Order matters: statements are evaluated in descending order
  • 2. Perl: Assignment Perl: Variable types § Dollar-sign ($) variable represents a scalar or string Assignment: • $DNA_length = 20; § Equal sign represents variable assignment • $DNA_sequence = “ATTAGCCGAATTGGCCAAGG”; • $A = “B”; § At-sign (@) variable represents an array § Binary assignment operators: Dollar-sign ($) sign represents individual array element • $A = $A + 5; => $A += 5; • @DNA = (A,T,T,A,G,C,C,G,A,A,T,T,G,G,C,C,A,A,G,G); • $B = $B - 6; => $B -= 6; • $DNA[0] is equal to “A”; $DNA[1] is equal to “T”; etc. § Percent sign (%) variable represents a hash. Dollar-sign ($) represents individual hash element • %DNA = (“First” => “A”, “Second” => “T”); • $DNA[“First”] is equal to “A”; Perl: Arithmetic Operators Perl: Logical Operators Arithmetic Operators: Logical Operators: § Addition: $a = 5 + 6; # $a equals 11 § Identity test: if ($a == 6); # $a is equal to 6? § Subtraction: $a = 6 - 4; # $a equals 2 § Not equals test: if ($a != 6); # $a is not equal to 6? § Multiplication: $a = 3 * 2; # $a equals 6 § Less than, greater than: $a < 6; $b > 5 § Division: $a = 6 / 2; # $a equals 3 § AND operator: $a == 6 && $b > 5; # $a is equal to 6 AND $b is greater than 5 § Modulus: $a = 3 % 2 = 1 § OR operator: $a == 6 || $b < 4; # $a is equal to 6 OR $b is less than 4 § Auto-increment: $a = 0; $a++; # $a is equal to 1 § Comparing strings: if ($a eq “Hello”); # $a is the string “Hello”?
  • 3. Perl: String Functions Perl: Array Functions § Split function: splits a string into an array of letters String functions: • $seq = “ATAGCCAT”; § String concatenate operator is a period (.) @DNA = split(//, $seq); # $DNA[0] is “A”, $DNA[1] is “T”, etc. • $a = “Hello”; $b = “World”; § Push/Pop: Push adds value to end of array; pop removes last value of array • $c = $a . $b; # $c is “HelloWorld” • push (@DNA, “G”); # @DNA is {A,T,A,G,C,C,A,T,G} § String length: $length = length($string) • $last = pop (@DNA); # $last is “G”, @DNA is {A,T,A,G,C,C,A,T} • $text_length = length($c); # $text_length is 10 § Reverse: reverses order of the array § String reverse operator: $rev_string = reverse($string); • @DNA = reverse (@DNA); # @DNA is {T,A,C,C,G,A,T,A} • $rev_c = reverse ($string); # $rev_c is “dlroWolleH” § Length of array: scalar @array • $size_of_array = scalar @DNA; # $size_of_array is 8 Perl: Conditional statements Perl: Loops § for statements: § if/else statements: • for (initial expression; test expression; increment expression) { • if (statement) {do if statement is true} do statement} • else {do if statement is false} • for ($i = 0; $i < 100; $i++) { $DNA[$i] = “A”; • if ( $DNA eq “A”) { print (“DNA is equal to An”); } } elsif ($DNA eq “T”) { print (“DNA is equal to Tn”);} § foreach statements: else { print (“DNA is not A or Tn”);} • foreach $i (@some_list) {do statement} • foreach $i (@DNA) { $i = “T”; }
  • 4. Perl Loops (continued) Perl: Input/Output § Standard input: <STDIN> § while statements: • $a = <STDIN>; • while (statement) {do if statement is true, evaluate while again} # $a equals line of text inputted by user • $i = 0; § Standard output: print statement while ($i < 100) { $DNA[$i] = “A”; • print “hello $an”; $i++; # prints: hello [value of $a] } § Opening File: open (FILEHANDLE, “filename”); • open (DNASEQ, “dnaseq.txt”); § Reading File: single line => $DNA = <FILEHANDLE>; whole file => @DNA = <FILEHANDLE>; • $DNA = <DNASEQ>; # Reads single line from dnaseq.txt file Perl: Regular Expressions Perl: Regular Expressions (continued) § Matching: $string =~ /pattern/ § Wildcards: • $DNA = “ATATAAAGA”; if ($DNA =~ /TATA/) { • [ATGC] matches A or T or G or C print (“Contains TATA elementn”); } • [^0-9] matches all non-digit characters § Substitution: $string =~ s/pattern/replacement pattern/(g) • A{1,5} matches a stretch of 1 to 5 “A” characters (note: g results in global replacement, otherwise just replaces first match) Example: • $DNA =~ s/TATA/GGGG/g; # $DNA is now “AGGGGAAGA” • $DNA = ““TCCCCTTCT”; § Transliteration: $string =~ tr/ATCG/TAGC/ • $DNA =~ /[AT]C{1,4}T/; # Does this find a match? • Will replace “A” with “T”, “T” with “A”, “C” with “G”, and “G” with “C” • $DNA =~ tr/ATCG/TAGC/; # $DNA is now “TCCCCTTCT”;
  • 5. Example Perl Program: ReverseComp.pl Implementing Reverse Complement Algorithm in Perl § Want to write a Perl program that will calculate the reverse complement of a DNA sequence provided by the software user. # ReverseComp.pl => takes DNA sequence from user # and returns the reverse complement § Program tasks: print (“Please input DNA sequence:n”); (1) Obtain DNA sequence from user. $DNA = <STDIN>; $DNA =~ tr/ATGC/TACG/; # Find complement of DNA sequence (2) Calculate the complement of the DNA sequence. • A => T; T => A; G => C; C => G $DNA = reverse($DNA); # Reverse DNA sequence (3) Reverse the order of the DNA sequence. print (“Reverse complement of sequence is:n”); print $DNA . “n”; (4) Output the calculated reverse complement DNA sequence to user. Exact Sequence Matching Algorithm in Perl Perl code: # @DNA_Q is an array containing each nucleotide of the query sequence as an # array element (from user) # @DNA_T is an array containing each nucleotide of the chromosome sequence as # an array element. # Find length of Query and Template (Chromosome) arrays $length_Q = scalar @DNA_Q; $length_T = scalar @DNA_T; # Initialize number of matches counting variable $num_matches = 0; # Search for sequence match and print position of match if found. for ($i = 0; $i < = ($length_T - $length_Q); $i++) { for ($j = 0; $j < $length_Q && $DNA_Q[$j] eq $DNA_T[($i + $j)]; $j++) { if ($j == ($length_Q - 1)) { print ("Found match at position $i in chromosomen"); $num_matches++; } } }