The following workflow has a single step that generates a number of files with the number specified by parameter num
.
The following cell will not be executed directly (with Ctrl-Enter
or Shift-Enter
) because it is a formal SoS cell. It has to be executed by magic %run
or %sosrun
.
[no_task]
parameter: num = 2
input: for_each = {'i': range(num)}
output: f'test_{i}.txt'
sh: expand=True
sleep {3*i}
echo test_{i} > test_{i}.txt
echo "Test_{i}.txt generated"
%sosrun no_task
Test_0.txt generated Test_1.txt generated
When we rerun the workflow with option --num 3
to generate one more file, the first two are ignored because they have already been generated.
%sosrun no_task --num 3
Test_2.txt generated
Keyword task
separates the reset of the step process as external tasks:
[task]
parameter: num = 2
input: for_each = {'i': range(num)}
output: f'test_{i}.txt'
task:
sh: expand=True
sleep {5*i}
echo test_{i} > test_{i}.txt
echo "Test_{i}.txt generated"
input: 'data/*.fastq', group_by=1, concurrent=True
sh: expand=True
echo "Counting lines of {_input}"
sleep {5 * _index}
wc -l {_input}
Counting lines of data/S20_R1.fastq 2000 data/S20_R1.fastq Counting lines of data/S20_R2.fastq 2000 data/S20_R2.fastq