snakemake
snakemake copied to clipboard
Linting interprets command string starting with / wrongly as path
Snakemake version
7.12.1 (latest stable)
Describe the bug
When linting the the rule below using snakemake --lint --cores 1, snakemake complains about "Absolute path" (see Logs below) even though
the intended command has nothing to do with any paths. I believe it is interpreting the / at the beginning of the string and assumes it is a path, which of course it isn't. Could linting be made more smart to recognize and handle those cases correctly?
Logs
Lints for snakefile /home/seb/workspace/dolomite/code/scpipe/workflow/rules/star.smk:
* Absolute path "/^[0-9]+[ ]+[0-9]+[ ]+[0-9]+/ {{print $0}}" in line 225:
Do not define absolute paths inside of the workflow, since this renders your workflow irreproducible on other machines. Use path relative to the working directory instead, or make the path configurable via a config file.
Also see:
https://snakemake.readthedocs.io/en/latest/snakefiles/configuration.html#configuration
Minimal example
rule awk_convert:
input:
"in.txt"
output:
"out.txt"
shell:
"""
awk '/^[0-9]+[ ]+[0-9]+[ ]+[0-9]+/ {{print $0}}' {input} > {output}
"""
Additional context
`
Similar thing happened to me. Line was roughly
link="https://.../filename"
filename=f"{link.split('/')[-1]"
Version 8.20.6 (latest stable at this moment)
samples.loc[:, "sample_id"] = [
line.split("/")[-2] for line in samples["path_to_sample"]
]
Gives false positive for this piece of code as well.