Commit e0d2b4e4 authored by Dylan Aïssi's avatar Dylan Aïssi
Browse files

New upstream version 5.4.0

parent d8fa1f73
Loading
Loading
Loading
Loading
+76 −33
Original line number Diff line number Diff line
[5.4.0] - 2018-12-18
====================

Added
-----
- Snakemake now allows for data-dependent conditional re-evaluation of the job DAG via checkpoints. This feature also deprecates the ``dynamic`` flag. See `the docs <https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution>`_.

[5.3.1] - 2018-12-06
====================

Changed
-------

- Various fixed bugs and papercuts, e.g., in group handling, kubernetes execution, singularity support, wrapper and script usage, benchmarking, schema validation.

[5.3.0] - 2018-09-18
====================

@@ -26,8 +41,10 @@ Added
Changed
-------

-  fixed permission issue when using script directive
-  fixed various minor bugs and papercuts.
-  Fixed permission issue when using the script directive. This is a breaking change
   for scripts referring to files relative to the script directory (see the
   `docs <https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#external-scripts>`__).
-  Fixed various minor bugs and papercuts.
-  Allow URL to local git repo with wrapper directive
   (``git+file:///path/to/your/repo/path_to_file@@version``)

@@ -126,7 +143,7 @@ Changed
====================

Added
=====
-----

-  Group jobs for reduced queuing and network overhead, in particular
   with short running jobs.
@@ -135,7 +152,11 @@ Added
   transferred directly without using disk.
-  Command line flags to clean output files.
-  Command line flag to list files in working directory that are not
   tracked by Snakemake. # Changes
   tracked by Snakemake.

Changed
-------

-  Fix of --default-remote-prefix in case of input functions returning
   lists or dicts.
-  Scheduler no longer prefers jobs with many downstream jobs.
@@ -144,7 +165,7 @@ Added
====================

Added
=====
-----

-  Allow URLs for the conda directive. # Changed
-  Various minor updates in the docs.
@@ -162,7 +183,7 @@ Added
====================

Added
~~~~~
-----

-  Integration with CWL: the ``cwl`` directive allows to use CWL tool
   definitions in addition to shell commands or Snakemake wrappers.
@@ -202,7 +223,7 @@ Changed
====================

Added
~~~~~
-----

-  Input and output files can now tag pathlib objects. # ## Changed
-  Various minor bug fixes.
@@ -211,7 +232,7 @@ Added
====================

Added
~~~~~
-----

-  iRODS remote provider # ## Changed
-  Bug fix in shell usage of scripts and wrappers.
@@ -221,10 +242,14 @@ Added
--------------------

Added
~~~~~
-----

-  A new shadow mode (minimal) that only symlinks input files has been
   added. # ## Changed
   added.

Changed
-------

-  The default shell is now bash on linux and macOS. If bash is not
   installed, we fall back to sh. Previously, Snakemake used the default
   shell of the user, which defeats the purpose of portability. If the
@@ -239,10 +264,14 @@ Added
--------------------

Added
~~~~~
-----

-  List all conda environments with their location on disk via
   --list-conda-envs. # ## Changed
   --list-conda-envs.

Changed
-------

-  Do not clean up shadow on dry-run.
-  Allow R wrappers.

@@ -250,7 +279,7 @@ Added
--------------------

Added
~~~~~
-----

-  GridFTP remote provider. This is a specialization of the GFAL remote
   provider that uses globus-url-copy to download or upload files. # ##
@@ -265,11 +294,15 @@ Added
--------------------

Added
~~~~~
-----

-  Support for executing jobs in per-rule singularity images. This is
   meant as an alternative to the conda directive (see docs), providing
   even more guarantees for reproducibility. # ## Changed
   even more guarantees for reproducibility.

Changed
-------

-  In cluster mode, jobs that are still running after Snakemake has been
   killed are automatically resumed.
-  Various fixes to GFAL remote provider.
@@ -280,7 +313,7 @@ Added
--------------------

Added
~~~~~
-----

-  Support for configuration profiles. Profiles allow to specify default
   options, e.g., a cluster submission command. They can be used via
@@ -302,7 +335,7 @@ Added
--------------------

Added
~~~~~
-----

-  Cloud computing support via Kubernetes. Snakemake workflows can be
   executed transparently in the cloud, while storing input and output
@@ -363,7 +396,7 @@ Changed
---------------------

Added
~~~~~
-----

-  An NCBI remote provider. By this, you can seamlessly integrate any
   NCBI resouce (reference genome, gene/protein sequences, ...) as input
@@ -382,7 +415,7 @@ Added
---------------------

Added
~~~~~
-----

-  Support for RMarkdown (.Rmd) in script directives.
-  New option --debug-dag that prints all decisions while building the
@@ -421,7 +454,7 @@ Changed
---------------------

Added
~~~~~
-----

-  Param functions can now also refer to threads. # ## Changed
-  Improved tutorial and docs.
@@ -445,7 +478,7 @@ Changed
---------------------

Added
~~~~~
-----

-  Workflows can now be archived to a tarball with
   ``snakemake --archive my-workflow.tar.gz``. The archive contains all
@@ -466,7 +499,7 @@ Added
--------------------

Added
~~~~~
-----

-  Jobs can be restarted upon failure (--restart-times). # ## Changed
-  The docs have been restructured and improved. Now available under
@@ -479,7 +512,7 @@ Added
--------------------

Added
~~~~~
-----

-  Ability to define isolated conda software environments (YAML) per
   rule. Environments will be deployed by Snakemake upon workflow
@@ -518,7 +551,7 @@ Changed
--------------------

Added
~~~~~
-----

-  Wildcards can now be constrained by rule and globally via the new
   ``wildcard_constraints`` directive (see the
@@ -537,7 +570,10 @@ Added
   quoted (see the
   `docs <https://bitbucket.org/snakemake/snakemake/wiki/Documentation#markdown-header-rules>`__).
   This is usefull when dealing with filenames that contain whitespaces.
   # ## Changed

Changed
-------

-  Snakemake now deletes output files before job exection. Further, it
   touches output files after job execution. This solves various
   problems with slow NFS filesystems.
@@ -559,7 +595,7 @@ Changed
--------------------

Added
~~~~~
-----

-  The entries in ``resources`` and the ``threads`` job attribute can
   now be callables that must return ``int`` values.
@@ -591,7 +627,7 @@ Changed
--------------------

Added
~~~~~
-----

-  onstart handler, that allows to add code that shall be only executed
   before the actual workflow execution (not on dryrun).
@@ -612,7 +648,7 @@ Added
--------------------

Added
~~~~~
-----

-  New experimental wrapper directive, which allows to refer to
   re-usable `wrapper
@@ -645,7 +681,7 @@ Changed
--------------------

Added
~~~~~
-----

-  Support for easy integration of external R and Python scripts via the
   new `script
@@ -655,9 +691,12 @@ Added
   Google Storage, FTP, SFTP, HTTP and Dropbox.
-  Simon Ye has implemented support for sandboxing jobs with `shadow
   rules <https://bitbucket.org/snakemake/snakemake/wiki/Documentation#markdown-header-shadow-rules>`__.
   # ## Changed

Changed
-------

-  Manuel Holtgrewe has fixed dynamic output files in combination with
   mutliple wildcards.
   multiple wildcards.
-  It is now possible to add suffixes to all shell commands with
   shell.suffix("mysuffix").
-  Job execution has been refactored to spawn processes only when
@@ -703,14 +742,18 @@ Changed
------------------

Added
~~~~~
-----

-  This release adds support for executing jobs on clusters in
   synchronous mode (e.g. qsub -sync). Thanks to David Alexander for
   implementing this.
-  There is now vim syntax highlighting support (thanks to Jay
   Hesselberth).
-  Snakemake is now available as Conda package. # ## Changed
-  Snakemake is now available as Conda package.

Changed
-------

-  Lots of bugs have been fixed. Thanks go to e.g. David Koppstein,
   Marcel Martin, John Huddleston and Tao Wen for helping with useful
   reports and debugging.
+1 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ Publications using Snakemake
In the following you find an **incomplete list** of publications making use of Snakemake for their analyses.
Please consider to add your own.

* Doris et al. 2018. `Spt6 is required for the fidelity of promoter selection <https://doi.org/10.1016/j.molcel.2018.09.005>`_. Molecular Cell.
* Karlsson et al. 2018. `Four evolutionary trajectories underlie genetic intratumoral variation in childhood cancer <https://www.nature.com/articles/s41588-018-0131-y>`_. Nature Genetics.
* Planchard et al. 2018. `The translational landscape of Arabidopsis mitochondria <https://academic.oup.com/nar/advance-article/doi/10.1093/nar/gky489/5033161>`_. Nucleic acids research.
* Schult et al. 2018. `Effect of UV irradiation on Sulfolobus acidocaldarius and involvement of the general transcription factor TFB3 in the early UV response <https://academic.oup.com/nar/article/46/14/7179/5047281>`_. Nucleic acids research.
+27 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ This entails the pipefail option, which reports errors from within a pipe to out

.. code-block:: bash

    set +o pipefile;
    set +o pipefail;

to your shell command in the problematic rule.

@@ -605,3 +605,29 @@ You should have a look if maybe you are missing some library or a certain compil
If everything seems fine, please report to the upstream developers of the failing dependency.

Note that in general it is recommended to install Snakemake via `Conda <https://conda.io>`_ which gives you precompiled packages and the additional benefit of having :ref:`automatic software deployment <integrated_package_management>` integrated into your workflow execution.

How to enable autocompletion for the zsh shell?
-----------------------------------------------

For users of the `Z shell <https://www.zsh.org/>`_ (zsh), just run the following (assuming an activated zsh) to activate autocompletion for snakemake:

.. code-block:: console

    compdef _gnu_generic snakemake

Example:
Say you have forgotten how to use the various options starting ``force``, just type the partial match i.e. ``--force`` which results in a list of all potential hits along with a description:


.. code-block:: console

    $snakemake --force**pressing tab**

    --force              -- Force the execution of the selected target or the
    --force-use-threads  -- Force threads rather than processes. Helpful if shared
    --forceall           -- Force the execution of the selected (or the first)
    --forcerun           -- (TARGET (TARGET ...)), -R (TARGET (TARGET ...))

To activate this autocompletion permanently, put this line in ``~/.zshrc``.

`Here <https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org>`_ is some further reading.
+9 −3
Original line number Diff line number Diff line
@@ -111,11 +111,16 @@ This allows to create links between otherwise separate data analyses.
.. code-block:: python

    subworkflow otherworkflow:
        workdir: "../path/to/otherworkflow"
        snakefile: "../path/to/otherworkflow/Snakefile"
        workdir:
            "../path/to/otherworkflow"
        snakefile:
            "../path/to/otherworkflow/Snakefile"
        configfile:
            "path/to/custom_configfile.yaml"

    rule a:
        input:  otherworkflow("test.txt")
        input:
            otherworkflow("test.txt")
        output: ...
        shell:  ...

@@ -123,6 +128,7 @@ Here, the subworkflow is named "otherworkflow" and it is located in the working
The snakefile is in the same directory and called ``Snakefile``.
If ``snakefile`` is not defined for the subworkflow, it is assumed be located in the workdir location and called ``Snakefile``, hence, above we could have left the ``snakefile`` keyword out as well.
If ``workdir`` is not specified, it is assumed to be the same as the current one.
The (optional) definition of a ``configfile`` allows to parameterize the subworkflow as needed.
Files that are output from the subworkflow that we depend on are marked with the ``otherworkflow`` function (see the input of rule a).
This function automatically determines the absolute path to the file (here ``../path/to/otherworkflow/test.txt``).

+174 −2
Original line number Diff line number Diff line
@@ -426,6 +426,8 @@ Apart from Python scripts, this mechanism also allows you to integrate R_ and R

In the R script, an S4 object named ``snakemake`` analog to the Python case above is available and allows access to input and output files and other parameters. Here the syntax follows that of S4 classes with attributes that are R lists, e.g. we can access the first input file with ``snakemake@input[[1]]`` (note that the first file does not have index ``0`` here, because R starts counting from ``1``). Named input and output files can be accessed in the same way, by just providing the name instead of an index, e.g. ``snakemake@input[["myfile"]]``.

For technical reasons, scripts are executed in ``.snakemake/scripts``. The original script directory is available as ``scriptdir`` in the ``snakemake`` object. A convenience method, ``snakemake@source()``, acts as a wrapper for the normal R ``source()`` function, and can be used to source files relative to the original script directory.

An example external Python script would could look like this:

.. code-block:: python
@@ -530,8 +532,7 @@ Further, an output file marked as ``temp`` is deleted after all rules that use i
Directories as outputs
----------------------

There are situations where it can be convenient to have directories, rather than files, as outputs of a rule. For example, some tools generate different output files based on which settings they are run with. Rather than covering all these cases with conditional statements in the Snakemake rule, you can let the rule output a directory that contains all the output files regardless of settings. Another use case could be when the number of outputs is large or unknown, say one file per identified species in a metagenomics sample or one file per cluster from a clustering algorithm. If all downstream rules rely on the whole sets of outputs, rather than on the individual species/clusters, then having a directory as an output can be a faster and easier solution compared to using the ``dynamic`` keyword.
As of version 5.2.0, directories as outputs have to be explicitly marked with ``directory``. This is primarily for safety reasons; since all outputs are deleted before a job is executed, we don't want to risk deleting important directories if the user makes some mistake. Marking the output as ``directory`` makes the intent clear, and the output can be safely removed. Another reason comes down to how modification time for directories work. The modification time on a directory changes when a file or a subdirectory is added, removed or renamed. This can easily happen in not-quite-intended ways, such as when Apple macOS or MS Windows add ``.DS_Store`` or ``thumbs.db`` files to store parameters for how the directory contents should be displayed. When the ``directory`` flag is used, then a hidden file called ``.snakemake_timestamp`` is created in the output directory, and the modification time of that file is used when determining whether the rule output is up to date or if it needs to be rerun.
Sometimes it can be convenient to have directories, rather than files, as outputs of a rule. As of version 5.2.0, directories as outputs have to be explicitly marked with ``directory``. This is primarily for safety reasons; since all outputs are deleted before a job is executed, we don't want to risk deleting important directories if the user makes some mistake. Marking the output as ``directory`` makes the intent clear, and the output can be safely removed. Another reason comes down to how modification time for directories work. The modification time on a directory changes when a file or a subdirectory is added, removed or renamed. This can easily happen in not-quite-intended ways, such as when Apple macOS or MS Windows add ``.DS_Store`` or ``thumbs.db`` files to store parameters for how the directory contents should be displayed. When the ``directory`` flag is used a hidden file called ``.snakemake_timestamp`` is created in the output directory, and the modification time of that file is used when determining whether the rule output is up to date or if it needs to be rerun. Always consider if you can't formulate your workflow using normal files before resorting to using ``directory()``.

.. code-block:: python

@@ -1038,3 +1039,174 @@ Naturally, a pipe output may only have a single consumer.
It is possible to combine explicit group definition as above with pipe outputs.
Thereby, pipe jobs can live within, or (automatically) extend existing groups.
However, the two jobs connected by a pipe may not exist in conflicting groups.

.. _snakefiles-checkpoints:

Data-dependent conditional execution
------------------------------------

From Snakemake 5.4 on, conditional reevaluation of the DAG of jobs based on the content outputs is possible.
The key idea is that rules can be declared as checkpoints, e.g.,

.. code-block:: python

  checkpoint somestep:
      input:
          "samples/{sample}.txt"
      output:
          "somestep/{sample}.txt"
      shell:
          "somecommand {input} > {output}"

Snakemake allows to re-evaluate the DAG after the successful execution of every job spawned from a checkpoint.
For this, every checkpoint is registered by its name in a globally available ``checkpoints`` object.
The ``checkpoints`` object can be accessed by :ref:`input functions <snakefiles-input_functions>`.
Assuming that the checkpoint is named ``somestep`` as above, the output files for a particular job can be retrieved with

.. code-block:: python

  checkpoints.somestep.get(sample="a").output

Thereby, the ``get`` method throws ``snakemake.exceptions.IncompleteCheckpointException`` if the checkpoint has not yet been executed for these particular wildcard value(s).
Inside an input function, the exception will be automatically handled by Snakemake, and leads to a re-evaluation after the checkpoint has been successfully passed.

To illustrate the possibilities of this mechanism, consider the following complete example:

.. code-block:: python

  # a target rule to define the desired final output
  rule all:
      input:
          "aggregated/a.txt",
          "aggregated/b.txt"


  # the checkpoint that shall trigger re-evaluation of the DAG
  checkpoint somestep:
      input:
          "samples/{sample}.txt"
      output:
          "somestep/{sample}.txt"
      shell:
          # simulate some output vale
          "echo {wildcards.sample} > somestep/{wildcards.sample}.txt"


  # intermediate rule
  rule intermediate:
      input:
          "somestep/{sample}.txt"
      output:
          "post/{sample}.txt"
      shell:
          "touch {output}"


  # alternative intermediate rule
  rule alt_intermediate:
      input:
          "somestep/{sample}.txt"
      output:
          "alt/{sample}.txt"
      shell:
          "touch {output}"


  # input function for the rule aggregate
  def aggregate_input(wildcards):
      # decision based on content of output file
      with open(checkpoints.somestep.get(sample=wildcards.sample).output[0]) as f:
          if f.read().strip() == "a":
              return "post/{sample}.txt"
          else:
              return "alt/{sample}.txt"


  rule aggregate:
      input:
          aggregate_input
      output:
          "aggregated/{sample}.txt"
      shell:
          "touch {output}"

As can be seen, the rule aggregate uses an input function.
Inside the function, we first retrieve the output files of the checkpoint ``somestep`` with the wildcards, passing through the value of the wildcard sample.
Upon execution, if the checkpoint is not yet complete, Snakemake will record ``somestep`` as a direct dependency of the rule ``aggregate``.
Once ``somestep`` has finished for a given sample, the input function will automatically be re-evaluated and the method ``get`` will no longer return an exception.
Instead, the output file will be opened, and depending on its contents either ``"post/{sample}.txt"`` or ``"alt/{sample}.txt"`` will be returned by the input function.
This way, the DAG becomes conditional on some produced data.

It is also possible to use checkpoints for cases where the output files are unknown before execution.
A typical example is a clustering process with an unknown number of clusters, where each cluster shall be saved into a separate file.
Consider the following example:

.. code-block:: python

  # a target rule to define the desired final output
  rule all:
      input:
          "aggregated/a.txt",
          "aggregated/b.txt"


  # the checkpoint that shall trigger re-evaluation of the DAG
  checkpoint clustering:
      input:
          "samples/{sample}.txt"
      output:
          clusters=directory("clustering/{sample}")
      shell:
          "mkdir clustering/{wildcards.sample}; "
          "for i in 1 2 3; do echo $i > clustering/{wildcards.sample}/$i.txt; done"


  # an intermediate rule
  rule intermediate:
      input:
          "clustering/{sample}/{i}.txt"
      output:
          "post/{sample}/{i}.txt"
      shell:
          "cp {input} {output}"


  def aggregate_input(wildcards):
      checkpoint_output = checkpoints.clustering.get(**wildcards).output[0]
      return expand("post/{sample}/{i}.txt",
             sample=wildcards.sample,
             i=glob_wildcards(os.path.join(checkpoint_output, "{i}.txt")).i)


  # an aggregation over all produced clusters
  rule aggregate:
      input:
          aggregate_input
      output:
          "aggregated/{sample}.txt"
      shell:
          "cat {input} > {output}"

Here, our checkpoint simulates a clustering.
We pretend that the number of clusters is unknown beforehand.
Hence, the checkpoint only defines an output ``directory``.
The rule ``aggregate`` again uses the ``checkpoints`` object to retrieve the output of the checkpoint.
This time, instead of explicitly writing

.. code-block:: python

  checkpoints.clustering.get(sample=wildcards.sample).output[0]

we use the shorthand

.. code-block:: python

  checkpoints.clustering.get(**wildcards).output[0]

which automatically unpacks the wildcards as keyword arguments (this is standard python argument unpacking).
If the checkpoint has not yet been executed, accessing ``checkpoints.clustering.get(**wildcards)`` ensure that Snakemake records the checkpoint as a direct dependency of the rule ``aggregate``.
Upon completion of the checkpoint, the input function is re-evaluated, and the code beyond its first line is executed.
Here, we retrieve the values of the wildcard ``i`` based on all files named ``{i}.txt`` in the output directory of the checkpoint.
These values are then used to expand the pattern ``"post/{sample}/{i}.txt"``, such that the rule ``intermediate`` is executed for each of the determined clusters.

This mechanism can be used to replace the use of the :ref:`dynamic-flag <snakefiles-dynamic_files>` which will be deprecated in Snakemake 6.0.
Loading