I'm new to SnakeMake. I'm trying to teach it myself with this simple Snakefile:
(IDS, ) = glob_wildcards( "{id}.txt" )
print ( str ( IDS ) )
rule all:
input:
expand ( "out/{id}-1.txt", id = IDS )
rule copy:
input:
"{id}.txt"
output:
"out/{id}-1.txt"
shell:
"cp {input} {output}"
The first time I run it (when out doesn't exist yet), it goes fine and creates the three copies in out. The next time, IDS contains 'out/c-1', 'out/a-1', 'out/b-1'
, which of course isn't what I want, cause I'd like that glob_wildcards scanned the first level only. Any way to do it, maybe with the regex parameter the function receives?
So far, I only managed it via a filter, after the IDS creation:
IDS = [ id for id in IDS if '/' not in id ]
But I was hoping for something more compact.
From what I see in the glob_wildcards
implementation, this function doesn't have any parameters that limits the levels. That means that your solution (1 line of code) is probably the most compact solution in case you really need the output folder to be the nesting folder of input.
The simple solution is to have input and output separated into sibling folders. In this case the code below will search in a clean input folder that is never polluted with output:
(IDS, ) = glob_wildcards( "path_to_input/{id}.txt" )