-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro_python_trii_4.tex
354 lines (350 loc) · 11.2 KB
/
intro_python_trii_4.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
%
\mode<presentation> {
\usetheme{CambridgeUS}
}
%
\setbeamercolor{frametitle}{fg=cyan!80!black}
\setbeamercolor{title}{fg=cyan!80!black}
\setbeamercolor{palette tertiary}{fg=black, bg=cyan}
\setbeamercolor{palette primary}{fg=black, bg=gray!30!white}
\setbeamercolor{palette secondary}{fg=black, bg=gray!20!white}
%
\setbeamertemplate{headline}
{
\leavevmode%
\hbox{%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}%
% % \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{subsection in head/foot}%
% % \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
% %\end{beamercolorbox}
}%
\vskip0pt%
}
\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
% % \usebeamerfont{author in head/foot}{Vipin @ R\"{a}tschLab}
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
% % \usebeamerfont{title in head/foot}\insertshorttitle
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
% %\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
% %\end{beamercolorbox}
}%
\vskip0pt%
}
%
\usepackage{graphicx}
\usepackage{booktabs}
\setbeamertemplate{navigation symbols}{}
\usepackage{listings}
\usepackage{color}
\definecolor{codecomment}{rgb}{152,0,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{codekeys}{rgb}{30,0,100}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codecomment},
keywordstyle=\color{codekeys},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=4
}
\lstset{style=mystyle}
\newcommand{\thankyou}
{\begin{center} Would love to hear your experience! \\ [email protected] \\ [email protected] \end{center}}
%
\title[pyClass1]{Introduction to Programming with Python - Day 4}
\author{[email protected]}
%
\institute[cBio@MSKCC]
{
R{\"a}tsch Laboratory, Computational Biology Center\\
Memorial Sloan Kettering Cancer Center\\
}
\date{13 November 2014}
%
\begin{document}
\maketitle
%
\begin{frame}[plain]
\frametitle{Python for Scientific Computing}
\begin{itemize}
\item[] SciPy is a Python-based ecosystem of open-source software for science.
\newline
\pause
\item[] NumPy - Powerful N-dimensional array object
\newline
\pause
\item[] Matplotlib - 2D plotting library
\newline
\pause
\item[] IPython - Interactive python console
\newline
\pause
\item[] pandas - Data structures
\end{itemize}
\end{frame}
%
%
\begin{frame}[plain]
\frametitle{NumPy - multidimensional data arrays}
\begin{itemize}
\item[] The \textbf{numpy} package (module) is used in almost all numerical computation using Python.
\newline
\pause
\item[] Provide high-performance vector, matrix and higher-dimensional data structures for Python.
\newline
\pause
\item[] In the \textbf{numpy} package the terminology used for vectors, matrices and higher-dimensional data sets is \textit{array}.
\newline
\pause
\lstinputlisting[language=Python]{scripts/import_np_1.py}
\pause
\item[] The recommended convention to import numpy is:
\newline
\pause
\lstinputlisting[language=Python]{scripts/import_np_2.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - manual construction of arrays}
\begin{itemize}
\item[] 1-Dimension:
\lstinputlisting[language=Python]{scripts/np_1d.py}
\pause
\item[] 2-Dimension:
\lstinputlisting[language=Python]{scripts/np_2d.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - basic data types}
\begin{itemize}
\item[] Different data types allows to store data efficiently.
\newline
\pause
\lstinputlisting[language=Python]{scripts/np_dtype_1.py}
\pause
\item[] ValueError - assign a value of the wrong type to an element
\lstinputlisting[language=Python]{scripts/np_dtype_2.py}
\pause
\item[] Other data types:
\begin{itemize}
\item[] Complex
\item[] Bool
\item[] String
\end{itemize}
\pause
\lstinputlisting[language=Python]{scripts/np_dtype_3.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - function for creating arrays}
\begin{itemize}
\item[] arange
\lstinputlisting[language=Python]{scripts/np_range.py}
\pause
\item[] linspace
\lstinputlisting[language=Python]{scripts/np_linspace.py}
\pause
\item[] random
\lstinputlisting[language=Python]{scripts/np_rand.py}
\pause
\lstinputlisting[language=Python]{scripts/np_randn.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - common arrays}
\begin{itemize}
\item[] zeros
\lstinputlisting[language=Python]{scripts/np_zeros.py}
\pause
\item[] ones
\lstinputlisting[language=Python]{scripts/np_ones.py}
\pause
\item[] diag
\lstinputlisting[language=Python]{scripts/np_diag.py}
\pause
\item[] eye
\lstinputlisting[language=Python]{scripts/np_eye.py}
\pause
\item[] More details: \url{http://wiki.scipy.org/Tentative_NumPy_Tutorial}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - indexing}
\begin{itemize}
\item[] Index elements in an array using the square bracket and indices.
\lstinputlisting[language=Python]{scripts/np_idx_1.py}
\pause
\lstinputlisting[language=Python]{scripts/np_idx_2.py}
\pause
\item[] If we omit an index of a multidimensional array it returns the whole row
\lstinputlisting[language=Python]{scripts/np_idx_3.py}
\pause
\item[] Assigning new values to elements in an array using indexing
\lstinputlisting[language=Python]{scripts/np_idx_4.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{NumPy - slicing}
\begin{itemize}
\item[] Index slicing syntax \textbf{xm[lower:upper:step]} to extract part of an array.
\lstinputlisting[language=Python]{scripts/np_sl_1.py}
\pause
\item[] We can omit any of the three parameters in \textbf{xm[lower:upper:step]}
\lstinputlisting[language=Python]{scripts/np_sl_2.py}
\pause
\item[] Index slicing works exactly the same way for multidimensional arrays.
\lstinputlisting[language=Python]{scripts/np_sl_3.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{Matplotlib - basic visualization}
\begin{itemize}
\item[] \textit{Matplotlib} is a 2D plotting package.
\pause
\lstinputlisting[language=Python]{scripts/plt_1d.py}
\pause
\lstinputlisting[language=Python]{scripts/plt_2d.py}
\pause
\item[] Reference: \url{http://matplotlib.org/}\\
\url{http://web.stanford.edu/~mwaskom/software/seaborn/}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{BioPython - python modules for bioinformatics}
\begin{itemize}
\item[] A set of free Python modules for working with sequence analysis.
\newline
\pause
\begin{itemize}
\item[] AlignIO
\item[] SearchIO
\item[] BioSQL
\item[] Seq
\item[] SeqIO
\item[] SeqRecord
\newline
\pause
\end{itemize}
\item[] Details: \url{http://biopython.org}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{Seq - basic sequence tools}
\begin{itemize}
\item[] BioPython represents sequences with the \textbf{Seq} object.
\newline
\pause
\lstinputlisting[language=Python]{scripts/seq.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{SeqIO - basic fileIO}
\begin{itemize}
\item[] \textbf{parse} function can handle GenBank, FastQ, Fasta formats.
\newline
\pause
\lstinputlisting[language=Python]{scripts/seqIO.py}
\pause
\lstinputlisting[language=Python]{scripts/seqIOfq.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{SeqRecord - handling sequence records}
\begin{itemize}
\item[] Hold a sequence (as a Seq object) with identifiers (ID and name).
\pause
\lstinputlisting[language=Python]{scripts/seqrecord.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{GFF Parsing - parsing genome annotation file}
\begin{itemize}
\item[] Not yet integrated into the core biopython
\item[] \url{http://github.com/chapmanb/bcbb/tree/master/gff}
\newline
\pause
\item[] Collection of different annotation conveter programs
\item[] \url{https://github.com/vipints/GFFtools-GX}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{\textbf{pip} or \textbf{easy\_install} - managing local python packages}
\begin{itemize}
\item[] Machine learning toolbox in python
\begin{itemize}
\item []SHOGUN - \url{shogun-toolbox.org}
\item []scikit-learn - \url{scikit-learn.org}
\pause
\end{itemize}
\lstinputlisting[language=Bash]{scripts/pip_install.sh}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{\textbf{cPickle} - data persistence}
\begin{itemize}
\item[] Methods \textbf{dump()}, \textbf{load()}
\newline
\pause
\lstinputlisting[language=Python]{scripts/cpickle_dump.py}
\pause
\lstinputlisting[language=Python]{scripts/cpickle_load.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{\textbf{Django} - python web framework}
\begin{itemize}
\item[] Creating a project: django-admin.py startproject mysite
\newline
\pause
\item[] Add names to \textit{mysite settings.py} \textit{mysite urls.py}
\pause
\item[] python manage.py startapp app\_name
\pause
\item[] Edit view.py
\lstinputlisting[language=Python]{scripts/views.py}
\pause
\item[] python manage.py runserver
\item[] Details: \url{https://www.djangoproject.com/}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\thankyou
\end{frame}
\end{document}