Places To Put Things Exploring Perl's Built-In Variable Containers: Arrays and Hashes.

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Arrays Strings and regular expressions Basic PHP Syntax CS380 1.
1 Perl: arrays. 2 #!/usr/bin/perl -w # bind3.pl # # Here's an example that takes a unix path ($file) # and copies it to anothe variable ($filename) #
Dynamic Arrays Lecture 4. Arrays In many languages the size of the array is fixed however in perl an array is considered to be dynamic: its size can be.
Perl Arrays and Lists Software Tools. Slide 2 Lists l A list is an ordered collection of scalar data. l A list begins and ends with parentheses, with.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Perl Arrays and Lists Learning Objectives: 1. To understand the format and the declaration of Arrays & Lists in Perl 2. To distinguish the difference between.
Bioinformatics Lecture 7: Introduction to Perl. Introduction Basic concepts in Perl syntax: – variables, strings, input and output – Conditional and iteration.
Perl Hashes Software Tools. Slide 2 “bill” “cheap” What is a Hash? l A hash (or associative array) is like an array, where the index can be any scalar.
Scripting Languages Chapter 5 Hashes. Hash Data structure, not unlike an array – it will hold any number of values It indexes values by name – not by.
Signal Processing Problems in Genomics Mohammad Al Bataineh Illinois Institute of Technology Chicago, IL.
Hashes a “hash” is another fundamental data structure, like scalars and arrays. Hashes are sometimes called “associative arrays”. Basically, a hash associates.
Sorting. Simple Sorting As you are probably aware, there are many different sorting algorithms: selection sort, insertion sort, bubble sort, heap sort,
CSE S. Tanimoto Perl Arrays, Functions, Lists, Refs, Etc 1 Perl: Arrays, Functions, References, Etc. Arrays Slices, splices Contexts: list, scalar.
1 An Introduction to Perl Part 2 CSC8304 – Computing Environments for Bioinformatics - Lecture 8.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
CPTG286K Programming - Perl Chapter 3: Arrays and List Data.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Chapter 6 Genes and Gene Technology
– Introduction to Perl 10/20/ Introduction to Perl - Lists and Arrays Introduction to Perl Session 3 · lists and arrays.
DNA Bases. Adenine: Adenine: (A) pairs with Thymine (T) only.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
CS 368 – Intro to Scripting Languages Summer 2009 Cartwright, De Smet, LeRoy 1 Day 3: Collections suggested reading: Learning Perl (4th Ed.), Chapter 3:
Built-in Data Structures in Python An Introduction.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
1 96-Summer 生物資訊程式設計實習 ( 二 ) Bioinformatics with Perl 8/13~8/22 蘇中才 8/24~8/29 張天豪 8/31 曾宇鳯.
CPTG286K Programming - Perl Chapter 5 & 6: Hashes & Basic I/O.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Topic 3: Lists and arrays CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 3, pages 40-55, 86-91, Programming Perl 3rd edition.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
Introduction to DNA. Question: From your on-line computer activity, what do you know about the structure of DNA?
DNA: the Molecule of Heredity. DNA DNA is a long molecule made of repeating subunits called nucleotides Nucleotides have three parts sugar phosphate and.
Your “Do Now”2/17 Get out your KWL Take a ½ sheet of paper Write down 2 things that another person had on their KWL’s “L” column Be ready to share out.
BINF 634 Fall LECTURE061 Outline Lab 1 (Quiz 3) Solution Program 2 Scoping Algorithm efficiency Sorting Hashes Review for midterm Quiz 4 Outline.
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
CSC 4630 Perl 2 adapted from R. E. Beck. I/O and Arithmetic Form pairs of programmer/investigator/discover Exercise 1. Write a program that prompts the.
DNA Structure DNA consists of two molecules that are arranged into a ladder-like structure called a Double Helix. A molecule of DNA is made up of millions.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Working with Collections of Data
Input, Output and Other Things
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
DNA Structure.
Perl Variables: Array Web Programming.
Perl: Arrays, Functions, References, Etc.
Perl Variables: Hash Web Programming.
Perl: Arrays, Functions, References, Etc.
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Perl: Arrays, Functions, References, Etc.
DNA & The Genetic Code The sequence (order) of bases in a strand of DNA acts as a template for DNA replication and makes the code for building proteins.
Perl: Arrays, Functions, References, Etc.
Nucleic Acids.
Perl: Arrays, Functions, References, Etc.
Useful functions.
DNA Structure.
Perl: Arrays, Functions, References, Etc.
List Operation in ProLog EUSL/TC/IS/2013/COM/08. In here list will print..
Presentation transcript:

Places To Put Things Exploring Perl's Built-In Variable Containers: Arrays and Hashes

Beyond Scalars

@list_of_sequences ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' ); Arrays: Associating Data With Numbers

Maxim 4.1 Lists in Perl are comma-separated collections of scalars

Array insert array here

Maxim 4.2 Perl starts counting from zero, not one

print "$list_of_sequences[1]\n"; $list_of_sequences[1] = 'CTATGCGGTA'; $list_of_sequences[3] = 'GGTCCATGAA'; Working with array elements

The Array insert array here

print "The array size is: ", $#list_of_sequences+1, ".\n"; print "The array size is: ", ".\n"; The array size is: 4. How big is the array?

Maxim 4.3 There are three main contexts in Perl: numeric, list and scalar

@sequences = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' = 'CTATGCGGTA' ); print TTATTATGTT GCTCAGTTCT GACCTCTTAA = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' = ( 'CTATGCGGTA' ); print CTATGCGGTA Adding elements to an array

@sequences = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' = ( 'CTATGCGGTA', 'CTATTATGTC' ) ); print TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA' = ( 'GCTCAGTTCT', 'GACCTCTTAA' ); print TTATTATGTT GCTCAGTTCT GACCTCTTAA GCTCAGTTCT GACCTCTTAA Adding more elements to an array

@sequences = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'TTATTATGTT' = 1, 2; print print GCTCAGTTCT GACCTCTTAA = (); Removing elements from an array

@dnas[ 1, 4, ] Slicing arrays

#! /usr/bin/perl -w # The 'slices' program - slicing = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'CTATGCGGTA', 'ATCTGACCTC' ); ]; print = 1, 3; print print The slices program

TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC GCTCAGTTCT GACCTCTTAA CTATGCGGTA TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC TTATTATGTT ATCTGACCTC GCTCAGTTCT GACCTCTTAA CTATGCGGTA Results from slices...

Maxim 4.4 To access a list of values from an array, use a slice

Maxim 4.5 To remove a list of values from an array, use splice

#! /usr/bin/perl -w # The 'pushpop' program - pushing, popping, shifting # and = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'CTATGCGGTA', 'ATCTGACCTC' ); print $last = print $first = print $last; print ( $first, $last ); print Pushing, popping, shifting and unshifting

TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC GCTCAGTTCT GACCTCTTAA CTATGCGGTA TTATTATGTT ATCTGACCTC Results from pushpop...

#! /usr/bin/perl -w # The 'iterateW' program - iterate over an entire array # with = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'CTATGCGGTA', 'ATCTGACCTC' ); $index = 0; $last_index = $#sequences; while ( $index <= $last_index ) { print "$sequences[ $index ]\n"; ++$index; } Processing every element in an array

TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC Results from iterateW...

#! /usr/bin/perl -w # The 'iterateF' program - iterate over an entire array # with = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'CTATGCGGTA', 'ATCTGACCTC' ); foreach $value ) { print "$value\n"; } The iterateF program

Maxim 4.6 Use foreach to process every element in an array

@sequences = ( 'TTATTATGTT', 'GCTCAGTTCT', 'GACCTCTTAA', 'CTATGCGGTA', 'ATCTGACCTC' = ( TTATTATGTT, GCTCAGTTCT, GACCTCTTAA, CTATGCGGTA, ATCTGACCTC = qw( TTATTATGTT GCTCAGTTCT GACCTCTTAA CTATGCGGTA ATCTGACCTC ); Making lists easier to work with

Hashes: Associating Data With Words %bases %genomes %nucleotide_bases %nucleotide_bases = ( A, Adenine, T, Thymine );

Maxim 4.7 A hash is a collection of name/value pairings

The %nucleotide_bases Hash insert hash here

Maxim 4.8 Hash name-parts must be unique

print "The expanded name for 'A' is $nucleotide_bases{ 'A' }\n"; Working with hash entries

%nucleotide_bases = ( A, Adenine, T, Thymine = keys %nucleotide_bases; print "The names in the %nucleotide_bases hash The names in the %nucleotide_bases hash are: A T %nucleotide_bases = ( A, Adenine, T, Thymine ); $hash_size = keys %nucleotide_bases; print "The size of the %nucleotide_bases hash is: $hash_size\n"; The size of the %nucleotide_bases hash is: 2 How big is the hash?

$nucleotide_bases{ 'G' } = 'Guanine'; $nucleotide_bases{ 'C' } = 'Cytosine'; %nucleotide_bases = ( A => Adenine, T => Thymine, G => Guanine, C => Cytosine ); Adding entries to a hash

The Grown %nucleotide_bases Hash insert hash here

delete $nucleotide_bases{ 'G' }; $nucleotide_bases{ 'C' } = undef; Removing entries from a hash

%gene_counts = ( Human => 31000, 'Thale cress' => 26000, 'Nematode worm' => 18000, 'Fruit fly' => 13000, Yeast => 6000, 'Tuberculosis microbe' => Human, 'Fruit fly', 'Tuberculosis microbe' }; print Slicing hashes

#! /usr/bin/perl -w # The 'bases' program - a hash of the nucleotide bases. %nucleotide_bases = ( A => Adenine, T => Thymine, G => Guanine, C => Cytosine ); $sequence = 'CTATGCGGTA'; print "\nThe sequence is $sequence, which expands to:\n\n"; while ( $sequence =~ /(.)/g ) { print "\t$nucleotide_bases{ $1 }\n"; } Working with hash entries: a complete example

The sequence is CTATGCGGTA, which expands to: Cytosine Thymine Adenine Thymine Guanine Cytosine Guanine Thymine Adenine Results from bases...

#! /usr/bin/perl -w # The 'genes' program - a hash of gene counts. use constant LINE_LENGTH => 60; %gene_counts = ( Human => 31000, 'Thale cress' => 26000, 'Nematode worm' => 18000, 'Fruit fly' => 13000, Yeast => 6000, 'Tuberculosis microbe' => 4000 ); Processing every entry in a hash

print '-' x LINE_LENGTH, "\n"; while ( ( $genome, $count ) = each %gene_counts ) { print "`$genome' has a gene count of $count\n"; } print '-' x LINE_LENGTH, "\n"; foreach $genome ( sort keys %gene_counts ) { print "`$genome' has a gene count of $gene_counts{ $genome }\n"; } print '-' x LINE_LENGTH, "\n"; The genes program, cont.

`Human' has a gene count of `Tuberculosis microbe' has a gene count of 4000 `Fruit fly' has a gene count of `Nematode worm' has a gene count of `Yeast' has a gene count of 6000 `Thale cress' has a gene count of `Fruit fly' has a gene count of `Human' has a gene count of `Nematode worm' has a gene count of `Thale cress' has a gene count of `Tuberculosis microbe' has a gene count of 4000 `Yeast' has a gene count of Results from genes...

Where To From Here