1 / 18

Bioinformatics

Bioinformatics. Introduction to Perl. Introduction. What is Perl Basic concepts in Perl syntax: variables, strings, Use of strict ( explicit variables) and warnings Basic input and output Read and writing to a File. Computer programming. Perl is a high level [scripting] language

Download Presentation

Bioinformatics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bioinformatics Introduction to Perl

  2. Introduction • What is Perl • Basic concepts in Perl syntax: • variables, strings, • Use of strict (explicit variables) and warnings • Basic input and output • Read and writing to a File

  3. Computer programming • Perl is a high level [scripting] language • Perl is an interpreted language • Very good string handling [feature] functionality and other features [functionality] which we will cover later. • This makes it suitable for bioinformatics

  4. A typical bioinformatics file: FASTA format • Name of the following file is: DNA_sequence .fasta • >gi|34529|emb|Y00477.1| Human bone marrow serine protease gene (medullasin) (leukocyte neutrophilelastase gene) • TTGTCAGAGCCCCAGCTGGTGTCCAGGGACTGACCGTGAGCCTGGGTGAAAGTGAGTTCCCCGTTGGAGGCACCAGACGAGGAGAGGATGGAAGGCCTGGCCCCCAAGAATGAGCCCTGAGGTTCAGGAGCGGCTGGAGTGAGCCGCCCCCAGATCTCCGTCCAGCTGCGGGTCCCAGAGGCCTGGGTTACACTCGGAGCTCCTGGGGGAGGCCCTTGACGTGCTCAGTTCCCAAACAGGAACCCTGGGAAGGACCAGAGAAGTGCCTATTGCGCAGTGAGTGCCCGACACAGCTGCATGTGGCCGGTATCACAGGGCCCTGGGTAAACTGAGGCAGGCGACACAGCTGCATGTGGCCGGTATCACAGGGCCCTGGGTAAACTGAGGCAGGCGACACAGCTGCATGTGGCCGGTATCACAGGGCCCTGGGTAAACTGAGGCAGGCGACACAGCTGCATGTGGCCGGTATCACAGGGCCCTGGGTAAACTGAGGCAGGCGACACAGCTGCATGTGGCCGGTATCACGGGGCCCTGGATAAACAGAGGCAGGCGAGGCCACCCCCATCAAG…… • The line in Bold is the “descriptor line” • The rest are nucleotides bases • The Y00477.1 gene has over 5292 bp [most not shown here but can be found in file] • Need to analyse such files and Perl as we will see is suited to manipulating such files. • Note: FASTA files also exist for proteins

  5. Variables: $variable_name • A variable is a location in memory that can store a value • A Number: (1, 1.2) • A string (text) AATTAAGGA or ‘I like blablabla …’ • In perl to use a “basic” variable use: • $variable_name • The $variable_name [memory location] can be assigned a value • There is no distinction between basic data types. • $variable_name = ‘ my name is Denis’; ( = is the assign operator) • $variable_name = 5.1;

  6. “explicit” variable • The &variable is referred to as a global variable and it may lead to problems; for example if I entered &varaible = 5; it would not change the value of &variable and nor would the compiler detect an error. • It is better to use my &variable as it gives greater control if used with: use strict; and use warnings.

  7. Using Strict • Example 1: • #!/usr/bin/perl • # using strict and my $variables • use strict; • use warnings; • my $variable = 5; • print "the value of the variable is: ",$varaible; • Example 2: • #!/usr/bin/perl • # using strict and my $variables • my $variable = 5; • print "the value of the variable is: ",$varaible;

  8. Example 1 Example 2

  9. Using Strict • Example 3: (Write and Run Program) • #!/usr/bin/perl • # using strict and my $variables • use strict; • use warnings; • my $variable = 5; • print "the value of the variable is: ",$variable;

  10. Variables: $variable_name • The “value” associated with the variable can be assigned new values • $variable_name = 3.7; or $variable = ‘ I like … ‘; • If the value of the variable is a number Arithmetic operators can be applied: • +, • -, • *, • / , • **( exponentiation); • % modulus (the remainder after dividing; 3%2 is 1)

  11. Arithmetic example Code output • #!/usr/bin/perl • #evaluating expressions in print (# comment line symbol) • $ x = 15; • $y = 8; • print “the value of x is “, $x , “\n”; • print “ the new value of x is “, $x + 3, “\n”; • print “the sum of x and y is “, $x + $y, “\n”; • print “the product of x and y is “, $x*$y, “\n”; • (ArithmeticExample.pl)

  12. Format output • Double v single quotation marks • Sometimes we want to print a “ quotation“ so in perl it is done using ‘ ‘: • Print ’ ”the end justifies the means “ \n’; • More on output (refer to OutputExample.pl): • #!/usr/bin/perl • # formating output example • Print ’ ”the end justifies the means “ \n’; • $x = "I am from Cork "; #declare a string • $y = "my name is Denis"; #declare another string • print "the value of $x is $x\n"; • print "the value of \$x is $x\n"; # note the \$x • print "the value of \$y concatenated to \$x is $y$x\n";

  13. Output from OutputExample.pl

  14. Inputting Data (assign data to a variable) • This is where data can be typed in from the keyboard, read from a file or “hardcode” into the program • Perl reads text files – including FASTA files. • Reads input one line at a time this includes the return key (carriage return/End of line ) • Read data from the key board • #!/usr/bin/perl : This line must be at the start of each program. • $var = <> ; (input a line of characters and assign it to $var) • Chomp $var removes the return character from the line. • Use both of these statements together • Alternatively you can combine both statements together • chomp($var = <>);

  15. display contents from a file • Normally you open a file and read/write to the file. However perl can put the name of the file as one of the “arguments” in the command line; let us consider a file called text1.txt • Perl code: • $variable = <> (same as that for inputin g form the keyboard) • At the Command line type • C:\directory> Input.pl text1.txt

  16. Exercise 1 • Declare 3 ($x, $y and $z) variables and assign them the following values: 12, 6, 8. • Perform and print the results of the following arithmetic operations • $x to the power of $y • $x modulus % $y • $x modulus $z • &x plus $y plus $z and assign it to a new variable ($a) • Perform one other simple arithmetic operation of your choice

  17. Exercise 2 • Ask user to input a line of text from the keyboard and assign it to a variable • Display the “value” that was assigned to the variable • Run the above with only the name on the command line • Re run the program with a text file as one of the arguments.

  18. Useful link • http://www.perl.org/books/beginning-perl/ • perl tutorial book • http://www.webbasedprogramming.com/Perl-Quick-Reference/ch3.htm • This link covers all languages including perl

More Related