Home > Software design >  Perl installed via conda snakemake shell error: Can´t open perl script .. no such file or directory
Perl installed via conda snakemake shell error: Can´t open perl script .. no such file or directory

Time:08-10

I´m currently writing a snakemake pipeline, for which I want to include a perl script. The script is not written by me, but from a github page. I never worked with perl before.

I installed perl (5.32.1) via conda. I have installed miniconda and am working on my universities unix server.

The code for my perl script rule looks like this:

rule r1_filter5end:
input:
    config["arima_mapping"]   "unprocessed_bam/{sample}_R1.sam"
output:
    config["arima_mapping"]   "filtered_bam/{sample}_R1.bam"
params:
conda:
    "../envs/arima_mapping.yaml"
log:
    config["logs"]   "arima_mapping/r1_filter5end/{sample}_R1.log"
threads:
    12
shell:
    "samtools view --threads {threads} -h {input} -b | perl ../scripts/filter_five_end.pl | samtools -b -o {output} 2> log"

When I run this I receive the following error:

Can't open perl script "../scripts/filter_five_end.pl": no such file or directory found

From what I learned while researching is that the 1. line of a perl script sets the path to my perl executable. The script I downloaded had the following path:

#!/usr/bin/perl

And since I use perl installed via conda this is probably wrong. So I set the path to:

#!/home/mi/my_user/miniconda3/bin/perl

However this did still not work, regardless of if I call

perl ../scripts/filter_five_end.pl

or

../scripts/filter_five_end.pl

Maybe it´s just not possible to run perl scripts via snakemake? Anyone who had encountered this specific similar case?^^

CodePudding user response:

The problem is not with the shebang. The interpreter path in the shebang doesn't matter because you're calling it with perl ../path directly. The shell that this command is executed in will resolve the path to the perl program (which is very likely the conda one) and then run the script, only taking flags (like -T or -w) from the shebang inside the script.

The error message means it cannot find the actual script file. I suspect when you run that shell command, it's in the wrong directory. Try a fully qualified path.

As stated by OP in their comment:

I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.

CodePudding user response:

Not quite an answer but perhaps relevant:

I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.

This is not entirely correct, I think. The reference point is the directory set by -d/--directory which by default is where you execute snakemake:

--directory DIR, -d DIR
    Specify working directory (relative paths in the snakefile will use this as their origin). (default: None)
  • Related