Snakemake: STAR fails in snakemake but not standalone










0















Edit, before trying anything, make sure you install Snakemake with:



conda install -c bioconda -c conda-forge snakemake


As advertised here: snakemake.readthedocs.io. Don't install it as advertised here: anaconda.org/bioconda/snakemake, you will end up with a very old version (the -c conda-forge is important!)



Original post =>



I have been wrestling with Snakemake today. My problem is that my STAR rule gives me an error:



/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/etc/conda/activate.d/activate-binutils_linux-64.sh: line 67: HOST: unbound variable
Error in job star_map while creating output file /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.Aligned.out.bam.
RuleException:
CalledProcessError in line 50 of /home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile:
Command '
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR --runThreadN 8 --genomeDir /rst1/2017-0205_illuminaseq/scratch/swo-390/STAR_references/human --readFilesIn /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R1_001.fastq.gz /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R2_001.fastq.gz --outSAMtype BAM Unsorted --readFilesCommand zcat --outFileNamePrefix /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.
' returned non-zero exit status 1.
File "/home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile", line 50, in __rule_star_map
File "/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message


However, when I just copy that script/command into a terminal, it works.



This is my snakefile:



import os
from glob import glob
#from snakemake.utils import validate

configfile: 'config.yaml'
#validate(config, "config.schema.yaml")

# Set the working directory
workdir: config['workdir']

experiment_name = 'swo-406'
scratch_data_base_dir="/rst1/2017-0205_illuminaseq/scratch"
scratch_data_dir = os.path.join(scratch_data_base_dir, experiment_name)

seqrun = '180413_NB501997_0054_AHTFJ3BGX3'
fastq_dir = os.path.join(scratch_data_dir, 'fastq', seqrun)
preprocessing_dir = os.path.join(scratch_data_dir, 'preprocessing', seqrun)
quantification_dir = os.path.join(scratch_data_dir, 'quantification', seqrun)
if not os.path.isdir(preprocessing_dir):
os.makedirs(preprocessing_dir)

#ref_base_dir = config[ref_base_dir]
ref_genome = os.path.join(config['ref_base_dir'], config['ref_genome'])
star_ref_dir = config['star_ref_dir']

## Rsem settings
rsem_ref_dir = os.path.join(scratch_data_base_dir, 'swo-387', 'RSEM_references')
rsem_ref_base = os.path.join(rsem_ref_dir, 'Homo_sapiens.GRCh38')

log = os.path.join(preprocessing_dir, 'log.txt')

SAMPLES = set([os.path.basename(fastq_file.replace('_R1_001.fastq.gz', '').replace('_R2_001.fastq.gz', ''))
for fastq_file in glob(os.path.join(fastq_dir, '*_R*_001.fastq.gz'))
if not 'Undetermined' in fastq_file])

#star_output_prefix = os.path.join(preprocessing_dir, 'sample.')

# Rule all is a pseudo-rule that tells snakemake what final files to generate.
rule all:
input:
expand(os.path.join(quantification_dir, 'sample'), sample=SAMPLES)

rule star_map:
input:
os.path.join(fastq_dir, 'sample_R1_001.fastq.gz'),
os.path.join(fastq_dir, 'sample_R2_001.fastq.gz'),
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR
--runThreadN 8
--genomeDir star_ref_dir
--readFilesIn input
--outSAMtype BAM Unsorted
--readFilesCommand zcat
--outFileNamePrefix preprocessing_dir/wildcards.sample.
"""

rule samtools_sort:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
samtools sort -T wildcards.sample -O bam input > output
"""


rule rsem_quantify:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
output:
os.path.join(quantification_dir, 'sample')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
rsem-calculate-expression
--paired-end
--bam
--num-threads 8
--strandedness reverse
rsem_ref_base
output
"""


Can anyone spot the error?
By the way, I have to comment out



validate(config, "config.schema.yaml")


Because my snakemake.utils does not seem to have a "validate":



(/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 16:40 nlv24077@kavia /rst1/2017-0205_illuminaseq/scratch/swo-406 > python3
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snakemake.utils import validate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'validate'
>>>


Highest regards,



Freek.










share|improve this question



















  • 1





    What's your snakemake version? validate is available only from v5.1.

    – JeeYem
    Nov 15 '18 at 21:21











  • Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

    – Freek
    Nov 16 '18 at 7:26











  • Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

    – Freek
    Nov 16 '18 at 7:40











  • Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

    – Freek
    Nov 16 '18 at 16:39















0















Edit, before trying anything, make sure you install Snakemake with:



conda install -c bioconda -c conda-forge snakemake


As advertised here: snakemake.readthedocs.io. Don't install it as advertised here: anaconda.org/bioconda/snakemake, you will end up with a very old version (the -c conda-forge is important!)



Original post =>



I have been wrestling with Snakemake today. My problem is that my STAR rule gives me an error:



/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/etc/conda/activate.d/activate-binutils_linux-64.sh: line 67: HOST: unbound variable
Error in job star_map while creating output file /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.Aligned.out.bam.
RuleException:
CalledProcessError in line 50 of /home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile:
Command '
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR --runThreadN 8 --genomeDir /rst1/2017-0205_illuminaseq/scratch/swo-390/STAR_references/human --readFilesIn /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R1_001.fastq.gz /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R2_001.fastq.gz --outSAMtype BAM Unsorted --readFilesCommand zcat --outFileNamePrefix /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.
' returned non-zero exit status 1.
File "/home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile", line 50, in __rule_star_map
File "/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message


However, when I just copy that script/command into a terminal, it works.



This is my snakefile:



import os
from glob import glob
#from snakemake.utils import validate

configfile: 'config.yaml'
#validate(config, "config.schema.yaml")

# Set the working directory
workdir: config['workdir']

experiment_name = 'swo-406'
scratch_data_base_dir="/rst1/2017-0205_illuminaseq/scratch"
scratch_data_dir = os.path.join(scratch_data_base_dir, experiment_name)

seqrun = '180413_NB501997_0054_AHTFJ3BGX3'
fastq_dir = os.path.join(scratch_data_dir, 'fastq', seqrun)
preprocessing_dir = os.path.join(scratch_data_dir, 'preprocessing', seqrun)
quantification_dir = os.path.join(scratch_data_dir, 'quantification', seqrun)
if not os.path.isdir(preprocessing_dir):
os.makedirs(preprocessing_dir)

#ref_base_dir = config[ref_base_dir]
ref_genome = os.path.join(config['ref_base_dir'], config['ref_genome'])
star_ref_dir = config['star_ref_dir']

## Rsem settings
rsem_ref_dir = os.path.join(scratch_data_base_dir, 'swo-387', 'RSEM_references')
rsem_ref_base = os.path.join(rsem_ref_dir, 'Homo_sapiens.GRCh38')

log = os.path.join(preprocessing_dir, 'log.txt')

SAMPLES = set([os.path.basename(fastq_file.replace('_R1_001.fastq.gz', '').replace('_R2_001.fastq.gz', ''))
for fastq_file in glob(os.path.join(fastq_dir, '*_R*_001.fastq.gz'))
if not 'Undetermined' in fastq_file])

#star_output_prefix = os.path.join(preprocessing_dir, 'sample.')

# Rule all is a pseudo-rule that tells snakemake what final files to generate.
rule all:
input:
expand(os.path.join(quantification_dir, 'sample'), sample=SAMPLES)

rule star_map:
input:
os.path.join(fastq_dir, 'sample_R1_001.fastq.gz'),
os.path.join(fastq_dir, 'sample_R2_001.fastq.gz'),
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR
--runThreadN 8
--genomeDir star_ref_dir
--readFilesIn input
--outSAMtype BAM Unsorted
--readFilesCommand zcat
--outFileNamePrefix preprocessing_dir/wildcards.sample.
"""

rule samtools_sort:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
samtools sort -T wildcards.sample -O bam input > output
"""


rule rsem_quantify:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
output:
os.path.join(quantification_dir, 'sample')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
rsem-calculate-expression
--paired-end
--bam
--num-threads 8
--strandedness reverse
rsem_ref_base
output
"""


Can anyone spot the error?
By the way, I have to comment out



validate(config, "config.schema.yaml")


Because my snakemake.utils does not seem to have a "validate":



(/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 16:40 nlv24077@kavia /rst1/2017-0205_illuminaseq/scratch/swo-406 > python3
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snakemake.utils import validate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'validate'
>>>


Highest regards,



Freek.










share|improve this question



















  • 1





    What's your snakemake version? validate is available only from v5.1.

    – JeeYem
    Nov 15 '18 at 21:21











  • Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

    – Freek
    Nov 16 '18 at 7:26











  • Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

    – Freek
    Nov 16 '18 at 7:40











  • Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

    – Freek
    Nov 16 '18 at 16:39













0












0








0








Edit, before trying anything, make sure you install Snakemake with:



conda install -c bioconda -c conda-forge snakemake


As advertised here: snakemake.readthedocs.io. Don't install it as advertised here: anaconda.org/bioconda/snakemake, you will end up with a very old version (the -c conda-forge is important!)



Original post =>



I have been wrestling with Snakemake today. My problem is that my STAR rule gives me an error:



/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/etc/conda/activate.d/activate-binutils_linux-64.sh: line 67: HOST: unbound variable
Error in job star_map while creating output file /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.Aligned.out.bam.
RuleException:
CalledProcessError in line 50 of /home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile:
Command '
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR --runThreadN 8 --genomeDir /rst1/2017-0205_illuminaseq/scratch/swo-390/STAR_references/human --readFilesIn /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R1_001.fastq.gz /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R2_001.fastq.gz --outSAMtype BAM Unsorted --readFilesCommand zcat --outFileNamePrefix /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.
' returned non-zero exit status 1.
File "/home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile", line 50, in __rule_star_map
File "/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message


However, when I just copy that script/command into a terminal, it works.



This is my snakefile:



import os
from glob import glob
#from snakemake.utils import validate

configfile: 'config.yaml'
#validate(config, "config.schema.yaml")

# Set the working directory
workdir: config['workdir']

experiment_name = 'swo-406'
scratch_data_base_dir="/rst1/2017-0205_illuminaseq/scratch"
scratch_data_dir = os.path.join(scratch_data_base_dir, experiment_name)

seqrun = '180413_NB501997_0054_AHTFJ3BGX3'
fastq_dir = os.path.join(scratch_data_dir, 'fastq', seqrun)
preprocessing_dir = os.path.join(scratch_data_dir, 'preprocessing', seqrun)
quantification_dir = os.path.join(scratch_data_dir, 'quantification', seqrun)
if not os.path.isdir(preprocessing_dir):
os.makedirs(preprocessing_dir)

#ref_base_dir = config[ref_base_dir]
ref_genome = os.path.join(config['ref_base_dir'], config['ref_genome'])
star_ref_dir = config['star_ref_dir']

## Rsem settings
rsem_ref_dir = os.path.join(scratch_data_base_dir, 'swo-387', 'RSEM_references')
rsem_ref_base = os.path.join(rsem_ref_dir, 'Homo_sapiens.GRCh38')

log = os.path.join(preprocessing_dir, 'log.txt')

SAMPLES = set([os.path.basename(fastq_file.replace('_R1_001.fastq.gz', '').replace('_R2_001.fastq.gz', ''))
for fastq_file in glob(os.path.join(fastq_dir, '*_R*_001.fastq.gz'))
if not 'Undetermined' in fastq_file])

#star_output_prefix = os.path.join(preprocessing_dir, 'sample.')

# Rule all is a pseudo-rule that tells snakemake what final files to generate.
rule all:
input:
expand(os.path.join(quantification_dir, 'sample'), sample=SAMPLES)

rule star_map:
input:
os.path.join(fastq_dir, 'sample_R1_001.fastq.gz'),
os.path.join(fastq_dir, 'sample_R2_001.fastq.gz'),
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR
--runThreadN 8
--genomeDir star_ref_dir
--readFilesIn input
--outSAMtype BAM Unsorted
--readFilesCommand zcat
--outFileNamePrefix preprocessing_dir/wildcards.sample.
"""

rule samtools_sort:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
samtools sort -T wildcards.sample -O bam input > output
"""


rule rsem_quantify:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
output:
os.path.join(quantification_dir, 'sample')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
rsem-calculate-expression
--paired-end
--bam
--num-threads 8
--strandedness reverse
rsem_ref_base
output
"""


Can anyone spot the error?
By the way, I have to comment out



validate(config, "config.schema.yaml")


Because my snakemake.utils does not seem to have a "validate":



(/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 16:40 nlv24077@kavia /rst1/2017-0205_illuminaseq/scratch/swo-406 > python3
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snakemake.utils import validate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'validate'
>>>


Highest regards,



Freek.










share|improve this question
















Edit, before trying anything, make sure you install Snakemake with:



conda install -c bioconda -c conda-forge snakemake


As advertised here: snakemake.readthedocs.io. Don't install it as advertised here: anaconda.org/bioconda/snakemake, you will end up with a very old version (the -c conda-forge is important!)



Original post =>



I have been wrestling with Snakemake today. My problem is that my STAR rule gives me an error:



/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/etc/conda/activate.d/activate-binutils_linux-64.sh: line 67: HOST: unbound variable
Error in job star_map while creating output file /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.Aligned.out.bam.
RuleException:
CalledProcessError in line 50 of /home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile:
Command '
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR --runThreadN 8 --genomeDir /rst1/2017-0205_illuminaseq/scratch/swo-390/STAR_references/human --readFilesIn /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R1_001.fastq.gz /rst1/2017-0205_illuminaseq/scratch/swo-406/fastq/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14_R2_001.fastq.gz --outSAMtype BAM Unsorted --readFilesCommand zcat --outFileNamePrefix /rst1/2017-0205_illuminaseq/scratch/swo-406/preprocessing/180413_NB501997_0054_AHTFJ3BGX3/0054_P2018SEQE15S4_S14.
' returned non-zero exit status 1.
File "/home/nlv24077/experiments/experiments/swo-406/scripts/Snakefile.snakefile", line 50, in __rule_star_map
File "/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message


However, when I just copy that script/command into a terminal, it works.



This is my snakefile:



import os
from glob import glob
#from snakemake.utils import validate

configfile: 'config.yaml'
#validate(config, "config.schema.yaml")

# Set the working directory
workdir: config['workdir']

experiment_name = 'swo-406'
scratch_data_base_dir="/rst1/2017-0205_illuminaseq/scratch"
scratch_data_dir = os.path.join(scratch_data_base_dir, experiment_name)

seqrun = '180413_NB501997_0054_AHTFJ3BGX3'
fastq_dir = os.path.join(scratch_data_dir, 'fastq', seqrun)
preprocessing_dir = os.path.join(scratch_data_dir, 'preprocessing', seqrun)
quantification_dir = os.path.join(scratch_data_dir, 'quantification', seqrun)
if not os.path.isdir(preprocessing_dir):
os.makedirs(preprocessing_dir)

#ref_base_dir = config[ref_base_dir]
ref_genome = os.path.join(config['ref_base_dir'], config['ref_genome'])
star_ref_dir = config['star_ref_dir']

## Rsem settings
rsem_ref_dir = os.path.join(scratch_data_base_dir, 'swo-387', 'RSEM_references')
rsem_ref_base = os.path.join(rsem_ref_dir, 'Homo_sapiens.GRCh38')

log = os.path.join(preprocessing_dir, 'log.txt')

SAMPLES = set([os.path.basename(fastq_file.replace('_R1_001.fastq.gz', '').replace('_R2_001.fastq.gz', ''))
for fastq_file in glob(os.path.join(fastq_dir, '*_R*_001.fastq.gz'))
if not 'Undetermined' in fastq_file])

#star_output_prefix = os.path.join(preprocessing_dir, 'sample.')

# Rule all is a pseudo-rule that tells snakemake what final files to generate.
rule all:
input:
expand(os.path.join(quantification_dir, 'sample'), sample=SAMPLES)

rule star_map:
input:
os.path.join(fastq_dir, 'sample_R1_001.fastq.gz'),
os.path.join(fastq_dir, 'sample_R2_001.fastq.gz'),
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
STAR
--runThreadN 8
--genomeDir star_ref_dir
--readFilesIn input
--outSAMtype BAM Unsorted
--readFilesCommand zcat
--outFileNamePrefix preprocessing_dir/wildcards.sample.
"""

rule samtools_sort:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.bam')
output:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
samtools sort -T wildcards.sample -O bam input > output
"""


rule rsem_quantify:
input:
os.path.join(preprocessing_dir, 'sample.Aligned.out.sorted.bam')
output:
os.path.join(quantification_dir, 'sample')
shell:
"""
source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake
rsem-calculate-expression
--paired-end
--bam
--num-threads 8
--strandedness reverse
rsem_ref_base
output
"""


Can anyone spot the error?
By the way, I have to comment out



validate(config, "config.schema.yaml")


Because my snakemake.utils does not seem to have a "validate":



(/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 16:40 nlv24077@kavia /rst1/2017-0205_illuminaseq/scratch/swo-406 > python3
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snakemake.utils import validate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'validate'
>>>


Highest regards,



Freek.







snakemake






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:42







Freek

















asked Nov 15 '18 at 15:45









FreekFreek

3881418




3881418







  • 1





    What's your snakemake version? validate is available only from v5.1.

    – JeeYem
    Nov 15 '18 at 21:21











  • Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

    – Freek
    Nov 16 '18 at 7:26











  • Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

    – Freek
    Nov 16 '18 at 7:40











  • Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

    – Freek
    Nov 16 '18 at 16:39












  • 1





    What's your snakemake version? validate is available only from v5.1.

    – JeeYem
    Nov 15 '18 at 21:21











  • Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

    – Freek
    Nov 16 '18 at 7:26











  • Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

    – Freek
    Nov 16 '18 at 7:40











  • Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

    – Freek
    Nov 16 '18 at 16:39







1




1





What's your snakemake version? validate is available only from v5.1.

– JeeYem
Nov 15 '18 at 21:21





What's your snakemake version? validate is available only from v5.1.

– JeeYem
Nov 15 '18 at 21:21













Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

– Freek
Nov 16 '18 at 7:26





Wow, seems like I'm on the truly ancient version of 3.13.3! I did a fresh install but perhaps my cluster's conda is old? I'll dive into this, thanx for the tip!

– Freek
Nov 16 '18 at 7:26













Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

– Freek
Nov 16 '18 at 7:40





Hmm, I have an old snakemake but a recent conda, can you explain this: 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > snakemake --version 3.13.3 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:36 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda --version conda 4.5.11 (/rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake) 08:37 nlv24077@lefkimi /rst1/2017-0205_illuminaseq/scratch/swo-406 > conda update snakemake Solving environment: done # All requested packages already installed.

– Freek
Nov 16 '18 at 7:40













Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

– Freek
Nov 16 '18 at 16:39





Ok I found the error, so Snakemake to get the latest snakemake, one needs to install with: conda "install -c bioconda -c conda-forge snakemake", not "conda install -c bioconda snakemake".

– Freek
Nov 16 '18 at 16:39












1 Answer
1






active

oldest

votes


















1














Could you remove all the source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemakecommands from your shell portions of the different rules in the Snakefile and activate the environment either:



  1. run command source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake before you actually run snakemake on that Snakefile (you can even add a version of snakemake that has validate to this environment). So you can run source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake and then run snakemake.


  2. Create a conda environment file matching that environment and add the conda : path/to/created/env/fileparameter in your rules requiring the environment. Then run snakemake with the --use-conda flag


Since you are using the same environment for all your rules, it is better to use option 1 as option 2 is much slower and will make it unecessarily rule specific.



I can reproduce your error with this example Snakefile:



rule test_activate:
output : "test.txt"
shell: "source activate NGS && conda list > output"


I get the same unbound variable error but for a different variable as my environment is different. This is an explanation of what might be going on:



Virtualenv activate script won't run in bash script with set -euo



in the sense that once you run it through snakemake vs terminal some variables become unbound which is treated as error.






share|improve this answer























  • This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

    – Freek
    Nov 16 '18 at 7:25











  • I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

    – JohnnyBD
    Nov 16 '18 at 10:07











  • Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

    – Freek
    Nov 16 '18 at 14:40










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323044%2fsnakemake-star-fails-in-snakemake-but-not-standalone%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Could you remove all the source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemakecommands from your shell portions of the different rules in the Snakefile and activate the environment either:



  1. run command source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake before you actually run snakemake on that Snakefile (you can even add a version of snakemake that has validate to this environment). So you can run source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake and then run snakemake.


  2. Create a conda environment file matching that environment and add the conda : path/to/created/env/fileparameter in your rules requiring the environment. Then run snakemake with the --use-conda flag


Since you are using the same environment for all your rules, it is better to use option 1 as option 2 is much slower and will make it unecessarily rule specific.



I can reproduce your error with this example Snakefile:



rule test_activate:
output : "test.txt"
shell: "source activate NGS && conda list > output"


I get the same unbound variable error but for a different variable as my environment is different. This is an explanation of what might be going on:



Virtualenv activate script won't run in bash script with set -euo



in the sense that once you run it through snakemake vs terminal some variables become unbound which is treated as error.






share|improve this answer























  • This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

    – Freek
    Nov 16 '18 at 7:25











  • I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

    – JohnnyBD
    Nov 16 '18 at 10:07











  • Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

    – Freek
    Nov 16 '18 at 14:40















1














Could you remove all the source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemakecommands from your shell portions of the different rules in the Snakefile and activate the environment either:



  1. run command source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake before you actually run snakemake on that Snakefile (you can even add a version of snakemake that has validate to this environment). So you can run source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake and then run snakemake.


  2. Create a conda environment file matching that environment and add the conda : path/to/created/env/fileparameter in your rules requiring the environment. Then run snakemake with the --use-conda flag


Since you are using the same environment for all your rules, it is better to use option 1 as option 2 is much slower and will make it unecessarily rule specific.



I can reproduce your error with this example Snakefile:



rule test_activate:
output : "test.txt"
shell: "source activate NGS && conda list > output"


I get the same unbound variable error but for a different variable as my environment is different. This is an explanation of what might be going on:



Virtualenv activate script won't run in bash script with set -euo



in the sense that once you run it through snakemake vs terminal some variables become unbound which is treated as error.






share|improve this answer























  • This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

    – Freek
    Nov 16 '18 at 7:25











  • I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

    – JohnnyBD
    Nov 16 '18 at 10:07











  • Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

    – Freek
    Nov 16 '18 at 14:40













1












1








1







Could you remove all the source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemakecommands from your shell portions of the different rules in the Snakefile and activate the environment either:



  1. run command source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake before you actually run snakemake on that Snakefile (you can even add a version of snakemake that has validate to this environment). So you can run source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake and then run snakemake.


  2. Create a conda environment file matching that environment and add the conda : path/to/created/env/fileparameter in your rules requiring the environment. Then run snakemake with the --use-conda flag


Since you are using the same environment for all your rules, it is better to use option 1 as option 2 is much slower and will make it unecessarily rule specific.



I can reproduce your error with this example Snakefile:



rule test_activate:
output : "test.txt"
shell: "source activate NGS && conda list > output"


I get the same unbound variable error but for a different variable as my environment is different. This is an explanation of what might be going on:



Virtualenv activate script won't run in bash script with set -euo



in the sense that once you run it through snakemake vs terminal some variables become unbound which is treated as error.






share|improve this answer













Could you remove all the source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemakecommands from your shell portions of the different rules in the Snakefile and activate the environment either:



  1. run command source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake before you actually run snakemake on that Snakefile (you can even add a version of snakemake that has validate to this environment). So you can run source activate /rst1/2017-0205_illuminaseq/scratch/swo-406/snakemake and then run snakemake.


  2. Create a conda environment file matching that environment and add the conda : path/to/created/env/fileparameter in your rules requiring the environment. Then run snakemake with the --use-conda flag


Since you are using the same environment for all your rules, it is better to use option 1 as option 2 is much slower and will make it unecessarily rule specific.



I can reproduce your error with this example Snakefile:



rule test_activate:
output : "test.txt"
shell: "source activate NGS && conda list > output"


I get the same unbound variable error but for a different variable as my environment is different. This is an explanation of what might be going on:



Virtualenv activate script won't run in bash script with set -euo



in the sense that once you run it through snakemake vs terminal some variables become unbound which is treated as error.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 23:49









JohnnyBDJohnnyBD

11115




11115












  • This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

    – Freek
    Nov 16 '18 at 7:25











  • I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

    – JohnnyBD
    Nov 16 '18 at 10:07











  • Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

    – Freek
    Nov 16 '18 at 14:40

















  • This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

    – Freek
    Nov 16 '18 at 7:25











  • I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

    – JohnnyBD
    Nov 16 '18 at 10:07











  • Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

    – Freek
    Nov 16 '18 at 14:40
















This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

– Freek
Nov 16 '18 at 7:25





This works indeed! I probably should have mentioned that I use qsub, and I initially got "STAR not found errors", I thought I solved it initially using the "source activate" method. Now I added STAR to the path at the top of my script (export PATH=/rst1/2017-0205_illuminaseq/tools/STAR-2.6.1a/source:$PATH #this is not conda's star btw) and it works. Somehow I would have thought that it would be good to activate the Snakemake env because it has all my tools. I find it strange that it causes an error and that I have to manually add all tools to my path. But for, now, I'm happy.

– Freek
Nov 16 '18 at 7:25













I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

– JohnnyBD
Nov 16 '18 at 10:07





I incorrectly assumed you were using conda. If it is something you need in most of your submitted jobs you can add source activate ... to $HOME/.bash_profile and it will be available when the jobs are submitted. I usually create a jobscript file and run snakemake with snakemake --jobscript path/to/jobscript. In your case the jobscript can be as simple as the template just change # properties = properties to export PATH... and add any other tools. You can then reuse this jobscript whenever you need.

– JohnnyBD
Nov 16 '18 at 10:07













Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

– Freek
Nov 16 '18 at 14:40





Ok, thanx, I will try this. But first I have to find out how I can get my conda to install Snakemake 5.1 instead of 3.13... Thanx for the support so far.

– Freek
Nov 16 '18 at 14:40



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323044%2fsnakemake-star-fails-in-snakemake-but-not-standalone%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線