Reputation: 1151
I would like to run a bash script inside the snakemake pipeline. But I do not know how to call the input and output of snakemake in a bash script.
snakemake:
rule xxx:
input:
"input.vcf"
output:
"output.tab"
shell:
"""
some_bash.sh {input} {output}
"""
bash script:
#!/bin/bash
paste <(bcftools snakemake@input[0] |\
awk -F"\t" 'BEGIN {print "CHR\tPOS\tID\tREF\tALT\tFILTER"} \
!/^#/ {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}') \
\
<(bcftools query -f '[\t%SAMPLE=%GT]\n' snakemake@input[0] |\
awk 'BEGIN {print "nHet"} {print gsub(/0\|1|1\|0|0\/1|1\/0/, "")}') \
\
<(bcftools query -f '[\t%SAMPLE=%GT]\n' snakemake@input[0] |\
awk 'BEGIN {print "nHomAlt"} {print gsub(/1\|1|1\/1/, "")}') \
\
<(bcftools query -f '[\t%SAMPLE=%GT]\n' snakemake@input[0] |\
awk 'BEGIN {print "nHomRef"} {print gsub(/0\|0|0\/0/, "")}') \
\
<(bcftools snakemake@input[0] | awk -F"\t" '/^#CHROM/ {split($0, header, "\t"); print "HetSamples"} \
!/^#CHROM/ {for (i=10; i<=NF; i++) {if (gsub(/0\|1|1\|0|0\/1|1\/0/, "", $(i))==1) {printf header[i]","}; if (i==NF) {printf "\n"}}}') \
\
<(bcftools snakemake@input[0] | awk -F"\t" '/^#CHROM/ {split($0, header, "\t"); print "HomSamplesAlt"} \
!/^#CHROM/ {for (i=10; i<=NF; i++) {if (gsub(/1\|1|1\/1/, "", $(i))==1) {printf header[i]","}; if (i==NF) {printf "\n"}}}') \
\
| sed 's/,\t/\t/g' | sed 's/,$//g' > snakemake@output[0]
Error I get:
[E::main] unrecognized command 'snakemake@input[0]'
[E::main] unrecognized command 'snakemake@input[0]'
[E::main] unrecognized command 'snakemake@input[0]'
[E::hts_open_format] [E::hts_open_format] Failed to open file "snakemake@input[0]" : No such file or directoryFailed to open file "snakemake@input[0]" : No such file or directory
Upvotes: 0
Views: 743
Reputation: 2079
You need to get the input arguments using bash syntax, snakemake@input[0]
is specifically for R scripts using a script
directive.
In particular, you can replace snakemake@input[0]
with $1
, which gets the first argument to a bash script and snakemake@output[0]
with $2
, the second argugment. To be safe, wrap those with double quotes in case there are spaces in the filenames, e.g. "$1"
.
Upvotes: 2