Download presentation
Presentation is loading. Please wait.
Published byPhillip Charles Modified over 9 years ago
1
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015
2
Trinity College Dublin, The University of Dublin GE3M25 Data Handling Module Content Python Programming Bioinformatics ChIP-Seq analysis
3
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
4
Trinity College Dublin, The University of Dublin Overview Programming First Python script/program Why Python? Examples Additional resources
5
Trinity College Dublin, The University of Dublin Overview Programming First Python script/program Why Python? Examples Additional resources http://bioinf.gen.tcd.ie/GE3M25/
6
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
7
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
8
Trinity College Dublin, The University of Dublin Programming Concepts "human" recipe
9
Trinity College Dublin, The University of Dublin Programming Concepts "computerised" recipe
10
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
11
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment open through Spotlight
12
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment
13
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment Alternatively: open through Finder
14
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment interactive Python console
15
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment simple Python statement
16
Trinity College Dublin, The University of Dublin IDLE: Integrated DeveLopment Environment user input output
17
Trinity College Dublin, The University of Dublin Simple Operations try a few simple numeric operations try a few simple numeric operations user input output
18
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)
19
Trinity College Dublin, The University of Dublin Special Operators 13 / 5 = 2.6 = 2 * 5 + 3 13 // 5 = 2 13 % 5 = 3 floor division modulus
20
Trinity College Dublin, The University of Dublin EXERCISE: Print greetings to the screen Tip: Use the built-in function 'print'
21
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
22
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts open a new file
23
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts Opening bracket triggers 'call tip'
24
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts Quotes needed around words/sentences!
25
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts First Python script!
26
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts run your code shortcut: F5
27
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts save file first
28
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts specify a file name
29
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
30
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
31
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
32
Trinity College Dublin, The University of Dublin Python Help
33
Trinity College Dublin, The University of Dublin IDLE: Writing Python Scripts make it personal
34
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
35
Trinity College Dublin, The University of Dublin Single vs Double Quotes Can you use single quotes here?
36
Trinity College Dublin, The University of Dublin Escaping special meaning of characters Now you can!
37
Trinity College Dublin, The University of Dublin EXERCISE: Can you print an exclamation mark at the end?
38
Trinity College Dublin, The University of Dublin SOLUTION: Add it as a string to the list of arguments
39
Trinity College Dublin, The University of Dublin EXERCISE: How to get rid of the extra space?
40
Trinity College Dublin, The University of Dublin TIP: Check call tip by deleting and typing opening bracket. separator, space as default
41
Trinity College Dublin, The University of Dublin SOLUTION: sep='' (empty string) Now all the spaces are gone!
42
Trinity College Dublin, The University of Dublin SOLUTION: sep='' (empty string) add an extra space here
43
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!
44
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.
45
Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Pseudocode: - receive two numbers - calculate sum - print result to screen
46
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
47
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
48
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!
49
Trinity College Dublin, The University of Dublin First project: Make a Python Calculator First attempt: Not what we want!
50
Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Better: What about non-integers?
51
Trinity College Dublin, The University of Dublin First project: Make a Python Calculator Even better: Works also for integers!
52
Trinity College Dublin, The University of Dublin Repeated calculations:
53
Trinity College Dublin, The University of Dublin Repeated calculations: Error when trying to run script!
54
Trinity College Dublin, The University of Dublin Repeated calculations: Highlight block and indent:
55
Trinity College Dublin, The University of Dublin Repeated calculations: Save and Run (cmd-s + F5)
56
Trinity College Dublin, The University of Dublin EXERCISE: Make it stop!
57
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
58
Trinity College Dublin, The University of Dublin Online courses http://biopython.org/DIST/docs/tutorial/Tutorial.html http://biopython.org/DIST/docs/tutorial/Tutorial.html http://dowell.colorado.edu/education-python.html http://www.pasteur.fr/formation/infobio/python http://www.pasteur.fr/formation/infobio/python https://www.codecademy.com/tracks/python http://anh.cs.luc.edu/python/hands-on/ http://anh.cs.luc.edu/python/hands-on/ https://www.coursera.org
59
Trinity College Dublin, The University of Dublin Books
60
Trinity College Dublin, The University of Dublin Thank You! http://bioinf.gen.tcd.ie/GE3M25/
61
Trinity College Dublin, The University of Dublin Don't forget to log out!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.