1
votes

I have a Snakefile with a rule to create and activate a conda environment from a yaml file with samtools version 1.9, then to check the version:

rule environ:
    conda:
        "envs/samtools.yaml"
    shell:
        'samtools --version > version.txt'

And the yaml file:

name: samtools
channels:
  - bioconda
dependencies:
  - samtools=1.9*

I run snakemake using:

snakemake --cores 1 --use-conda

It seems to build the environment successfully, and when I check the version in .snakemake/conda/79eeda10/bin/samtools it is 1.9:

.snakemake/conda/79eeda10/bin/samtools --version
samtools 1.9
Using htslib 1.9
Copyright (C) 2018 Genome Research Ltd.

However the output in version.txt indicates the samtools being run is 1.3:

samtools 1.3
Using htslib 1.3
Copyright (C) 2015 Genome Research Ltd.

When I use this method to run a different rule that needs a specific samtools parameter only available in version 1.9, it also fails due to 1.3 being run instead.

Lastly, I am activating a conda environment containing snakemake before I run this workflow. But I would think there are no issues/conflicts with running a separate environment for specific rules?

Can anyone help me to determine why my conda environment is being built but not activated for these rules? Any help would be much appreciated.

Update:

I have realised that samtools 1.3 is the default version on my cluster which is called even when I activate a conda environment with samtools 1.9 installed. To get around this I need to specifically call the samtools binary within my conda path as follows: /share/ClusterShare/thingamajigs/jamtor/local/lib/miniconda3/envs/py37/envs/snk/bin/samtools

However, this does not solve the problem of building an environment containing samtools 1.9 within a snakemake rule and using this version. Due to the unique hash for the environment build, I would not know the path to specify to call it within the shell command. Does anyone know of a way to get around this?

Thanks

1
I don't have this issue. Conda prepends to PATH and that should override user- and system-level software. Do you have default conda init output in your .bashrc? Also, versions of Snakemake and Conda might be relevant.merv

1 Answers

2
votes

I found the problem - I had a path pointing to samtools 1.3 in my PATH environment variable, in my .bashrc. I removed this and it solved the problem - samtools 1.9 was built and the environment used by snakemake appropriately. Strange as I would have thought the conda environment would take precedence over the PATH variable.