...
 
Commits (2)
.ipynb_checkpoints
*.pyc
*.slides.html
*.aux
*.log
*.nav
*.out
*.snm
*.backup
*.toc
*.vrb
......@@ -11,79 +11,7 @@
\usetheme{lumc}
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{ipyout}{HTML}{F0FFF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}\label{#1}In \thecntr:}}}
\end{minipage}%
\begin{minipage}[t]{0.89\linewidth}%
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}
{%
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}\label{#1}Out\thecntr:}}}
\end{minipage}%
\color{ipyout}%
\ttfamily%
\begin{minipage}[t]{0.89\linewidth}%
}
{\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\input{../../shared/shared.tex}
\begin{document}
......@@ -193,7 +121,7 @@ triple-quotes.
You see? I continued after a blank line."""
\end{pythonin}
\begin{pythonout}
'A multiline string.\n\nYou see? I continued after a blank line.'
'A multiline string.\textbackslash n\textbackslash nYou see? I continued after a blank line.'
\end{pythonout}
\end{ipython}
\end{pframe}
......@@ -396,7 +324,7 @@ list('abcdefghijk')
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
\end{pythonout}
\\
\begin{pythonin}{python}
range(5, 16) # In python 2: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
\end{pythonin}
......@@ -405,7 +333,7 @@ range(5, 16) # In python 2: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
range(5, 16)
\end{pythonout}
\\
\begin{pythonin}{python}
list(range(5, 16))
\end{pythonin}
......@@ -413,8 +341,8 @@ list(range(5, 16))
\begin{pythonout}
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
\end{pythonout}
\\
\\
\begin{pythonin}{python}
zip(['red', 'white', 'blue'], range(3))
\end{pythonin}
......@@ -423,7 +351,7 @@ zip(['red', 'white', 'blue'], range(3))
<zip at 0x7f3565860108>
\end{pythonout}
\\
\begin{pythonin}{python}
list(zip(['red', 'white', 'blue'], range(3)))
\end{pythonin}
......@@ -645,12 +573,12 @@ True
s1 = {12, 28, 21, 17}
\end{pythonin}
\\
\begin{pythonin}{python}
s2 = {28, 32, 71, 12}
\end{pythonin}
\\
\begin{pythonin}{python}
s1.difference(s2)
\end{pythonin}
......
......@@ -11,95 +11,7 @@
\usetheme{lumc}
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{scriptback}{HTML}{CDECF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}\label{#1}In \thecntr:}}}
\end{minipage}
\begin{minipage}[t]{0.89\linewidth}
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}[1]
{\VerbatimEnvironment
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}\label{#1}Out\thecntr:}}}
\end{minipage}
\begin{minipage}[t]{0.89\linewidth}
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\newenvironment{pythonfile}[1]
{\begin{tcolorbox}[title=#1,
title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\input{../../shared/shared.tex}
\begin{document}
......@@ -145,7 +57,7 @@
\subsection{Writing your script}
\begin{pframe}
Let's start with a simple hello world example.\\
Open your text editor and write the following Python statement:
\begin{pythonfile}{first\_script.py}
......@@ -176,7 +88,7 @@ Save the file as first\_script.py and go to your shell.
\item Save the file, go back to the shell, and allow the file to be executed.
\end{itemize}
\begin{terminal}
\color{white}{\texttt{\$ chmod +x first\_script.py}
\color{white}{\texttt{\$ chmod +x first\_script.py}}
\end{terminal}
You can now execute the file directly:
\begin{terminal}
......@@ -232,7 +144,7 @@ while i < 5:
\begin{terminal}
\color{white}{\texttt{\$ python while\_example.py \\
0\\
0\\
1\\
2\\
3\\
......@@ -280,11 +192,11 @@ These are common for programmers coming from other languages.
\begin{minted}[linenos]{python}
i = 0
while i < len(colors):
print colors[i]
print(colors[i])
i += 1
for i in range(len(colors)):
print colors[i]
print(colors[i])
\end{minted}
\end{pythonfile}
......@@ -303,7 +215,7 @@ for i, color in enumerate(colors):
# Taking two sequences together:
for city, color in zip(cities, colors):
print(city, '->', color)
# Iterating over a dictionary yields keys:
for key in {'a': 33, 'b': 17, 'c': 18}:
print(key)
......@@ -333,11 +245,11 @@ for line in open('data/short_file.txt'):
\begin{minted}[linenos]{python}
if False:
if False:
print 'Why am I here?'
print('Why am I here?')
else:
while True:
print 'When will it stop?'
print "And we're back to the first indentation level"
print('When will it stop?')
print("And we're back to the first indentation level")
\end{minted}
\end{pythonfile}
\end{pframe}
......@@ -387,7 +299,7 @@ def add_two(number):
return number + 2
for i in range(5):
print add_two(i)
print(add_two(i))
\end{minted}
\end{pythonfile}
\end{pframe}
......@@ -424,12 +336,12 @@ def add_some_other_number(number, other_number=12):
functions = [add_two, add_some_other_number]
for function in functions:
print function(7)
print(function(7))
# Simple anonymous functions can be created with lambda.
functions.append(lambda x: x * 7)
for function in functions:
print function(4)
print(function(4))
\end{minted}
\end{pythonfile}
\end{pframe}
......@@ -558,8 +470,6 @@ colors = ['red', 'white', 'blue', 'orange']
Next, it calculates and prints the number of upper case letters and lower
case letters. Make use of the \mintinline{python}{isupper} and
\mintinline{python}{islower} built in methods.
\end{enumerate}
\end{pframe}
......
......@@ -11,100 +11,7 @@
\usetheme{lumc}
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{ipyout}{HTML}{F0FFF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}In \thecntr:}}}
\end{minipage}%
\begin{minipage}[t]{0.89\linewidth}%
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}
{%
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}Out\thecntr:}}}
\end{minipage}%
\color{ipyout}%
\ttfamily%
\begin{minipage}[t]{0.89\linewidth}%
}
{\end{minipage}}
\newenvironment{pythonoutnonumber}
{%
\color{ipyout}%
\ttfamily%
}
{}
%\newenvironment{pythonout}
%{\VerbatimEnvironment%
% \addtocounter{cntr}{-1}
% \begin{minipage}[t]{0.11\linewidth}
% \textcolor{red}{\texttt{{\refstepcounter{cntr}\label{#1}Out\thecntr:}}}
% \end{minipage}%
% \begin{minipage}[t]{0.89\linewidth}%
% \color{ipyout}%
% \ttfamily%
%}%
%{%
%\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\input{../../shared/shared.tex}
\begin{document}
......@@ -449,6 +356,22 @@ IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
\end{pythonout}
\\
\begin{pythonin}{python}
14 // 4
\end{pythonin}
\begin{pythonout}
3
\end{pythonout}
\\
\begin{pythonin}{python}
14 % 4
\end{pythonin}
\begin{pythonout}
2
\end{pythonout}
\\
\begin{pythonin}{python}
2 ** 3
\end{pythonin}
......
......@@ -10,113 +10,8 @@
\providecommand{\myCenter}{}
\usetheme{lumc}
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{scriptback}{HTML}{CDECF0}
\definecolor{ipyout}{HTML}{F0FFF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}In \thecntr:}}}
\end{minipage}%
\begin{minipage}[t]{0.89\linewidth}%
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}
{%
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}Out\thecntr:}}}
\end{minipage}%
\color{ipyout}%
\ttfamily%
\begin{minipage}[t]{0.89\linewidth}%
}
{\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\newenvironment{pythonfile}[1]
{\begin{tcolorbox}[title=#1,
title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\newenvironment{pythoncode}
{\begin{tcolorbox}[title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\input{../../shared/shared.tex}
\begin{document}
......@@ -150,7 +45,8 @@ print("The sequence 'CAGG' has a %GC of {:.2f}".format(
\end{minted}
\end{pythonfile}
\pause
Our script is nice and dandy, but we don't want to edit the source file everytime we calculate a sequence's GC.
Our script is nice and dandy, but we don't want to edit the source file
everytime we calculate a sequence's GC.
\end{pframe}
......@@ -159,8 +55,10 @@ print("The sequence 'CAGG' has a %GC of {:.2f}".format(
\begin{pframe}
\begin{itemize}
\item A collection of Python modules (or functions, for now) that comes packaged with a default Python installation.
\item They're not part of the language per se, more like a batteries included thing.
\item A collection of Python modules (or functions, for now) that comes
packaged with a default Python installation.
\item They're not part of the language per se, more like a batteries included
thing.
\end{itemize}
\end{pframe}
......@@ -168,8 +66,10 @@ print("The sequence 'CAGG' has a %GC of {:.2f}".format(
\subsection{Our first standard library module: sys}
\begin{pframe}
\begin{itemize}
\item We'll start by using the simple sys module to make our script more flexible.
\item Standard library (and other modules, as we'll see later) can be used via the import statement, for example:
\item We'll start by using the simple sys module to make our script more
flexible.
\item Standard library (and other modules, as we'll see later) can be used
via the import statement, for example:
\end{itemize}
\begin{ipython}
......@@ -179,8 +79,8 @@ import sys
\end{ipython}
\begin{itemize}
\item Like other objects so far, we can peek into the documentation of these modules
using help, or the IPython ? shortcut. For example:
\item Like other objects so far, we can peek into the documentation of these
modules using help, or the IPython ? shortcut. For example:
\end{itemize}
\begin{ipython}
\begin{pythonin}{python}
......@@ -243,11 +143,13 @@ print("The sequence '{}' has a %GC of {:.2f}".format(
\begin{itemize}
\vspace{-0.8cm}
\item Try running the script with \mintinline{python}{'cagg'} as the input sequence. What happens?
\item Try running the script with \mintinline{python}{'cagg'} as the input
sequence. What happens?
\item As we saw earlier, many objects, like those of type
\mintinline{python}{list}, \mintinline{python}{dict}, or \mintinline{python}{str},
have useful methods defined on them.
\item One way to squash this potential bug is by using Python's string method upper.
\mintinline{python}{list}, \mintinline{python}{dict}, or
\mintinline{python}{str}, have useful methods defined on them.
\item One way to squash this potential bug is by using Python's string method
upper.
\item Let's first check out some commonly used string functions.
\end{itemize}
......@@ -404,7 +306,8 @@ print("The sequence '{}' has a %GC of {:.2f}".format(
\begin{pframe}
\begin{itemize}
\item Try running the script with \mintinline{python}{'ACTG123'} as the argument.
\item Try running the script with \mintinline{python}{'ACTG123'} as the
argument.
\begin{itemize}
\item What happens?
\item Is this acceptable behavior?
......@@ -616,18 +519,11 @@ return gc_count * 100.0 / (gc_count + at_count)
\end{minted}
\end{pythoncode}
\begin{itemize}
\item Both approaches are correct and have their own plus and minuses in general.
\item Both approaches are correct and have their own plus and minuses in
general.
\end{itemize}
\end{pframe}
% \section{Improving our script by handling more corner cases}
% \begin{pframe}
% \begin{itemize}
% \item Now try running your script without any arguments at all. What happens?
% \item Armed with what you now know, how would you handle this situation?
% \end{itemize}
% \end{pframe}
% Make the acknowledgements slide.
\makeAcknowledgementsSlide{
\begin{tabular}{ll}
......
......@@ -10,113 +10,8 @@
\providecommand{\myCenter}{}
\usetheme{lumc}
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{scriptback}{HTML}{CDECF0}
\definecolor{ipyout}{HTML}{F0FFF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}In \thecntr:}}}
\end{minipage}%
\begin{minipage}[t]{0.89\linewidth}%
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}
{%
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}Out\thecntr:}}}
\end{minipage}%
\color{ipyout}%
\ttfamily%
\begin{minipage}[t]{0.89\linewidth}%
}
{\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\newenvironment{pythonfile}[1]
{\begin{tcolorbox}[title=#1,
title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\newenvironment{pythoncode}
{\begin{tcolorbox}[title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\input{../../shared/shared.tex}
\begin{document}
......@@ -191,7 +86,8 @@ IndexError: list index out of range
\begin{pframe}
\vspace{-.05cm}
\begin{itemize}
\item During a module import, Python executes all the statements inside the module.
\item During a module import, Python executes all the statements inside the
module.
\item To make our script work as a module (in the intended way), we need to
add a check whether the module is imported or not:
\end{itemize}
......@@ -200,8 +96,8 @@ IndexError: list index out of range
\begin{minted}{python}
if __name__ == '__main__':
input_seq = sys.argv[1]
print "The sequence '{}' has %GC of {:.2f}".format(
input_seq, calc_gc_percent(input_seq))
print("The sequence '{}' has %GC of {:.2f}".format(
input_seq, calc_gc_percent(input_seq)))
\end{minted}
\end{pythoncode}
\begin{itemize}
......@@ -239,7 +135,8 @@ seq_toolbox.calc_gc_percent
\begin{pframe}
\begin{itemize}
\item By the way, remember we added docstring to the calc\_gc\_percent function?
\item By the way, remember we added docstring to the calc\_gc\_percent
function?
\item After importing our module, we can read up on how to use the function
in its docstring:
\end{itemize}
......@@ -263,7 +160,8 @@ seq_toolbox.calc_gc_percent('ACTG')
\begin{pframe}
\begin{itemize}
\item We can also expose an object inside the module directly into our
current namespace using the \mintinline{python}{from ... import ...} statement:
current namespace using the \mintinline{python}{from ... import ...}
statement:
\end{itemize}
\begin{ipython}
\begin{pythonin}{python}
......@@ -389,7 +287,8 @@ math.sqrt(2) # Square root of 2.
\subsection{random module}
\begin{pframe}
\begin{itemize}
\item The random module contains useful functions for generating pseudo-random numbers.
\item The random module contains useful functions for generating
pseudo-random numbers.
\end{itemize}
\begin{ipython}
\begin{pythonin}{python}
......@@ -431,7 +330,8 @@ random.choice(['apple', 'banana', 'grape', 'kiwi', 'orange'])
\begin{itemize}
\item Using sys.argv is neat for small scripts, but as our script gets larger
and more complex, we want to be able to handle complex arguments too.
\item The argparse module has handy functionalities for creating command-line scripts.
\item The argparse module has handy functionalities for creating command-line
scripts.
\end{itemize}
\end{pframe}
......@@ -456,9 +356,9 @@ if __name__ == '__main__':
# Do the actual parsing.
args = parser.parse_args()
# And show the output.
print "The sequence '{}' has %GC of {:.2f}".format(
print("The sequence '{}' has %GC of {:.2f}".format(
args.input_seq,
calc_gc_percent(args.input_seq))
calc_gc_percent(args.input_seq)))
\end{minted}
\end{pythoncode}
\end{pframe}
......@@ -497,7 +397,8 @@ fh = open('data/short_file.txt')
\end{ipython}
\begin{itemize}
\item fh is a file handle object which we can use to retrieve the file contents.
\item fh is a file handle object which we can use to retrieve the file
contents.
\item One simple way would be to read the whole file contents:
\end{itemize}
\begin{ipython}
......@@ -583,13 +484,14 @@ fh.readline()
\begin{pframe}
\begin{itemize}
\item More common in Python is to use the for loop with the file handle itself.
\item More common in Python is to use the for loop with the file handle
itself.
\item Python will automatically iterate over each line.
\end{itemize}
\begin{pythoncode}
\begin{minted}{python}
for line in fh:
print line
print(line)
\end{minted}
\end{pythoncode}
\begin{itemize}
......@@ -670,12 +572,12 @@ fw.close()
try:
f = open('data/short_file.txt')
for line in f:
print int(line)
print(int(line))
except ValueError:
print 'Seems there was a line we could not handle'
print('Seems there was a line we could not handle')
finally:
f.close()
print 'We closed our file handle'
print('We closed our file handle')
\end{minted}
\end{pythoncode}
\end{pframe}
......@@ -697,7 +599,8 @@ with open("welcome.txt") as f: # Use file to refer to the file object
\subsection{Improving our script to allow input from a file}
\begin{pframe}
\begin{itemize}
\item The script should accept as its argument a path to a file containing sequences.
\item The script should accept as its argument a path to a file containing
sequences.
\item It will then compute the GC percentage for each sequence in this file.
\item There are at least two things we need to do:
\begin{itemize}
......
\usepackage{minted}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\definecolor{monokaibg}{HTML}{272822}
\definecolor{emailc}{HTML}{1e90FF}
\definecolor{scriptback}{HTML}{CDECF0}
\definecolor{ipyout}{HTML}{F0FFF0}
\newenvironment{ipython}
{\begin{tcolorbox}[title=IPython,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newenvironment{terminal}
{\begin{tcolorbox}[title=terminal,
title filled=false,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
colback=monokaibg,
drop small lifted shadow,
boxrule=0.1mm,
left=0.1cm,
arc=0mm,
colframe=black]}
{\end{tcolorbox}}
\newcommand{\hrefcc}[2]{\textcolor{#1}{\href{#2}{#2}}}
\newcommand{\hrefc}[3]{\textcolor{#1}{\href{#2}{#3}}}
\newcounter{cntr}
\renewcommand{\thecntr}{\texttt{[\arabic{cntr}]}}
\newenvironment{pythonin}[1]
{\VerbatimEnvironment
\begin{minipage}[t]{0.11\linewidth}
\textcolor{green}{\texttt{{\refstepcounter{cntr}In \thecntr:}}}
\end{minipage}%
\begin{minipage}[t]{0.89\linewidth}%
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}
\end{minipage}}
\newenvironment{pythonout}
{%
\addtocounter{cntr}{-1}
\begin{minipage}[t]{0.11\linewidth}
\textcolor{red}{\texttt{{\refstepcounter{cntr}Out\thecntr:}}}
\end{minipage}%
\color{ipyout}%
\ttfamily%
\begin{minipage}[t]{0.89\linewidth}%
}
{\end{minipage}}
\newenvironment{pythonerr}[1]
{\VerbatimEnvironment
\begin{minted}[
breaklines=true,style=monokai]{#1}}
{\end{minted}}
\newenvironment{pythonfile}[1]
{\begin{tcolorbox}[title=#1,
title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\newenvironment{pythoncode}
{\begin{tcolorbox}[title filled=false,
coltitle=LUMCDonkerblauw,
fonttitle=\scriptsize,
fontupper=\footnotesize,
enhanced,
drop small lifted shadow,
boxrule=0.1mm,
leftrule=5mm,
rulecolor=white,
left=0.1cm,
colback=white!92!black,
colframe=scriptback]}
{\end{tcolorbox}}
\newenvironment{pythonoutnonumber}
{%
\color{ipyout}%
\ttfamily%
}
{}