a = 10
a

"""
Explanation: Introduction to the jupyter notebook
<p>**Authors**: Thierry D.G.A Mondeel, Stefania Astrologo, Ewelina Weglarz-Tomczak & Hans V. Westerhoff <br/>
University of Amsterdam <br/>2017
</p>

This material is heavily based on Learning IPython for Interactive Computing and Data Visualization, second edition.
This first notebook is a fast introduction to the user interface of the Jupyter notebook. The point is to get you comfortable with executing cells of code, adding new ones and finding your way around. 
Do not focus too much on understanding the python code in this document. This is just an introduction to the user interface.
The Jupyter notebook
Jupyter notebook, formerly known as the IPython notebook, is a flexible tool that helps you create readable analyses, as you can keep code, images, comments, formulae and plots together.
For reference and if you are interested
* Main documentation of Jupyter at http://jupyter.readthedocs.org/en/latest/
* Jupyter Notebook interface explained at http://jupyter-notebook.readthedocs.org/en/latest/notebook.html
Take the tour
<span style="color:red">Assignment (5 min):</span> Take the user interface tour by clicking help > User Interface Tour 
Cell menu
The "Cell" menu has a number of menu items for running code in different ways. These include:

Run and Select Below
Run and Insert Below
Run All
Run All Above
Run All Below

Edit menu
The "Edit" menu has some common options to manage your cells. These include:
* splitting and merging cells
* Find and replace 
* Moving cells up and down (also notice the arrow keys in the toolbar)
* image inserting
Fancy menu interaction
Another way to access keyboard shortcuts, and a handy way to learn them is to use the command palette: Cmd + Shift + P (or Ctrl + Shift + P on Linux and Windows). This dialog box helps you run any command by name - useful if you don’t know the keyboard shortcut for an action or if what you want to do does not have a keyboard shortcut. Once you start using it you’ll wonder how you lived without it!
A notebook has two types of cells

A Markdown cell contains text. In addition to classic formatting options like bold or italics, we can add links, images, HTML elements, LaTeX mathematical equations, and more. 
A code cell contains code to be executed by the kernel. The programming language corresponds to the kernel's language. We will only use Python here, but you can use many other languages.

<span style="color:red">Assignment (2 min):</span>Try adding a code cell and a markdown cell below. 
In the toolbar use the "+" the add new cells. Focus on one cell and use the toolbar to make it a code or markdown cell. 
- In the code cell try computing 2*2
- Write some text, e.g. your name, in the markdown cell
Keyboard shortcuts
If you are on a Mac replace ctrl by cmd.

Ctrl-Enter: run the cell
Shift-Enter: run the cell and select the cell below
Alt-Enter: run the cell and insert a new cell below
Ctrl-s: save the notebook

<span style="color:red">Assignment (1 min):</span> Try these out on the cells above
Running Code
First and foremost, the Jupyter Notebook is an interactive environment for writing and running code. The notebook is capable of running code in a wide range of languages. However, each notebook is associated with a single kernel.  This notebook is associated with the Python kernel, therefore runs Python code.
Code cells allow you to enter and run code
Run a code cell using Shift-Enter or pressing the <button class='btn btn-default btn-xs'><i class="icon-step-forward fa fa-step-forward"></i></button> button in the toolbar above:
End of explanation
"""


import time
time.sleep(20)

"""
Explanation: Managing the Kernel
Code is run in a separate process called the Kernel.  The Kernel can be interrupted or restarted. 
<span style="color:red">Assignment (1 min):</span>
Try running the following cell, it contains a sleep command that will do absolutely nothing for 20 seconds. During this time the kernal will be busy. Notice that in the top-right corner the circle will be black to indicate this. Hit the <button class='btn btn-default btn-xs'><i class='icon-stop fa fa-stop'></i></button> button in the toolbar above to interrupt the computation.
End of explanation
"""


dna_seq = 'ACCGTCAAA'
dna_seq

"""
Explanation: Restarting the kernels manually
The kernel maintains the state of a notebook's computations. You can reset this state by restarting the kernel. This is done by clicking on the <button class='btn btn-default btn-xs'><i class='fa fa-repeat icon-repeat'></i></button> in the toolbar above. 
Note: Restarting the kernel whipes the memory clean. 
<span style="color:red">Assignment (2 min):</span>
1. Execute the cell below. This will save the variable dna_seq, containing a short string of DNA sequence, in the memory. 
2. Now restart the kernel manually as described above. 
3. In the second cell below try showing the contents of dna_seq. 
Does python still know what dna_seq is?
End of explanation
"""


dna_seq

"""
Explanation: Restart the server using the button at the top of the notebook.
End of explanation
"""


for i in range(35):
    print(i)

"""
Explanation: Large outputs
To better handle large outputs, the output area can be collapsed. Run the following cell and then single- or double- click on the active area to the left of the output:
End of explanation
"""


import matplotlib.pyplot as plt

population_size = {0:1} # in generation 0 there is one bacteria
for generation in range(1,25): # simulation of generations 1-24
    population_size[generation] = population_size[generation-1]*2
    
plt.plot(list(population_size.values()))
plt.show()

"""
Explanation: Plots: The power of powers
"The greatest shortcoming of the human race is our inability to understand the exponential function." --Albert Allen Bartlett (https://en.wikipedia.org/wiki/Albert_Allen_Bartlett)
Exponential growth is fast. Consider a population of bacteria or cancer cells. Each generation each bacteria in the population divides in two. The code below shows the (perhaps surprising) rate of growth in the number of bacteria.
End of explanation
"""


