diff --git a/README.md b/README.md index 24febdb..f50bea5 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,9 @@ -# An introduction to solving biological problems with Python - course materials +## Course Material: An introduction to solving biological problems with Python -Materials for the course run by the Graduate School of Life Sciences, University of Cambridge. +- Course repository: https://github.com/pajtraining/python-basic -- Course website: http://pycam.github.io/ -- Booking website: http://www.training.cam.ac.uk/ +- Course website: http://pajtraining.github.io/ +If you wish to run the course on your personal computer, here are the steps to follow to get up and running: -If you wish to run the course on your personal computer, here are the steps to follow to get up and running. - -## Clone this github project - -```bash -git clone https://github.com/pycam/python-basic.git -cd python-basic -``` - -## Dependencies - -Install Python 3 by downloading the latest version from https://www.python.org/. - -Python 2.x is legacy, Python 3.x is the present and future of the language. - -Create first a virtual environment using the [`venv` library](https://docs.python.org/3/library/venv.html). Update pip if needed, install [jupyter](http://jupyter.org/) and [RISE](https://github.com/damianavila/RISE) to get a slideshow extension into jupyter. - -***Note*** A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments. - -```bash -python3 -m venv venv -# activate your virtual environment -source venv/bin/activate -# update pip if needed -pip install --upgrade pip -# install jupyter -pip install jupyter - -# slideshow extension -pip install rise -jupyter-nbextension install rise --py --sys-prefix -jupyter nbextension enable rise --py --sys-prefix -``` - -## Usage - -Go to the directory where you've cloned this repository, activate your virtual environment and run jupyter. - -Your web browser should automatically open with this url http://localhost:8888/tree where you see the directory tree of the course with all the jupyter notebooks. - -```bash -cd python-basic -source venv/bin/activate -jupyter notebook -``` - -To shutdown jupyter, type ctrl-C into the terminal you've ran `jupyter notebook`, answer `y` and press `enter`. - -You may wish to deactivate the virtual environment, by entering into the terminal: -``` -deactivate -``` +- Course setup: https://pajtraining.github.io/python-basic-setup.html diff --git a/python_basic_1_1.ipynb b/python_basic_1_1.ipynb index f9c6192..fe5814c 100644 --- a/python_basic_1_1.ipynb +++ b/python_basic_1_1.ipynb @@ -323,7 +323,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_1_2.ipynb b/python_basic_1_2.ipynb index 1651f65..233266a 100644 --- a/python_basic_1_2.ipynb +++ b/python_basic_1_2.ipynb @@ -48,9 +48,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "i = -7\n", @@ -70,9 +68,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 3.14159\n", @@ -90,9 +86,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "k = 1.5e3\n", @@ -115,9 +109,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "s = \"ATGTCGTCTACAACACT\"\n", @@ -140,9 +132,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "a = True\n", @@ -162,9 +152,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "z = None\n", @@ -183,9 +171,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "a = True\n", @@ -195,9 +181,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "i = -7\n", @@ -207,9 +191,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 12.7893\n", @@ -219,9 +201,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "s = \"ATGTCGTCTACAACACT\"\n", @@ -231,9 +211,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "z = None\n", @@ -254,9 +232,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "print(\"Hi\") # this will be ignored\n", @@ -282,9 +258,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 4.5\n", @@ -300,9 +274,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 4.5\n", @@ -325,9 +297,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 13\n", @@ -348,9 +318,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "13 + 5.0" @@ -366,9 +334,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "float(3) + float(7)" @@ -377,9 +343,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "int(3.14159) + 1" @@ -395,9 +359,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "print('number' + str(3))" @@ -413,9 +375,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "print(\"3/4 =\", 3/4) # in Python 2, you would get 0\n", @@ -433,9 +393,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 3\n", @@ -446,9 +404,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 2\n", @@ -554,7 +510,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_1_3.ipynb b/python_basic_1_3.ipynb index 407ae37..711772f 100644 --- a/python_basic_1_3.ipynb +++ b/python_basic_1_3.ipynb @@ -746,7 +746,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_1_4.ipynb b/python_basic_1_4.ipynb index 4296d3f..239463a 100644 --- a/python_basic_1_4.ipynb +++ b/python_basic_1_4.ipynb @@ -382,7 +382,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_1_intro.ipynb b/python_basic_1_intro.ipynb index 954dbb3..bd02c4e 100644 --- a/python_basic_1_intro.ipynb +++ b/python_basic_1_intro.ipynb @@ -14,22 +14,6 @@ "# 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", - "- Cristian" - ] - }, { "cell_type": "markdown", "metadata": { @@ -103,9 +87,7 @@ "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", + "- All course materiel is available on GitHub in our [python-basic repo](https://github.com/pajtraining/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" @@ -320,7 +302,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" }, "nbpresent": { "slides": { diff --git a/python_basic_2_1.ipynb b/python_basic_2_1.ipynb index 5442975..905433e 100644 --- a/python_basic_2_1.ipynb +++ b/python_basic_2_1.ipynb @@ -404,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_2_2.ipynb b/python_basic_2_2.ipynb index b8dbdd5..cd0aeb7 100644 --- a/python_basic_2_2.ipynb +++ b/python_basic_2_2.ipynb @@ -563,7 +563,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_2_3.ipynb b/python_basic_2_3.ipynb index 2d4bd34..949d157 100644 --- a/python_basic_2_3.ipynb +++ b/python_basic_2_3.ipynb @@ -286,7 +286,7 @@ "source": [ "## Exercises 2.3.1\n", "\n", - "Write a script that reads a file containing many lines of nucleotide sequence. For each line in the file, print out the line number, the length of the sequence and the sequence (There is an example file here or in `data/dna.txt` from the course materials )." + "Write a script that reads a file containing many lines of nucleotide sequence. For each line in the file, print out the line number, the length of the sequence and the sequence (There is an example file in `data/dna.txt` from the course materials )." ] }, { @@ -385,7 +385,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_2_4.ipynb b/python_basic_2_4.ipynb index aeb347f..4ccdebb 100644 --- a/python_basic_2_4.ipynb +++ b/python_basic_2_4.ipynb @@ -186,10 +186,8 @@ "### A big thank you!\n", "\n", "### Remember...\n", - "- Our course webpage: http://pycam.github.io\n", - "- The Python website: https://www.python.org/ \n", - "- To fill the course survey ;-)\n", - "- To come to our next course 'Working with Python: functions and modules' and register at https://training.csx.cam.ac.uk/" + "- Our course webpage: https://pajtraining.github.io/\n", + "- The Python website: https://www.python.org/ " ] }, { @@ -234,12 +232,7 @@ "- How many genes are there in *S.cerevisiae*?\n", "- Which is the longest and which is the shortest gene?\n", "- How many genes per chromosome? Print the number of genes per chromosome.\n", - "- For each chromosome, what is the longest and what is the shortest gene?\n", - "- For each chromosome, how many genes on the Watson strand and how many genes on the Crick strand?\n", - "\n", - "**bonus** \n", - "\n", - "- What is the chromosome with the highest gene density? You can calculate the length of each chromosome assuming that they start at 1 and they end at the end (if on the Watson strand) or at the start (if on the Crick strand) of their last gene. Then you can calculate the length of all the genes on each chromosome and the ratio between coding vs. noncoding regions." + "- For each chromosome, what is the longest and what is the shortest gene?" ] }, { @@ -266,7 +259,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/python_basic_2_intro.ipynb b/python_basic_2_intro.ipynb index af16b6c..18fbc43 100644 --- a/python_basic_2_intro.ipynb +++ b/python_basic_2_intro.ipynb @@ -10,7 +10,7 @@ "source": [ "# An introduction to solving biological problems with Python\n", "\n", - "- Our course webpage: http://pycam.github.io\n", + "- Our course webpage: https://pajtraining.github.io/\n", "- Python website: https://www.python.org/ \n", "- [Python 3 Standard Library](https://docs.python.org/3/library/index.html])" ] @@ -348,7 +348,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/solutions/pybasic_ex2_4_3.py b/solutions/pybasic_ex2_4_3.py index d5a7839..8bfebfe 100644 --- a/solutions/pybasic_ex2_4_3.py +++ b/solutions/pybasic_ex2_4_3.py @@ -33,6 +33,13 @@ print("The shortest gene is", shortest_gene, "which is", shortest, "bases long.") print("The longest gene is", longest_gene, "which is", longest, "bases long.") +# check if there's more than one shortest and longest genes +for g in genes: + if g['length'] == longest: + print('Longest gene: {}'.format(g['sys_name'])) + if g['length'] == shortest: + print('Shortest gene: {}'.format(g['sys_name'])) + # How many genes per chromosome? Print the number of genes per chromosome. unique_chrom = set(chromosomes)