0

I want to create a list of BAM files in the folder using this command line:

 ls *.bam > bam_list

But, I would like to integrate this in snakemake. How to do this? This is what I tried, but is not working:

rule bam_list:
    input:
         inlist ="dup/{sample}.bam"
    output:
         outlist = "dup/bam_list"
    shell:
         """
         ls {input.inlist} > {output.outlist}
         """

The output bam_list looks like this:

  bob.bam
  anne.bam
  john.bam
user3224522
  • 1,119
  • 8
  • 19

1 Answers1

1

You could completely skip the input:

rule bam_list:
    output:
         outlist = "dup/bam_list"
    shell:
         """
         ls *.bam > {output.outlist}
         """

edit

rule bam_list:
    input:
        rules.previous.output
    output:
         outlist = "dup/bam_list"
    params:
        indir = lambda wildcards, input: os.path.dirname(input[0])
    shell:
         """
         ls {params.indir}*.bam > {output.outlist}
         """

for more complex logic you will probably have to use input functions.

Maarten-vd-Sande
  • 3,413
  • 10
  • 27
  • Thanks!! the second one does not work... the first one creates me a problem, because I have a sequence of rules in one command line, and it would like bam_list rules before creating the bam files themselves since the input name is not identical... – user3224522 Oct 20 '20 at 15:00