See More

{ "cells": [ { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "dc7a1635-0bbd-4bf7-a07e-7a36f58e258b" }, "slideshow": { "slide_type": "slide" } }, "source": [ "# An introduction to solving biological problems with Python" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "53eee250-b3d0-4262-ad09-e87fb2acf82e" }, "slideshow": { "slide_type": "-" } }, "source": [ "## Today's Presenters\n", "- Anne\n", "- Niall" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "21082cb9-e1b9-4fe9-80d5-9d9e8418937b" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Learning objectives\n", "- **Recall** how to print, create variables and save Python code in files\n", "- **List** the most common data types in Python\n", "- **Explain** how to use different type of collections\n", "- **Use and compare** these concepts in different code examples \n", "- **Propose and create** solutions using these concepts in different exercises" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "ceb5f5a0-a5e8-435e-ae16-23c2ba8c6ab2" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Course schedule - day one\n", "\n", "- 09:30-10:00: [0h30] **Introduction**\n", "- 10:00-10:30: [0h30] **Session 1.1** - Print and Variables\n", "- 10:30-10:45: *break*\n", "- 10:45-12:15: [1h30] **Session 1.2** - Simple data types, Arithmetic and Saving code in files\n", "- 12:15-13:30: *lunch break*\n", "- 13:30-14:30: [1h00] **Session 1.3** - Collections: Lists and String \n", "- 14:30-14:45: *break*\n", "- 14:45-15:45: [1h00] **Session 1.4** - Collections: Sets and Dictionnaries\n", "- 15:45-16:00: *break*\n", "- 16:00-17:00: [1h00] **Wrap-up** " ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "e6c2e441-eb7b-4a4c-9c9c-b88cc9a2527f" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Course schedule - day two\n", "\n", "- Conditions, Loops and Files" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "8458de53-35b5-405e-a372-5db5d2e2c2c5" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Course materials\n", "\n", "- There is a course webpage with links to the materials, example solutions to the exercises etc.:\n", " - http://pycam.github.io\n", "- All course materiel is available on GitHub in our [python-basic repo](https://github.com/pycam/python-basic)\n", "- We’d like you to follow along with the example code as we go through the material, and attempt the exercises to practice what you’ve learned\n", "- Questions are welcome at any point!\n", "- If you have specific projects/problems you like to use Python for we are happy to (try to) help during the exercises\n" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "96ca5c44-2cfc-471c-8da7-39870c822e20" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## What is *Python*?\n", "\n", "- Python is a *dynamic, interpreted* general purpose programming language initially created by Guido van Rossum in 1991\n", "- It is a powerful language that supports several popular programming paradigms:\n", " - procedural\n", " - object-oriented\n", " - functional\n", "- Python is widely used in bioinformatics and scientific computing, as well as many other fields and in industry\n", "- Python is available on all popular operating systems\n", " - Macs\n", " - Windows\n", " - Linux" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "9110098b-9675-4d64-adf3-c947073d4c4d" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## The Python programming language\n", "\n", "- Python is considered to come with \"batteries included\" and the standard library provides built-in support for lots of common tasks:\n", " - numerical & mathematical functions \n", " - interacting with files and the operating system\n", " - ..." ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "0d61b4b4-163f-47fe-80f1-092287218273" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Getting started\n", "\n", "- Python is an *interpreted* language, this means that your computer does not run Python code natively, but instead we run our code using the Python interpreter\n", "- There are three ways in which you can run Python code:\n", " - Directly typing **commands into the interpreter**: *Good for experimenting with the language, and for some interactive work*\n", " - Using a **Jupyter notebook**: *Great for experimenting with the language, and for sharing and learning*\n", " - Typing code **into a file** and then telling the interpreter to run the code from this file: *Good for larger programs, and when you want to run the same code repeatedly*\n" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "b878a4f9-4345-4abb-81f4-5a731c639ab8" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## How to start the Python interpreter?\n", "\n", "- How you start the interpreter will depend on which operating system you are using, but on a Mac or Linux machine you should start a terminal and then just type the command `python3`\n", "- This will print out some information about your installation of python and then leave you with a command prompt which looks like `>>>` \n", "- You can then type commands and press `Enter` when you're done. Python will run the code you typed, and might display some output on the line below, before leaving you with another prompt.\n", "- If you want to exit the interactive interpreter you can type the command `quit()` or type `Ctrl-D`" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "8a4ac456-6c4b-4249-8662-b1cabfd7cee4" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## The terminal\n", "\n", "We will see later how to save code in a file and run it.\n", "

" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "f5bcbcb5-4352-4674-a7b6-c8e576220422" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## The shell command lines you may need\n", "\n", "- `ls`: to list directory contents\n", "- `pwd`: to return working directory name\n", "- `cd to/this/directory/`: to change directory\n", "- `cat hello.py`: to print the content of a text file \n" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "9814e8d7-60e0-43e6-aee0-3c33cc2cc809" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## What is a Jupyter notebook?\n", "\n", "\n", "\n", "- The [Jupyter Notebook](http://jupyter.org/) is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. \n", "\n", "- Jupyter provides a rich architecture for interactive data science and scientific computing with: \n", " - Over 40 programming languages such as Python, R, Julia and Scala.\n", " - A browser-based notebook with support for code, rich text, math expressions, plots and other rich media.\n", " - Support for interactive data visualization.\n", " - Easy to use tools for parallel computing." ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "62fdd00c-a006-4f11-b9dc-e2ca072225d7" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## How to install Jupyter on your own computer?\n", "\n", "\n", "\n", "- [See Installing Jupyter Notebook](https://jupyter.readthedocs.io/en/latest/install.html)\n", "\n", "- For new users, we recommend [installing Anaconda](https://www.continuum.io/downloads). Anaconda conveniently installs Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science.\n", "\n", "- Start the notebook server from the command line:\n", "```\n", "jupyter notebook\n", "```\n", "- You should see the notebook home page open in your web browser.\n" ] }, { "cell_type": "markdown", "metadata": { "nbpresent": { "id": "0e25dad3-add0-466e-8f71-e771d6ec4500" }, "slideshow": { "slide_type": "slide" } }, "source": [ "## How to run python in a Jupyter notebook?\n", "\n", "\n", "\n", "- See [Jupyter Notebook Basics](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Notebook%20Basics.ipynb)\n", "\n", "\n", "- Go to our notebook for the fist session: [python_basic_1_1](python_basic_1_1.ipynb)" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" }, "nbpresent": { "slides": { "152c5a3b-78f9-4183-bce2-379a4012baf6": { "id": "152c5a3b-78f9-4183-bce2-379a4012baf6", "layout": "grid", "prev": "5613e857-5b4e-42e4-9feb-df0440592ca2", "regions": { "20d6059c-7745-410d-a5fb-0b91cacbc2e2": { "attrs": { "height": 0.6666666666666666, "pad": 0.01, "treemap:weight": 1, "width": 0.5, "x": 0, "y": 0 }, "id": "20d6059c-7745-410d-a5fb-0b91cacbc2e2" }, "300e6ccd-ecf4-425e-8574-3debe305aafb": { "attrs": { "height": 0.3333333333333333, "pad": 0.01, "treemap:weight": 1, "width": 1, "x": 0, "y": 0.6666666666666666 }, "content": { "cell": "9814e8d7-60e0-43e6-aee0-3c33cc2cc809", "part": "whole" }, "id": "300e6ccd-ecf4-425e-8574-3debe305aafb" }, "df2dd6ff-570b-4b75-9cb7-1ff1dbdd4f55": { "attrs": { "height": 0.6666666666666666, "pad": 0.01, "treemap:weight": 1, "width": 0.5, "x": 0.5, "y": 0 }, "id": "df2dd6ff-570b-4b75-9cb7-1ff1dbdd4f55" } } }, "2586ca7d-5091-40ea-b566-ccc5fbf833c6": { "id": "2586ca7d-5091-40ea-b566-ccc5fbf833c6", "prev": "f001d476-5814-4664-a722-f04f5d23cd52", "regions": { "d6011048-43db-4990-a82e-768683aa4fe5": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "ceb5f5a0-a5e8-435e-ae16-23c2ba8c6ab2", "part": "whole" }, "id": "d6011048-43db-4990-a82e-768683aa4fe5" } } }, "27ee4130-d0bb-4287-b8fe-75a7b0ecf178": { "id": "27ee4130-d0bb-4287-b8fe-75a7b0ecf178", "prev": "2586ca7d-5091-40ea-b566-ccc5fbf833c6", "regions": { "7a689d66-0c9d-4492-928b-f35bfd2ffc4c": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "e6c2e441-eb7b-4a4c-9c9c-b88cc9a2527f", "part": "whole" }, "id": "7a689d66-0c9d-4492-928b-f35bfd2ffc4c" } } }, "2de0c027-7a07-4f7e-8594-a98d36125372": { "id": "2de0c027-7a07-4f7e-8594-a98d36125372", "prev": "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8", "regions": { "868fd842-e6fb-48b2-9ac5-95e8fe20927e": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "0e25dad3-add0-466e-8f71-e771d6ec4500", "part": "whole" }, "id": "868fd842-e6fb-48b2-9ac5-95e8fe20927e" } } }, "5613e857-5b4e-42e4-9feb-df0440592ca2": { "id": "5613e857-5b4e-42e4-9feb-df0440592ca2", "prev": "564dae42-4185-46c1-b156-e503f475e25c", "regions": { "17e888b0-050b-406a-a5a3-0d5c1605b8df": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "f5bcbcb5-4352-4674-a7b6-c8e576220422", "part": "whole" }, "id": "17e888b0-050b-406a-a5a3-0d5c1605b8df" } } }, "564dae42-4185-46c1-b156-e503f475e25c": { "id": "564dae42-4185-46c1-b156-e503f475e25c", "prev": "ba285213-f645-4314-afd5-0a656fa35631", "regions": { "328d4d72-cd9e-4e5b-aaa8-175833f5bfdb": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "8a4ac456-6c4b-4249-8662-b1cabfd7cee4", "part": "whole" }, "id": "328d4d72-cd9e-4e5b-aaa8-175833f5bfdb" } } }, "6ff94ac3-8ded-442e-ae43-aa0a5c14d468": { "id": "6ff94ac3-8ded-442e-ae43-aa0a5c14d468", "prev": "27ee4130-d0bb-4287-b8fe-75a7b0ecf178", "regions": { "ad759b3a-6080-4356-a9fd-87f2b1b90bc2": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "8458de53-35b5-405e-a372-5db5d2e2c2c5", "part": "whole" }, "id": "ad759b3a-6080-4356-a9fd-87f2b1b90bc2" } } }, "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8": { "id": "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8", "prev": "152c5a3b-78f9-4183-bce2-379a4012baf6", "regions": { "4afd3b41-071f-44eb-a8f6-9a7f780041c2": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "62fdd00c-a006-4f11-b9dc-e2ca072225d7", "part": "whole" }, "id": "4afd3b41-071f-44eb-a8f6-9a7f780041c2" } } }, "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1": { "id": "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1", "prev": "e2f5626f-0d60-47cb-967f-0edababb0329", "regions": { "af33776f-ec36-45be-a627-39573a78b1d6": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "0d61b4b4-163f-47fe-80f1-092287218273", "part": "whole" }, "id": "af33776f-ec36-45be-a627-39573a78b1d6" } } }, "ae3f4c01-80dc-4add-889a-05c74f7155a5": { "id": "ae3f4c01-80dc-4add-889a-05c74f7155a5", "prev": "6ff94ac3-8ded-442e-ae43-aa0a5c14d468", "regions": { "15f00a98-7b04-439d-996d-851b773b060a": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "96ca5c44-2cfc-471c-8da7-39870c822e20", "part": "whole" }, "id": "15f00a98-7b04-439d-996d-851b773b060a" } } }, "ba285213-f645-4314-afd5-0a656fa35631": { "id": "ba285213-f645-4314-afd5-0a656fa35631", "prev": "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1", "regions": { "6cddb9f2-8e39-4010-8fab-3e70b3a8993f": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "b878a4f9-4345-4abb-81f4-5a731c639ab8", "part": "whole" }, "id": "6cddb9f2-8e39-4010-8fab-3e70b3a8993f" } } }, "cd587236-8a19-444d-8b18-69d782dbf725": { "id": "cd587236-8a19-444d-8b18-69d782dbf725", "prev": null, "regions": { "ef377bfe-ff45-49db-b471-f79ecb10b580": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "dc7a1635-0bbd-4bf7-a07e-7a36f58e258b", "part": "whole" }, "id": "ef377bfe-ff45-49db-b471-f79ecb10b580" } } }, "e2f5626f-0d60-47cb-967f-0edababb0329": { "id": "e2f5626f-0d60-47cb-967f-0edababb0329", "prev": "ae3f4c01-80dc-4add-889a-05c74f7155a5", "regions": { "eef49fa0-0f9b-4228-8fb8-79e079bf7682": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "9110098b-9675-4d64-adf3-c947073d4c4d", "part": "whole" }, "id": "eef49fa0-0f9b-4228-8fb8-79e079bf7682" } } }, "f001d476-5814-4664-a722-f04f5d23cd52": { "id": "f001d476-5814-4664-a722-f04f5d23cd52", "prev": "cd587236-8a19-444d-8b18-69d782dbf725", "regions": { "5a176076-c5a5-4b50-ab2c-9cd0baedad45": { "attrs": { "height": 0.8, "width": 0.8, "x": 0.1, "y": 0.1 }, "content": { "cell": "53eee250-b3d0-4262-ad09-e87fb2acf82e", "part": "whole" }, "id": "5a176076-c5a5-4b50-ab2c-9cd0baedad45" } } } }, "themes": { "default": "c6b5d1ad-d691-4000-9f62-de7fc0e83644", "theme": { "586a6e7a-f661-4d6c-90d0-1392715bea27": { "id": "586a6e7a-f661-4d6c-90d0-1392715bea27", "palette": { "19cc588f-0593-49c9-9f4b-e4d7cc113b1c": { "id": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", "rgb": [ 252, 252, 252 ] }, "31af15d2-7e15-44c5-ab5e-e04b16a89eff": { "id": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", "rgb": [ 68, 68, 68 ] }, "50f92c45-a630-455b-aec3-788680ec7410": { "id": "50f92c45-a630-455b-aec3-788680ec7410", "rgb": [ 155, 177, 192 ] }, "c5cc3653-2ee1-402a-aba2-7caae1da4f6c": { "id": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "rgb": [ 43, 126, 184 ] }, "efa7f048-9acb-414c-8b04-a26811511a21": { "id": "efa7f048-9acb-414c-8b04-a26811511a21", "rgb": [ 25.118061674008803, 73.60176211453744, 107.4819383259912 ] } }, "rules": { "blockquote": { "color": "50f92c45-a630-455b-aec3-788680ec7410" }, "code": { "font-family": "Anonymous Pro" }, "h1": { "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "font-family": "Lato", "font-size": 8 }, "h2": { "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "font-family": "Lato", "font-size": 6 }, "h3": { "color": "50f92c45-a630-455b-aec3-788680ec7410", "font-family": "Lato", "font-size": 5.5 }, "h4": { "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "font-family": "Lato", "font-size": 5 }, "h5": { "font-family": "Lato" }, "h6": { "font-family": "Lato" }, "h7": { "font-family": "Lato" }, "pre": { "font-family": "Anonymous Pro", "font-size": 4 } }, "text-base": { "font-family": "Merriweather", "font-size": 4 } }, "c6b5d1ad-d691-4000-9f62-de7fc0e83644": { "backgrounds": { "dc7afa04-bf90-40b1-82a5-726e3cff5267": { "background-color": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", "id": "dc7afa04-bf90-40b1-82a5-726e3cff5267" } }, "id": "c6b5d1ad-d691-4000-9f62-de7fc0e83644", "palette": { "19cc588f-0593-49c9-9f4b-e4d7cc113b1c": { "id": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", "rgb": [ 252, 252, 252 ] }, "31af15d2-7e15-44c5-ab5e-e04b16a89eff": { "id": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", "rgb": [ 68, 68, 68 ] }, "50f92c45-a630-455b-aec3-788680ec7410": { "id": "50f92c45-a630-455b-aec3-788680ec7410", "rgb": [ 197, 226, 245 ] }, "c5cc3653-2ee1-402a-aba2-7caae1da4f6c": { "id": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "rgb": [ 43, 126, 184 ] }, "efa7f048-9acb-414c-8b04-a26811511a21": { "id": "efa7f048-9acb-414c-8b04-a26811511a21", "rgb": [ 25.118061674008803, 73.60176211453744, 107.4819383259912 ] } }, "rules": { "a": { "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c" }, "blockquote": { "color": "50f92c45-a630-455b-aec3-788680ec7410", "font-size": 3 }, "code": { "font-family": "Anonymous Pro" }, "h1": { "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", "font-family": "Merriweather", "font-size": 8 }, "h2": { "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", "font-family": "Merriweather", "font-size": 6 }, "h3": { "color": "50f92c45-a630-455b-aec3-788680ec7410", "font-family": "Lato", "font-size": 5.5 }, "h4": { "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", "font-family": "Lato", "font-size": 5 }, "h5": { "font-family": "Lato" }, "h6": { "font-family": "Lato" }, "h7": { "font-family": "Lato" }, "li": { "color": "50f92c45-a630-455b-aec3-788680ec7410", "font-size": 3.25 }, "pre": { "font-family": "Anonymous Pro", "font-size": 4 } }, "text-base": { "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", "font-family": "Lato", "font-size": 4 } } } } } }, "nbformat": 4, "nbformat_minor": 1 }