I'm running a custom perl script using Snakemake. I use this rule:
rule complexity_20mer_counter:
input:
os.path.join(fastq_trimmed_dir, '{sample}_{read}' + fastq_extension.split('.')[0] + '_val_' + '{read}'.strip('R') + '.fq.gz')
output:
os.path.join(custom_qc_dir, '{sample}_{read}_20mer_counter.txt')
shell:
'''
#!/bin/bash
perl scripts/20mer_counter.pl {input} > {output}
'''
It fails (I'll get to why later) with this error:
Building DAG of jobs...
MissingInputException in line 1 of /rst1/2017-0205_illuminaseq/scratch/swo-406/2019-01-24/rules/20mer_counter.smk:
Missing input files for rule complexity_20mer_counter:
fastq_trimmed/xs0067_P2018SEQE27R01_S1_R1_001_val_R1.fq.gz
... this is because I use the output of trim_galore, this rule looks like this:
rule trim_galore:
input:
[os.path.join(fastq_raw_dir, '{sample}_'+ read + fastq_extension)
for read in reads]
output:
timmed_fastq_files = [os.path.join(fastq_trimmed_dir, '{sample}_' + read + fastq_extension.split('.')[0] + '_val_' + read.strip('R') + '.fq.gz')
for read in reads],
trimming_reports = [os.path.join(trim_galore_qc_dir, '{sample}_'+ read + fastq_extension + '_trimming_report.txt')
for read in reads]
conda:
"../envs/fastqc.yaml"
shell:
'''
#!/bin/bash
trim_galore --fastqc --gzip -o {fastq_trimmed_dir} --paired --retain_unpaired {input}
# Move all qc reports to the fastq_trimmed_dir
mv {fastq_trimmed_dir}/*.zip \
{fastq_trimmed_dir}/*.html \
{fastq_trimmed_dir}/*.txt \
{trim_galore_qc_dir}
'''
As you can see, trim_galore not only uses my {read} parameter in the output filename but again adds it at the end, only now without the "R".
I tried solving it in my first rule by applying a python .strip('R') on my {read} wildcard, but this does not seem to work. How can I correctly get '1' and '2' from 'R1' and 'R2' (which are my {read} wildcards)?
(Extra bonus points for a nice output.trim_galore.something as input for my complexity_20mer_counter rule, which does not work because the output is a list (it needs 2 fastq files at the same time), but my complexity_20mer_counter rule can be run in parallel again.)
Snakefile
or at least a runnable minimal example. I would suggest that the values forread
are already without theR
. Than you can easily decide when aR
is needed in the filename and when not. $\endgroup$trim_galore
rule you havetimmed_fastq_files
instead oftrimmed_fastq_files
as the label for your output files. I don't know if this is a problem, but little things like that can definitely mess up the whole pipeline. Also, the shebang at the beginning of each "shell" directive is unnecessary. :-) $\endgroup$