Skip to content

Commit

Permalink
Revise part04 of the "workflows" programmers' tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jan 23, 2017
1 parent 065bb56 commit 893a151
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Binary file modified docs/programmers/tutorials/workflows/part04.pdf
Binary file not shown.
44 changes: 26 additions & 18 deletions docs/programmers/tutorials/workflows/part04.tex
Expand Up @@ -17,7 +17,7 @@
\\[1ex]
University of Zurich
}
\date{November~14--17, 2016}
\date{January~23--27, 2017}

\begin{document}

Expand All @@ -30,7 +30,7 @@
\begin{enumerate}
\item Customize positional argument processing
\item Customize option processing
\item More complex \texttt{new\_tasks()} implementations
\item More complex code in \texttt{new\_tasks()}
\end{enumerate}
\end{frame}

Expand Down Expand Up @@ -100,7 +100,7 @@
\begin{frame}[fragile]
\frametitle{Positional argument processing}
\frametitle{Positional argument processing: \texttt{nargs}}
\begin{python}
def setup_args(self):
Expand All @@ -116,7 +116,7 @@
\begin{frame}[fragile]
\frametitle{Positional argument processing}
\frametitle{Positional argument processing: \texttt{nargs}}
\begin{python}
def setup_args(self):
Expand All @@ -137,7 +137,7 @@
\begin{frame}[fragile]
\frametitle{Positional argument processing}
\frametitle{Positional argument processing: \texttt{metavar}}
\begin{python}
def setup_args(self):
Expand All @@ -163,7 +163,7 @@


\begin{frame}[fragile]
\frametitle{Positional argument processing}
\frametitle{Positional argument processing: \texttt{help}}

\begin{python}
def setup_args(self):
Expand All @@ -186,15 +186,15 @@
\begin{frame}[fragile]
\frametitle{Positional argument processing}
\frametitle{Multiple positional argument processing}
Calls to \lstinline|self.add_param()| can be repeated to
parse many different command-line arguments in sequence:
\begin{python}
class AScript(SessionBasedScript):
# ~\em [\ldots]~
def setup_args(self):
self.add_param('input', help="Input file")
self.add_param('infile', help="Input file")
self.add_param('radius', help="Convolution radius")
self.add_param('sigma', help="Threshold")
\end{python}
Expand All @@ -206,7 +206,7 @@
\end{sh}%$
generates the equivalent of the following Python code:
\begin{python}
self.params.input = 'example.py'
self.params.infile = 'example.py'
self.params.radius = '10' # it's a string!
self.params.sigma = '2.1' # this one too!
\end{python}
Expand Down Expand Up @@ -263,7 +263,7 @@
def setup_args(self):

# this argument is a string (default type)
self.add_param('input', type=str, help="...")
self.add_param('infile', type=str, help="...")

# the `radius` argument is an integer
self.add_param('radius', type=int, help="...")
Expand All @@ -277,15 +277,16 @@
\begin{frame}[fragile]
\frametitle{Argument types}

Declaring argument types makes for better usability: if an argument
does not match its type, the script exists immediately and the user
is notified with a clear error message.
\textbf{Declaring argument types makes for better usability!}

\+ If an argument does not match its type, \\ the script exists immediately
and the user is notified with a clear error message.

\+
\begin{sh}
$ python downloads/argp.py foo.txt 123 x
usage: argparse [-h] ~\em [\ldots]~
input radius sigma
infile radius sigma
argp: error: argument sigma: invalid float value: 'x'
\end{sh}%$
\end{frame}
Expand All @@ -306,7 +307,7 @@
# ~\em [\ldots]~
def setup_args(self):
# reject non-existent input files outright
self.add_param('input', type=existing_file, ~\ldots~)
self.add_param('infile', type=existing_file, ~\ldots~)
# force radius to be > 0
self.add_param('radius', type=positive_int, ~\ldots~)
# sigma is a floating-point number
Expand Down Expand Up @@ -419,8 +420,13 @@
\+ The command-line invocation for one such comparison would look like this:
\begin{sh}
$ blastp -query new.faa -subject known.faa \
-evalue 1e-6 -outfmt 9
-evalue 1e-6 -outfmt 5
\end{sh}%$

\+
\begin{center}
\tiny\itshape (Thanks to Lars Malmstroem for suggesting the following BLAST-related exercises.)
\end{center}
\end{frame}

\begin{frame}[fragile]
Expand All @@ -435,8 +441,10 @@
\end{sh}%$
where:
\begin{itemize}
\item Option \texttt{-e} (alias: \texttt{-{}-e-value}) takes a floating point threshold argument $T$;
\item Option \texttt{-m} (alias: \texttt{-{}-output-format}) takes a single-digit integer argument $F$;
\item Option \texttt{-e} (alias: \texttt{-{}-e-value}) takes a floating
point threshold argument $T$ (defaulting to $1.0$);
\item Option \texttt{-m} (alias: \texttt{-{}-output-format}) takes a
single-digit integer argument $F$ (default $5$);
\item Arguments \texttt{new.faa}, \texttt{k1.faa}, etc. are files.
\end{itemize}
Expand Down

0 comments on commit 893a151

Please sign in to comment.