Search code examples
pythonsnakemake

How to perform simple string operations in snakemake output


I am creating my first snakemake file, and I got to the point where I need to perform a simple string operation on the value of my output, so that my shell command works as expected:

rule sketch:
  input:
    'out/genomes.txt'
  output:
    'out/genomes.msh'
  shell:
    'mash sketch -l {input} -k 31 -s 100000 -o {output}'

I need to apply the split function to {output} so that only the name of the file up to the extension is used. I couldn't find anything in the docs or in related questions.


Solution

  • You could remove the extension within the shell command

    rule sketch:
      input:
        'out/genomes.txt'
      output:
        'out/genomes.msh'
      shell:
        'mash sketch -l {input} -k 31 -s 100000 -o $(echo "{output}" | sed -e "s/.msh//")'