10000 GitHub - joachimbrand/syw_pcb_paper: showyourwork repo for population control bias 2 paper
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

joachimbrand/syw_pcb_paper

 
 

Repository files navigation

showyourwork

Article status Article tarball Read the article

An open source scientific article created using the showyourwork workflow.

Using Julia

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

About

showyourwork repo for population control bias 2 paper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TeX 99.2%
  • Other 0.8%
0