snakemake.script package

Module contents

class snakemake.script.BashEncoder(namedlists=None, dicts=None, prefix='snakemake')[source]

Bases: object

bash docs for associative arrays - https://www.gnu.org/software/bash/manual/html_node/Arrays.html#Arrays

static dict_to_aa(d)[source]

Converts a dictionary to a Bash associative array This produces the array component of the variable. e.g. ( [var1]=val1 [var2]=val2 ) to make it a correct bash associative array, you need to name it with name=<output of this method>

Return type:

str

classmethod encode_namedlist(named_list)[source]

Convert a namedlist into a Bash associative array See the comments for dict_to_aa()

Return type:

str

encode_snakemake(smk)[source]

Turn a snakemake object into a collection of bash associative arrays

Return type:

str

class snakemake.script.BashScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

combine_preamble_and_source(preamble)[source]
execute_script(fname, edit=False)[source]
static generate_preamble(path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]
Return type:

str

get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.JuliaEncoder[source]

Bases: object

Encoding Python data structures into Julia.

classmethod encode_dict(d)[source]
classmethod encode_items(items)[source]
classmethod encode_list(l)[source]
classmethod encode_namedlist(namedlist)[source]
classmethod encode_positional_items(namedlist)[source]
classmethod encode_value(value)[source]
class snakemake.script.JuliaScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

execute_script(fname, edit=False)[source]
get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.PythonScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

execute_script(fname, edit=False)[source]
static generate_preamble(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local, preamble_addendum='')[source]
get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.REncoder[source]

Bases: object

Encoding Python data structures into R.

classmethod encode_dict(d)[source]
classmethod encode_items(items)[source]
classmethod encode_list(l)[source]

Encode as vector if the type is homogeneous, otherwise use a list.

classmethod encode_namedlist(namedlist)[source]
classmethod encode_numeric(value)[source]
classmethod encode_value(value)[source]
class snakemake.script.RMarkdown(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

execute_script(fname, edit=False)[source]
get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.RScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

execute_script(fname, edit=False)[source]
static generate_preamble(path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, preamble_addendum='')[source]
get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.ReportHref(path, parent=None, url_args=None, anchor=None)[source]

Bases: object

anchor(anchor)[source]
Return type:

TypeVar(ReportHrefType, bound= ReportHref)

child_path(path)[source]
Return type:

TypeVar(ReportHrefType, bound= ReportHref)

url_args(**args)[source]
Return type:

TypeVar(ReportHrefType, bound= ReportHref)

class snakemake.script.RustScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ScriptBase

combine_preamble_and_source(preamble)[source]

The manifest info needs to be moved to before the preamble. Also, because rust-scipt relies on inner docs, there can’t be an empty line between the manifest and preamble.

Return type:

str

static default_dependencies()[source]
Return type:

str

static default_features()[source]
Return type:

str

execute_script(fname, edit=False)[source]
static extract_manifest(source)[source]
Return type:

Tuple[str, str]

static generate_preamble(path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local, preamble_addendum='')[source]
get_preamble()[source]
write_script(preamble, fd)[source]
class snakemake.script.ScriptBase(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: ABC

editable = False
evaluate(edit=False)[source]
abstract execute_script(fname, edit=False)[source]
Return type:

None

abstract get_preamble()[source]
Return type:

str

property local_path
abstract write_script(preamble, fd)[source]
Return type:

None

class snakemake.script.Snakemake(input_, output, params, wildcards, threads, resources, log, config, rulename, bench_iteration, scriptdir=None)[source]

Bases: object

log_fmt_shell(stdout=True, stderr=True, append=False)[source]

Return a shell redirection string to be used in shell() calls

This function allows scripts and wrappers to support optional log files specified in the calling rule. If no log was specified, then an empty string “” is returned, regardless of the values of stdout, stderr, and append.

Return type:

str

Parameters:
  • stdout (bool) – Send stdout to log

  • stderr (bool) – Send stderr to log

  • append (bool) – Do not overwrite the log file. Useful for sending an output of multiple commands to the same log. Note however that the log will not be truncated at the start.

  • output (The following table describes the)

  • ------------- (-------- -------- -------- -----)

  • value (stdout stderr append log return)

  • ------------ (-------- -------- -------- -----)

  • 2>&1 (True True False fn > fn)

  • fn (False True False fn 2>)

  • fn

  • 2>&1

  • fn

  • fn

  • "" (any any any None)

  • ----------- (-------- -------- -------- -----)

property params
report_href(path)[source]

Return an href to the given path in the report context, assuming that the path is given as it is given to the report marker in the workflow.

The returned object can be extended to child paths using the child_path(path) method. This is useful if the referred item is a directory.

Return type:

ReportHref

class snakemake.script.XonshScript(path, cache_path, source, basedir, input_, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local)[source]

Bases: PythonScript

execute_script(fname, edit=False)[source]
snakemake.script.get_language(source_file, source)[source]
snakemake.script.get_source(path, sourcecache, basedir=None, wildcards=None, params=None)[source]
snakemake.script.script(path, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, sourcecache_path, runtime_sourcecache_path)[source]

Load a script from the given basedir + path and execute it.

snakemake.script.snakemake: Snakemake
snakemake.script.strip_re(regex, s)[source]

Strip a substring matching a regex from a string and return the stripped part and the remainder of the original string. Returns an empty string and the original string if the regex is not found

Return type:

Tuple[str, str]