Genome Sciences 373 Genome Informatics Quiz Section 2 April 7, 2015.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Python Programming Language
Introduction to Computing Science and Programming I
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Μαθαίνοντας Python [Κ4] ‘Guess the Number’
Genome Sciences 373 Genome Informatics Quiz Section 3 April 14, 2015.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
An Introduction to Python – Part II Dr. Nancy Warter-Perez April 21, 2005.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
General Computer Science for Engineers CISC 106 Lecture 25 Dr. John Cavazos Computer and Information Sciences 04/20/2009.
An introduction to Python and its use in Bioinformatics Csc 487/687 Computing for Bioinformatics Fall 2005.
Genome Sciences 373 Genome Informatics Quiz Section #1 March 31, 2015.
Geography 465 Assignments, Conditionals, and Loops.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Genome Sciences 373 Genome Informatics Quiz Section 5 April 28, 2015.
Python Control of Flow.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
ECS 10 10/8. Outline Announcements Homework 2 questions Boolean expressions If/else statements State variables and avoiding sys.exit(…) Example: Coin.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
If statements while loop for loop
Built-in Data Structures in Python An Introduction.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
List comprehensions (and other shortcuts) UW CSE 160 Spring 2015.
Tuples and Dictionaries Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Learning Javascript From Mr Saem
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Introduction to Python
Introduction to Decision Structures and Boolean Variables
Control Flow (Python) Dr. José M. Reyes Álamo.
Control Structures I Chapter 3
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Python: Control Structures
List comprehensions (and other shortcuts) UW CSE 160 Winter 2016.
Conditionals (if-then-else)
Arithmetic operations, decisions and looping
Introduction to Programming
Introduction to Python
CS190/295 Programming in Python for Life Sciences: Lecture 6
CISC101 Reminders Assn 3 due tomorrow, 7pm.
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Introduction to Programming
Introduction to Programming
Introduction to Python
Selection Statements.
An Introduction to Linux
Introduction to Python
Introduction to Programming
Introduction to Programming
CSE 231 Lab 9.
Presentation transcript:

Genome Sciences 373 Genome Informatics Quiz Section 2 April 7, 2015

Topics for today Questions from lecture Homework 1 due tomorrow 5pm Homework 2 assigned tomorrow Python overview: more data types

Questions about material from lecture Can python lists have strings and numbers mixed together? What are some ways of writing a newline to my program’s output? How do I decide what scores to put in my alignment scoring matrix?

More python for beginners: comments, sets, dictionaries

Commenting for beginners Your homework MUST HAVE COMMENTS It’s OK to “over-comment” Usually we put comments just above the part of the program we’re referring to In-class example

Today: data types, flow control Dictionaries Sets If/elif/else statements The importance of indenting!

Useful data type: sets Sets usually get introduced “later on” when learning to program But, they are VERY useful in bioinformatics! So we’re jumping ahead. A “set” in python implements the mathematical concept of a set [In-class example]

len(s) – cardinality or size of set s. x in s – test x for membership in s. s.issubset(t) – test whether every element in s is in t. s.issuperset(t) – test whether every element in t is in s. s.update(t) – Update set by adding all elements in t. s.add(e) – Add e to set. s.remove(e) – Remove e from set (or KeyError) compare: s.discard(e) – Remove e from set if it exists. s.clear() – Remove all items. Working with sets

s | t – new set with elements from both s and t. (a.k.a. “UNION”) s & t – new set with elements common to s and t. (a.k.a. “INTERSECTION”) s - t – new set with elements in s but not in t s ^ t – new set with elements in either s or t but not both Working with sets: part 2

In class example: State names

Dictionaries: pretty much what it sounds like Like a printed dictionary maps words to definitions, Python dictionaries map keys to associated values You can quickly “look up” the “value” associated with a “key” >>> capitals = { } >>> capitals[“WA”] = “Olympia” >>> capitals[“ID”] = “Boise” >>> capitals[“AK”] = “Juneau”

Working with dictionaries note: “random” order

Working with dictionaries, part 2 my_dict.get(k, default) – returns the value associated with k, or default if key k does not exist my_dict.items() – returns all key: value pairs as an iterator my_dict.keys() – returns all keys in the dictionary (in “random” order) my_dict.values() – returns all values in the dictionary (“random”) Values can be anything, even other dictionaries!

Python flow control: if / elif / else num = int(sys.argv[1]) if num > 0: print “input is greater than zero” elif num < 0: print “input is less than zero” else: print “input must be zero!” The order of these MUST be if  elif n  else But you only need “if” – the others are optional

Python flow control: if / elif / else num = int(sys.argv[1]) if num == 1: print “input is exactly 1” elif num == 2: print “input is exactly 2” elif num == 3: print “input is exactly 3” elif num == 4: […] else: print “input didn’t match anything I wanted!”

Doing more than one thing num = int(sys.argv[1]) if num == 1: print “input is exactly 1” prime = False even = False elif num == 2: print “input is exactly 2” prime = True even = True else: print “didn’t get a 1 or a 2”

Doing more than one thing num = int(sys.argv[1]) if num == 1: print “input is exactly 1” prime = False even = False elif num == 2: print “input is exactly 2” prime = True even = True else: print “didn’t get a 1 or a 2” a “block” of code defined by having the same indenting another block

For loops: iterating over groups of things Often you want to do something to every element of a group: Check every number to see if it’s less than some value Read the second column in every line of input Look at every key: value pair in a dictionary

Strings Lists

Note: three layers of indentation!

What is the value of current_max ? What is the value of top_gene_name?

Boolean: and, or, not Numeric:, ==, !=, >=, <= String: in, not in is greater than ==is equal to !=is NOT equal to =is greater than or equal to Comparison operators: comparing values Beware! = vs. ==

>>> seq = 'CAGGT' >>> if ('C' == seq[0]):...print 'C is first in', seq C is first in CAGGT >>> if ('CA' in seq):...print 'CA is found in', seq CA is found in CAGGT >>> if (('CA' in seq) and ('CG' in seq)):...print "Both there!“ >>> Comparison operators: examples