Python Lab Functions Proteomics Informatics, Spring 2014 Week 6 04 th Mar, 2014

Slides:



Advertisements
Similar presentations
Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
Advertisements

Python Lab: Fundamentals Proteomics Informatics, Spring 2014 Week 3 11 th Feb, 2014
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 6: User-Defined Functions I
Introduction to Methods
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
Python Lab Pandas Library - II Proteomics Informatics, Spring 2014 Week 8 18 th Mar, 2014
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Python Lab: Control Statements Conditionals, Loops, Iterations Proteomics Informatics, Spring 2014 Week 4 18 th Feb, 2014
General Programming Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Functions CS 103 March 3, Review A function is a set of code we can execute on command to perform a specific task A function is a set of code we.
Functions CS 103. Review A function is a set of code we can execute on command to perform a specific task When we call a function, we can pass arguments.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
CPS120: Introduction to Computer Science Lecture 14 Functions.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Introduction to Computing Using Python Namespaces – Local and Global  The Purpose of Functions  Global versus Local Namespaces  The Program Stack 
Python Functions : chapter 3
Introduction to Computing Using Python Namespaces – Local and Global  The Purpose of Functions  Global versus Local Namespaces  The Program Stack 
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Function Basics. Function In this chapter, we will move on to explore a set of additional statements that create functions of our own function (subroutine,
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Programming Fundamentals Enumerations and Functions.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
Agenda 0 Today 0 Assignment 2 Due 0 Sequence Diagrams- View & Data Layers 0 Message syntax 0 Cohesion & Coupling 0 Next Week 0 Review and wrap-up 0 Structure.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Lesson 06: Functions Class Participation: Class Chat:
Exam #1 You will have exactly 30 Mins to complete the exam.
Chapter 6: User-Defined Functions I
Introduction to Programming
CS 1110 Introduction to Programming Spring 2017
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Topic: Functions – Part 2
Think What will be the output?
Functions CIS 40 – Introduction to Programming in Python
Functions.
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 Simple Functions
Lesson 06: Functions Class Chat: Attendance: Participation
Topics Introduction to Functions Defining and Calling a Void Function
Namespaces – Local and Global
Python 19 Mr. Husch.
Chapter 6: User-Defined Functions I
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Topics Introduction to Functions Defining and Calling a Function
Loops and Simple Functions
CSE 231 Lab 4.
Python 19 Mr. Husch.
Introduction to Programming
Namespaces – Local and Global
IST256 : Applications Programming for Information Systems
Functions, Procedures, and Abstraction
Presentation transcript:

Python Lab Functions Proteomics Informatics, Spring 2014 Week 6 04 th Mar, 2014

From last week… Compute Peptide Fragment Ions Problem: Given a peptide sequence and charge state, compute m/z of various b- & y- ions

Functions: Concept Named group of a set of statements May receive inputs that differ each time the function is executed Perform some computation May return some result back

Examples Built-in functions x = 10; range(x) Functions from other libraries/modules: import math; math.pow(3,2) Functions associated with other objects (actually called methods): x = [1, 3, 8, 7, 5]; x.sort() User-defined

General Syntax When defining it specify name and statements def funcName (args/params/inputs): statement 1 statement 2 … return Use indentation to demarcate a function from the rest of the code

Flow of Execution Once python interpreter has executed the “def” statement, you can “call” the services of the function anywhere in your script, and as many times as needed – ‘call’ it using the name – followed by round braces with comma-separated inputs, just like in math, f(x): funcName(args) Must be defined before calling it Detour in the program’s flow of execution (Check using ipdb)

Why write functions? Modularize and organize your code, by meaningfully dividing a long program into smaller pieces (steps of a process/procedure) – Easier to: Build Debug Read (if using meaningful and self-documenting labels/function-names) Facilitates code reuse – remove redundant code run more than once, at different time points share across the same or different projects – easier to modify

Function Design Guidelines Size – keep them short Cohesion – each function should have a single, unified purpose Coupling – each function should be independent of things outside of it. Use arguments for inputs and return for outputs

HW Assignment Add remaining neutral losses – b-nh3 – y-h2o – y-nh3 Add remaining multiply-charged fragments – y+ Write functions: – to compute neutral losses – to compute higher charged fragments

Next Class More about functions Reading/Writing files Examples