7ex.1 Hashes. 7ex.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Eyal Enter a phone number: 08-8617262.

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

A primer on Perl programming First structures (with examples)
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
Programming and Perl for Bioinformatics Part III.
10.1 References & Complex Data Structures Variable types in PERL ScalarArrayHash $number $string %hash $reference
11.1 Variable types in PERL ScalarArrayHash $number $string %hash $array[0] $hash{key}
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.
9.1 Subroutines and sorting. 9.2 A subroutine is a user-defined function. Subroutine definition: sub SUB_NAME { STATEMENT1; STATEMENT2;... } Subroutine.
Hashes a “hash” is another fundamental data structure, like scalars and arrays. Hashes are sometimes called “associative arrays”. Basically, a hash associates.
CSci 143 Sets & Maps Adapted from Marty Stepp, University of Washington
11ex.1 Modules and BioPerl. 11ex.2 sub reverseComplement { my ($seq) $seq =~ tr/ACGT/TGCA/; $seq = reverse $seq; return $seq; } my $revSeq = reverseComplement("GCAGTG");
9.1 Hash revision. 9.2 Variable types in PERL ScalarArrayHash $number $string %hash => $array[0] $hash{key}
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
8.1 References and complex data structures. 8.2 An associative array (or simply – a hash) is an unordered set of key=>value pairs. Each key is associated.
13.1 Wrapping up Running Other Programs 13.3 You may run programs using the system function: $exitValue = system("blastall.exe..."); if ($exitValue!=0)
8.1 Hashes (associative arrays). 8.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Dudi Enter a phone.
10.1 Variable types in PERL ScalarArrayHash $number $string %hash => $array[0] $hash{key}
8ex.1 References and complex data structures. 8ex.2 An associative array (or simply – a hash) is an unordered set of key=>value pairs. Each key is associated.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
MCB 5472 Psi BLAST, Perl: Arrays, Loops J. Peter Gogarten Office: BPB 404 phone: ,
9.1 Hashes. 9.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Ofir Enter a phone number: Enter.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Advanced Perl for Bioinformatics Lecture 5. Regular expressions - review You can put the pattern you want to match between //, bind the pattern to the.
1 Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Lecture 8: Basic concepts of subroutines. Functions In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements Return.
11.1 Subroutines A function is a portion of code that performs a specific task. Functions Functions we've met: $newStr = substr
Computer Programming for Biologists Class 7 Nov 27 th, 2014 Karsten Hokamp
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
1 By: Nour Hilal. Microsoft Access is a database software where data is stored in one or more Tables. A Database is a group of related Tables. Access.
File Processing - Indexing MVNC1 Indexing Jim Skon.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
Perl Challenge Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
What have we learned?. What is a database? An organized collection of related data.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
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.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
8.1 Common Errors – Exercise #3 Assuming something on the variable part of the input file. When parsing a format file (genebank, fasta or any other format),
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Perl Day 5. Arrays vs Hash Arrays are one way to store multiple things in a variable. Hashes are another. Arrays are one way to store multiple things.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
Data Collections CS 127. Lists Lists are ordered sequences of items All programming languages provide a sequence structure similar to a Python list; in.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
Maps Nick Mouriski.
C++ Review STL CONTAINERS.
Data Structures Arrays and Lists Part 2 More List Operations.
1 Resolving Collision Although collisions should be avoided as much as possible, they are inevitable Need a strategy for resolving collisions. We look.
CSE 143 Lecture 11: Sets and Maps reading:
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Python Fundamentals: Complex Data Structures Eric Shook Department of Geography Kent State University.
 Movieclip symbols are reusable pieces of flash animation  consisting usually of one or more graphic/button symbols  thus they are flash movies within.
Indexing Goals: Store large files Support multiple search keys
CSc 110, Spring 2017 Lecture 29: Sets and Dictionaries
Perl Variables: Hash Web Programming.
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
Presentation transcript:

7ex.1 Hashes

7ex.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Eyal Enter a phone number: Enter a name that will be added to the phone book: Dudu Enter a phone number: Hash Motivation

7ex.3 Let's say we want to create a phone book... Enter a name that will be search for in the phone book: Eyal The phone number of Eyal is: Hash Motivation

7ex.4 An associative array (or simply – a hash) is an unordered set of key=>value pairs. Each key is associated with a value. A hash variable name always start with a “%”: my %h = ("a"=>5, "bob"=>"zzz", 50=>"Johnny"); You can access a value by its key: print $h{50}.$h{a};Johnny5 $h{bob} = "aaa"; (modifying an existing value) $h{555} = "z"; (adding a new key-value pair) Hash – an associative array

7ex.5 An associative array (or simply – a hash) is an unordered set of key=>value pairs. Each key is associated with a value. A hash variable name always start with a “%”: my %h = ("a"=>5, "bob"=>"zzz", 50=>"Johnny"); You can ask whether a certain key exists in a hash: if (exists($h{50}))... You can delete a certain key-value pair in a hash: delete($h{50}); Hash – an associative array

7ex.6 To iterate over the values in %h foreach $value (values(%h))... To iterate over the keys in %h foreach $key (keys(%h))... For example: foreach $key (keys(%h)) { print "The key is $key\n"; print "The value is $h{$key}\n"; } The elements are given in an arbitrary order, so if you want a certain order use sort: foreach $key (sort(keys(%h)))... These functions actually return a list of values, so you = keys(%h); Iterating over hash elements

7ex.7 my %h = ("a"=>5, "bob"=>"zzz", 50=>"Johnny"); In addition you can use: = each(%h)){ print "key is $pair[0], value is $pair[1]\n" } to get an array of a key-value pair in each iteration (e.g. ("a",5) ) Iterating over hash elements

7ex.8 Let’s see how to use a hash as a phone book… (phoneBook.pl) Example

7ex.9 Class exercise 9 1. Write a script that reads a file with a list of protein names and lengths: AP_ AP_ AP_ stores the names of the sequences as hash keys, with the length of the sequence as the value. 2. Add to the script: Read another file, and print the names that appeared in both files with the same length. Give a warning if the name is the same but the length is different. 3. Write a script that reads a GenPept file, finds all JOURNAL lines, and stores in a hash the journal name (as key) and year of publication (as value): a. Store only one year value for each journal name b*.Store all years for each journal name Then print the names and years, sorted by the journal name (no need to sort the years for the same journal in b*, unless you really want to do so … )