Skip to content

Commit 7fb6840

Browse files
committed
feat: added section about modularization
1 parent 8a00753 commit 7fb6840

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

slides/creators/modularization.tex

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
\section{Modularization}
3+
{
4+
\usebackgroundtemplate{
5+
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil\includegraphics[height=.7\paperheight]{misc/bricks.png}\hfil}\vfil}
6+
}
7+
\frame{
8+
\frametitle{Modulerizing Snakefiles}
9+
\begin{mdframed}[tikzsetting={draw=white,fill=white,fill opacity=0.8,
10+
line width=0pt},backgroundcolor=none,leftmargin=0,
11+
rightmargin=150,innertopmargin=4pt,roundcorner=10pt]
12+
\tableofcontents[currentsection,sections={1-4},hideothersubsections]
13+
\end{mdframed}
14+
}
15+
}
16+
17+
18+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19+
\begin{frame}
20+
\frametitle{What is this about?}
21+
\begin{question}[Questions]
22+
\begin{itemize}
23+
\item Are monolithic Snakefiles feasible?
24+
\item How can we put a Snakefile in pieces?
25+
\end{itemize}
26+
\end{question}
27+
\begin{docs}[Objectives]
28+
\begin{enumerate}
29+
\item Introduce maintainability concepts
30+
\item Introducing modularization strategies
31+
\end{enumerate}
32+
\end{docs}
33+
\end{frame}
34+
35+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36+
\begin{frame}
37+
\frametitle{Intro to Maintainability}
38+
\begin{question}[Take a guess:]
39+
\begin{itemize}
40+
\item How big can a workflow be (lines of code)? \pause A few hundred to thousand lines.
41+
\item Does it then make sense to keep it all in one file?
42+
\end{itemize}
43+
\end{question}
44+
\pause
45+
\begin{hint}
46+
The ideas behind code modularization are:\newline
47+
Increase readability, \pause enable parallel devolpment \pause ease testing and debugging.
48+
\end{hint}
49+
\end{frame}
50+
51+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52+
\begin{frame}[fragile]
53+
\frametitle{Dividing Snakefiles}
54+
Our Snakefile hardly merits modularization, but we could move all mapping-realted stuff to an extra file, e.\,g.:
55+
\begin{lstlisting}[language=Python,style=Python]
56+
include: "rules/mapping.smk" # will include this Snakefile
57+
\end{lstlisting}
58+
\pause
59+
\begin{docs}
60+
\begin{itemize}[<+->]
61+
\item we place our modules into \altverb{rules}
62+
\item the suffix \altverb{.smk} is convention, too.
63+
\end{itemize}
64+
\end{docs}
65+
\end{frame}
66+
67+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68+
\begin{frame}[fragile]
69+
\frametitle{How a good Snakefile \emph{should} look like}
70+
\begin{lstlisting}[language=Python,style=Python]
71+
from snakemake.utils import min_version
72+
73+
# require a minimum version
74+
min_version("8.10.7")
75+
76+
# may point to samples, contains sciency parts
77+
configfile: "config/config.yml"
78+
# entry point for the workflow documentation
79+
report: "report/workflow.rst"
80+
81+
include: "rules/commons.smk"
82+
include: "rules/qc.smk"
83+
include: "rules/utils.smk"
84+
include: "rules/ref.smk"
85+
include: "rules/alignment.smk"
86+
include: "rules/diffexp.smk"
87+
88+
inputdir = config["inputdir"]
89+
90+
rule all:
91+
input:
92+
# generates targets
93+
rule_all_input(),
94+
\end{lstlisting}
95+
\end{frame}
96+
97+
\begin{frame}[fragile]
98+
\frametitle{\HandsOn{Practical Modularization}}
99+
Try creating this major Snakefile:
100+
\begin{lstlisting}[language=Python,style=Python]
101+
from snakemake.utils import min_version
102+
103+
# which is the current snakemake version?
104+
min_version(<the current snakemake version>)
105+
106+
rule all:
107+
input:
108+
#our targets
109+
110+
include: "rules/mapping.smk"
111+
include: "rules/index.smk"
112+
include: "rules/call.smk"
113+
include: "rules/plots.smk"
114+
\end{lstlisting}
115+
\end{frame}
116+
117+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118+
\begin{frame}[fragile]
119+
\frametitle{Alien Modules}
120+
\Snakemake allows to "borrow" from CWL or Nextflow, too:
121+
\begin{lstlisting}[language=Python,style=Python]
122+
rule samtools_sort:
123+
input:
124+
input="mapped/{sample}.bam"
125+
output:
126+
output_name="mapped/{sample}.sorted.bam"
127+
params:
128+
threads=lambda wildcards, threads: threads,
129+
memory="4G"
130+
threads: 8
131+
cwl:
132+
"https://github.com/common-workflow-language/workflows/blob/"
133+
"fb406c95/tools/samtools-sort.cwl"
134+
\end{lstlisting}
135+
\end{frame}

0 commit comments

Comments
 (0)