Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Advertisements

 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Introduction to C Programming
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Python.
Python Programming Fundamentals
Trinity College Dublin, The University of Dublin A Brief Introduction to Scientific Programming with Python Karsten Hokamp, PhD TCD Bioinformatics Support.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Computational Linguistics Programming I.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Input, Output, and Processing
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Type accurately challenge! This is a starter activity and should take 2 minutes [ slide 1 ] 1.Can you type out the code in Code Box 2.1 with no errors.
Introduction to Programming with RAPTOR
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Variables, Expressions and Statements
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Trinity College Dublin, The University of Dublin GE3M25: Data Analysis, Class 4 Karsten Hokamp, PhD Genetics TCD, 07/12/2015
GE3M25: Computer Programming for Biologists Python, Class 5
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Trinity College Dublin, The University of Dublin Data download: bioinf.gen.tcd.ie/GE3M25/project Get.fastq.gz file associated with your student ID
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 4 Karsten Hokamp, PhD Genetics TCD, 01/12/2015.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Getting Started With Python Brendan Routledge
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Development Environment
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Whatcha doin'? Aims: To start using Python. To understand loops.
Topics Designing a Program Input, Processing, and Output
Introduction to Programming
Python: Experiencing IDLE, writing simple programs
Variables, Expressions, and IO
T. Jumana Abu Shmais – AOU - Riyadh
Topics Designing a Program Input, Processing, and Output
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
CSCI N207 Data Analysis Using Spreadsheet
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
12th Computer Science – Unit 5
Input and Output Python3 Beginner #3.
Introduction to Python
Programming for Business Computing Introduction
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015

Trinity College Dublin, The University of Dublin GE3M25 Data Handling Module Content Python Programming Bioinformatics ChIP-Seq analysis

Trinity College Dublin, The University of Dublin GE3M25 Data Handling Module Content Python Programming Bioinformatics ChIP-Seq analysis Evaluation: 1.Weekly tasks 2.Project report

Trinity College Dublin, The University of Dublin Overview Programming First Python script/program Why Python? Examples Additional resources

Trinity College Dublin, The University of Dublin Overview Programming First Python script/program Why Python? Examples Additional resources

Trinity College Dublin, The University of Dublin What is programming and why bother?  Data processing  Automation  Combination of programs for analysis pipelines  More control and flexibility  Better understanding of how programs work

Trinity College Dublin, The University of Dublin Programming Concepts  Turn into a very meticulous problem solver  Break problems into small details  Keep it variable  Give very precise instructions

Trinity College Dublin, The University of Dublin Programming Concepts "human" recipe

Trinity College Dublin, The University of Dublin Programming Concepts "computerised" recipe

Trinity College Dublin, The University of Dublin Mac for Windows users The main differences:  cmd instead of ctrl (e.g. cmd-C for copying)  right-click mouse: ctrl-click  hashtag (#): alt-3  switch between applications: cmd-tab  Spotlight (top right) for finding files/programs  Apple symbol (top left) for logging out

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment open through Spotlight

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment Alternatively: open through Finder

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment interactive Python console

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment simple Python statement

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment user input output

Trinity College Dublin, The University of Dublin Simple Operations try a few simple numeric operations try a few simple numeric operations user input output

Trinity College Dublin, The University of Dublin Simple Operations repeat/combine previous commands by clicking into them and hitting return (use left/right arrows and delete to edit them) repeat/combine previous commands by clicking into them and hitting return (use left/right arrows and delete to edit them)

Trinity College Dublin, The University of Dublin Special Operators 13 / 5 = 2.6 = 2 * // 5 = 2 13 % 5 = 3 floor division modulus

Trinity College Dublin, The University of Dublin EXERCISE: Print greetings to the screen Tip: Use the built-in function 'print'

Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment Console vs Editor ConsoleEditor interactiverequires extra click for running great for trying out codeadditional IDLE functionality not suited for long scriptssuited for long scripts no saving of codeallows to save code

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts open a new file

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts Opening bracket triggers 'call tip'

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts Quotes needed around words/sentences!

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts First Python script!

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts run your code shortcut: F5

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts save file first

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts specify a file name

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts Shortcut for save and run: cmd-S followed by F5 Shortcut for save and run: cmd-S followed by F5

Trinity College Dublin, The University of Dublin Learnt so far: IDLE allows executing Python code Python understands mathematical operators Floor division and modulus Scripts can be saved in files and run within IDLE Shortcuts: cmd-S and F5 Comments start with hashtag Character strings enclosed by quotes Built-in function 'print' for writing messages

Trinity College Dublin, The University of Dublin Why Python?  easy to learn  great for beginners  enforces clean coding  great for teachers  comes with IDE  avoids command-line usage  object-orientated  code reuse and recycling  very popular  many peers  BioPython  many bioinformatics modules

Trinity College Dublin, The University of Dublin Python Help

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts make it personal

Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts built-in function prints message waits for user input built-in function prints message waits for user input variable stores user input variable stores user input variable content gets printed to screen

Trinity College Dublin, The University of Dublin Single vs Double Quotes Can you use single quotes here?

Trinity College Dublin, The University of Dublin Escaping special meaning of characters Now you can!

Trinity College Dublin, The University of Dublin EXERCISE: Can you print an exclamation mark at the end?

Trinity College Dublin, The University of Dublin SOLUTION: Add it as a string to the list of arguments

Trinity College Dublin, The University of Dublin EXERCISE: How to get rid of the extra space?

Trinity College Dublin, The University of Dublin TIP: Check call tip by deleting and typing opening bracket. separator, space as default

Trinity College Dublin, The University of Dublin SOLUTION: sep='' (empty string) Now all the spaces are gone!

Trinity College Dublin, The University of Dublin SOLUTION: sep='' (empty string) add an extra space here

Trinity College Dublin, The University of Dublin Learnt so far: Variables store and release values Functions take arguments and parameters Built-in function 'input' The computer knows nothing. The devil is in the detail!

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Description: Write a script that asks the user for two numbers and prints out the sum of them.

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Pseudocode: - receive two numbers - calculate sum - print result to screen

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Refine Pseudocode: -Prompt user for first number and store in variable -Prompt user for second number and store in variable -Calculate and store sum of two numbers -Print numbers and sum to screen

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Put pseudocode as comments into new file: Save script, e.g. calculator.py

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Add code after each comment line: Save and run (cmd-s + F5) often!

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator First attempt: Not what we want!

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Better: What about non-integers?

Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Even better: Works also for integers!

Trinity College Dublin, The University of Dublin Repeated calculations:

Trinity College Dublin, The University of Dublin Repeated calculations: Error when trying to run script!

Trinity College Dublin, The University of Dublin Repeated calculations: Highlight block and indent:

Trinity College Dublin, The University of Dublin Repeated calculations: Save and Run (cmd-s + F5)

Trinity College Dublin, The University of Dublin EXERCISE: Make it stop!

Trinity College Dublin, The University of Dublin Learnt so far: Start project with pseudocode Turn pseudocode into comments Save and run your script often! 'while' and ':' introduces a loop Indentation is important Editor provides formatting help

Trinity College Dublin, The University of Dublin Online courses      

Trinity College Dublin, The University of Dublin Books

Trinity College Dublin, The University of Dublin Thank You!

Trinity College Dublin, The University of Dublin Don't forget to log out!