I am building a workflow in snakemake and would like to recycle one of the rules to two different input sources. The input sources could be either source1 or source1+source2 and depending on the input the output directory would also vary. Since this was quite complicated to do in the same rule and I didn't want to create the copy of the full rule I would like to create two rules with different input/output, but running same command.
Is it possible to make this work? I get the DAG resolved correctly but the job don't go through on the cluster (ERROR : bamcov_cmd not defined).. An example below (both rules use the same command at the end):
this is command
def bamcov_cmd(): return( (deepTools_path+"bamCoverage " + "-b {input.bam} " + "-o {output} " + "--binSize {params.bw_binsize} " + "-p {threads} " + "--normalizeTo1x {params.genome_size} " + "{params.read_extension} " + "&> {log}") ) this is the rule
rule bamCoverage: input: bam = file1+"/{sample}.bam", bai = file1+"/{sample}.bam.bai" output: "bamCoverage/{sample}.filter.bw" params: bw_binsize = bw_binsize, genome_size = int(genome_size), read_extension = "--extendReads" log: "bamCoverage/logs/bamCoverage.{sample}.log" benchmark: "bamCoverage/.benchmark/bamCoverage.{sample}.benchmark" threads: 16 run: bamcov_cmd() this is the optional rule2
rule bamCoverage2: input: bam = file2+"/{sample}.filter.bam", bai = file2+"/{sample}.filter.bam.bai" output: "bamCoverage/{sample}.filter.bw" params: bw_binsize = bw_binsize, genome_size = int(genome_size), read_extension = "--extendReads" log: "bamCoverage/logs/bamCoverage.{sample}.log" benchmark: "bamCoverage/.benchmark/bamCoverage.{sample}.benchmark" threads: 16 run: bamcov_cmd()