Julia-based Snakemake Workflow for Data Analysis and Document Generation

public public 1yr ago 0 bookmarks

Fork this repo to easily use Julia in showyourwork . The following modifications were made to the default template (You can also see this from the Git diff )

  1. Defined src/scripts/paths.jl , replacing src/scripts/paths.py (just a convenience file which defines paths when you include() it).

  2. Created a Project.toml to define Julia dependencies.

  3. Created two example scripts in src/scripts/ :

    • data.jl , to create a dataset and save it to mydata.csv , and

    • plot.jl , to plot the dataset and save it to myplot.png .

  4. Created three Snakemake rules:

    • julia_manifest creates Manifest.toml from the Project.toml .

    • data calls data.jl , and depends on Manifest.toml .

    • plot calls plot.jl , and depends on mydata.csv and Manifest.toml .

  5. Configured showyourwork.yml to map .jl to julia .

The Snakefile also defines the JULIA_PROJECT as "." . These three Julia jobs are dependencies of the final rule, which compiles the LaTeX document using tectonic . The generated PDF and arXiv tarball will contain myplot.png .

For example, the rule plot :

rule plot:
 input:
 "Manifest.toml",
 data="src/data/mydata.csv",
 output: "src/tex/figures/myplot.png"
 script: "src/scripts/plot.jl"

This Julia script is then able to reference the variable snakemake :

using Gadfly
using Cairo
using CSV
using DataFrames
input_fname = snakemake.input["data"]
output_fname = snakemake.output[1]
data = open(input_fname, "r") do io
 CSV.read(io, DataFrame)
end
# Plot x vs y:
p = plot(data, x=:x, y=:y, Geom.line)
# Save:
draw(PNG(output_fname, 10cm, 7.5cm), p)

In ms.tex , we can define the corresponding figure as:

\begin{figure}[h!] \centering \includegraphics[width=0.5\textwidth]{figures/myplot.png} \caption{A figure.} \label{fig:fig1} \script{../scripts/plot.jl}
\end{figure}

Which will add a hyperlink to the script used to generate the figure:

Screenshot 2023-04-15 at 3 01 17 PM

Code Snippets

13
shell: "julia -e 'using Pkg; Pkg.instantiate()'"
SnakeMake From line 13 of main/Snakefile
18
script: "src/scripts/data.jl"
SnakeMake From line 18 of main/Snakefile
27
script: "src/scripts/plot.jl"
SnakeMake From line 27 of main/Snakefile
ShowHide 3 more snippets with no or duplicated tags.

Login to post a comment if you would like to share your experience with this workflow.

Do you know this workflow well? If so, you can request seller status , and start supporting this workflow.

Free

Created: 1yr ago
Updated: 1yr ago
Maitainers: public
URL: https://github.com/MilesCranmer/showyourwork_julia_example
Name: showyourwork_julia_example
Version: 1
Badge:
workflow icon

Insert copied code into your website to add a link to this workflow.

Downloaded: 0
Copyright: Public Domain
License: MIT License
  • Future updates

Related Workflows

cellranger-snakemake-gke
snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...