Stream.

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Advertisements

A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Introduction to Computing Using Python Exceptions (Oops! When things go wrong)  Errors and Exceptions  Syntax errors  State (execution) errors.
CS0004: Introduction to Programming Repetition – Do Loops.
Introduction to Computing Using Python Imperative Programming  Python Programs  Interactive Input/Output  One-Way and Two-Way if Statements  for Loops.
An introduction to Python and its use in Bioinformatics Csc 487/687 Computing for Bioinformatics Fall 2005.
Group practice in problem design and problem solving
Python Control of Flow.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
List Comprehensions. Python’s higher-order functions  Python supports higher-order functions that operate on lists similar to Scheme’s >>> def square(x):
Python programs How can I run a program? Input and output.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 13 Files and Exception Handling 1.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Introduction to Computing Using Python Straight-line code  In chapter 2, code was “straight-line”; the Python statements in a file (or entered into the.
Chapter Function Basics CSC1310 Fall Function function (subroutine, procedure)a set of statements different inputs (parameters) outputs In.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Chapter 14 Advanced Function Topics CSC1310 Fall 2009.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
9/28/2015BCHB Edwards Basic Python Review BCHB Lecture 8.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Introduction to Computing Using Python Exceptions (Oops! When things go wrong)  Errors and Exceptions  Syntax errors  State (execution) errors.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CS1022 Computer Programming & Principles
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
CSc 120 Introduction to Computer Programing II Adapted from slides by
Sequence, Selection, Iteration The IF Statement
Python Comprehension and Generators
Presented By S.Yamuna AP/IT
C++, OBJECT ORIENTED PROGRAMMING
Section 6: Sequences Chapter 4 and 5.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Chapter 5: Loops and Files.
Scripts & Functions Scripts and functions are contained in .m-files
Programming Fundamentals
Introduction to Python
CHAPTER FOUR Functions.
PYTHON Varun Jain & Senior Software Engineer
Introduction to Python
Python Primer 2: Functions and Control Flow
Topics Introduction to File Input and Output
CPS120: Introduction to Computer Science
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Coding Concepts (Basics)
CSC1018F: Intermediate Python
(Oops! When things go wrong)
Introduction to Python: Day Three
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Introduction to Python
Dictionaries Dictionary: object that stores a collection of data
A Tutorial on the Python Programming Language
G. Pullaiah College of Engineering and Technology
(more) Python.
Topics Introduction to File Input and Output
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
CHAPTER 4: Lists, Tuples and Dictionaries
Python Comprehension and Generators
Introduction to Programming
The structure of programming
Topics Introduction to File Input and Output
Thinking procedurally
Introduction to Python
Presentation transcript:

Stream

Streams temporally ordered sequence of indefinite length

Files

Files Creating file objects open(path, mode) close()

Files File methods fileobj.read([count]) fileobj.readline([count]) fileobj.readlines() fileobj.write(string) fileobj.writelines(sequence)

Files : Ex1 Reading FASTA sequences from a file def read_FASTA_strings(filename): file = open(filename) return file.read().split('>')[1:] FASTA-formatted files are widely used in bioinformatics. They consist of one or more base or amino acid sequences broken up into lines of reasonable size (typically 70 characters), each preceded by a line beginning with a “>” character. That line is referred to as the sequence’s description, and it generally contains various identifiers and comments that pertain to the sequence that follows.

Generators an object that returns values from a series it computes

Collection-Related Expression Features Comprehensions creates a set, list, or dictionary from the results of evaluating an expression for each element of another collection List comprehensions [expression for item in collection] def validate_base_sequence(base_sequence, RNAflag = False): valid_bases = 'UCAG' if RNAflag else 'TCAG' return all([(base in valid_bases) for base in base_sequence.upper()])

Collection-Related Expression Features Comprehensions Set and dictionary comprehensions {expression for item in collection} {key-expression: value-expression for key, value in collection} def make_indexed_sequence_dictionary(filename): return {info[0]: seq for info, seq in read_FASTA(filename)} Generator expressions (expression for item in collection)

Collection-Related Expression Features Comprehensions Conditional comprehensions [expression for element in collection if test] def dr(name): return [nm for nm in dir(name) if nm[0] != '_'] Nested comprehensions def generate_triples(chars='TCAG'): chars = set(chars) return [b1 + b2 + b3 for b1 in chars for b2 in chars for b3 in chars]

Collection-Related Expression Features Functional Parameters The parameter "key" max(range(3, 7), key=abs) : 7 max(range(-7, 3), key=abs) : -7 lst = ['T', 'G', 'A', 'G', 't', 'g', 'a', 'g'] lst.sort() lst.sort(key=str.lower)

Collection-Related Expression Features Anonymous functions lambda args: expression-using-args def fn (x, y): return x*x + y*y fn = lambda x, y: x*x + y*y l = [(3, 'abc'), (5, 'ghijk'), (5, 'abcde'), (2, 'bd')] l.sort() l.sort(key=lambda seq: (len(seq), seq.lower())))

Control Statements

Conditionals

Loops

Loops Simple Loop Examples def echo(): while echo1(): pass line = input('Say something: ') print('You said', line) return line def polite_echo(): while echo1() != 'bye':

Initialization of Loop Values

Initialization of Loop Values def recording_echo(): # initialize entry and lst vlst = [] # get the first input entry = echo1() # test entry while entry != 'bye': # use entry lst.append(entry) # change entry # repeat # return result return lst

Looping Forever

Loops with Guard Conditions

Iterations Iteration Statements Iteration statements all begin with the keyword for

Exception Handlers def get_gi_ids(filename): with open(filename) as file: return [extract_gi_id(line) for line in file if line[0] == '>'] IOError: [Errno 2] No such file or directory: 'aa2.fasta‘

Python Errors Tracebacks Runtime errors

Exception Handling Statements