snakemake:如何对glob_wildcards()排序

发布于 2025-02-08 16:38:42 字数 661 浏览 2 评论 0原文

如何使用glob_wildcards()以字母顺序获取文件?

假设我在同一目录中有Sample1.txt,Sample2.txt,Sample3.txt和Sample4.txt。 当我运行此代码时:

file_pattern = 'dir_test/{sample}.txt'
FILES = glob_wildcards(file_pattern)
SAMPLES = FILES.sample


rule all:
    input:
        expand(file_pattern, sample=SAMPLES),
        "concat.txt"

rule concat:
    input:
        expand("dir_test/{sample}.txt", sample=SAMPLES),
    output:
        "concat.txt"
    shell:
        """
        cat {input} > {output}
        """

我得到了glob_wildcards()的结果,按照以下任意顺序出现:

$ cat concat.txt

This is Sample4
This is Sample1
This is Sample2
This is Sample3

How can I get files in alphabetical order using glob_wildcards()?

Suppose I have sample1.txt, sample2.txt, sample3.txt, and sample4.txt in the same directory.
When I run this code:

file_pattern = 'dir_test/{sample}.txt'
FILES = glob_wildcards(file_pattern)
SAMPLES = FILES.sample


rule all:
    input:
        expand(file_pattern, sample=SAMPLES),
        "concat.txt"

rule concat:
    input:
        expand("dir_test/{sample}.txt", sample=SAMPLES),
    output:
        "concat.txt"
    shell:
        """
        cat {input} > {output}
        """

I got the results of glob_wildcards() come out in an arbitrary order as follows:

$ cat concat.txt

This is Sample4
This is Sample1
This is Sample2
This is Sample3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽清风入怀 2025-02-15 16:38:42

您是否尝试过类似:(

SAMPLES = sorted(list(FILES.sample))

不确定list()甚至是必要的)。

Have you tried something like:

SAMPLES = sorted(list(FILES.sample))

(not sure that list() is even necessary).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文