How to handle python version/package conflicts in snakemake?

Viewed 283

I am attempting to build a pipeline using snakemake. I have created a conda environment which uses python v3.9 and also contains the snakemake program. My first couple of rules need v3.9. All the rules work great until I get to my 3rd rule, called rule3, where I want to use pysam, which is currently unavailable with python 3.9, and therefore can't be installed in the main conda environment. I'm aware that snakemake is supposed to be able to navigate these kinds of issues by being able to use multiple conda environments. I therefore included the yaml for a python environment that has both pysam and python v3.8. In rule3 I include the following lines

conda:
        "Env2.yaml" # used for running pysam

run:
        import pysam
        import sys
        import os
        .
        .
        .
        .

When I attempt to run snakemake I am left with the following message:

Conda environments are only allowed with shell, script, notebook, or wrapper directives (not with run).

This means you cannot run python in snakemake with different conda environments.

Given the problem above, my question is: What is the right way to deal with python version/package conflicts given that you can't run python code with the different conda environments in snakemake?

0 Answers
Related