Snakemake input functions
Snakemake input functions.
We will start with rule cat, which takes two files and makes a new one named all.
What cat does is take the content of the input files and stick them together in the output files.
Within the files sample_a and sample _b, we have a short declarative string.
# rule cat:
# input: "sample_a.txt", "sample_b.txt"
# output: "all.txt"
# shell: "cat {input} x {output}"
We launch the pipeline, rule cat is run, and file all is generated.
If we open the file all we see is a concatenation of the two input files.
########
So if we look at the input, we see that both files are the same except for one letter. Since this is a common occurrence, there is a built-in function in Snakemake to deal with these situations named expand.
We can use it like this.
# rule copy:
# input: expand("sample_{x}.txt", x =["a","b"])
# output: "all.txt"
# shell: "cat {input} x {output}"
When we launch the pipeline, the rule is run, and we can see that the intended shell command is generated as well as the all file.
########
An important aspect of expand is that it can take wildcards propagating from the output.
Let's make the extension of the file a wildcard, and let's name it y.
If you are not sure how wildcards work, I will encourage you to check the videos from this series on the topic. Also, we have a video explaining rule all.
# rule all:
# input: "all.txt"
#
# rule copy:
# input: expand("sample_{x}.{y}", x =["a","b"])
# output: "all.{y}"
# shell: "cat {input} x {output}"
When we launch the pipeline, it crashes with a wildcard error claiming that no values were given for wildcard y.
# WildcardError in file /Users/Marcos/Desktop/snakemake/Snakefile, line 5:
# No values given for wildcard 'y'.
# File "/Users/Marcos/Desktop/snakemake/Snakefile", line 5, in module
#########
What we need to do is indicate with a double curly bracket that the y in the input is actually the wildcard associated with the y wildcard from the input.
# rule all:
# input: "all.txt"
#
# rule copy:
# input: expand("sample_{x}.{{y}}", x=["a","b"])
# output: "all.{y}"
# shell: "cat {input} x {output}"
Now the pipeline launches, the rules are run, the shell string is well formed, and we get the all.txt file.
########
The input also admits native python functions, such as lambda. So we can write the equivalent string of input files.
Note that here we have to give wildcards as a parameter of the function.
# rule all:
# input: "all.txt"
#
# rule copy:
# input:
# lambda wildcards: \
# ["sample_" + x + "." + wildcards.y \
# for x in ["a", "b"]]
# output: "all.{y}"
# shell: "cat {input} x {output}"
We can launch the pipeline, the rules are run, the shell command is well formed, and we get the all.txt file.
##############
Actually, we can pass any function to the input to customize it as much as we want. For example, we can write an equivalent function using a for loop.
So now we need to specify that the rule input should be the function we just wrote.
# rule all:
# input: "all.txt"
#
# X = ["a", "b"]
# def the_files(wildcards):
# files=[]
# for letter in X:
# file = "sample_" + letter + "." + wildcards.y
# files = files+[file]
# return files
#
# rule copy:
# input: the_files
# output: "all.{y}"
# shell: "cat {input} x {output}"
Again the pipeline does not crash, the shell command is well formed, and we get the all.txt file as well.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Snakemake input functions», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.