如何将.txt文件中的每一行用作snakemake的新输入

发布于 2025-02-13 05:11:47 字数 123 浏览 0 评论 0原文

我在其中有一个“ filenames.txt”文件:

a.txt
b.txt
c.txt
d.txt

我想将这些行用作snakemake中的输入。有人知道我该怎么做吗?

I have a file 'filenames.txt' with in it:

a.txt
b.txt
c.txt
d.txt

I want to use these lines as input in snakemake. Does anyone know how I could do this?

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

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

发布评论

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

评论(1

乖乖兔^ω^ 2025-02-20 05:11:47

您可以在蛇文件中使用Python。这是您可以获取文件名列表的方式:

with open('filenames.txt') as fh:
    filenames = [line.strip() for line in fh]

然后,我不确定您打算如何使用这些文件名。
如果您希望工作流创建这些文件,则应将其制成Input top all 规则的部分:

rule all:
    input: filenames

您当然应该有一个可以创建这样的规则文件:

rule create_file:
    output: "{letter}.txt"
    shell:
        """
        touch {output[0]}
        """

You can use python inside a snakefile. Here is how you could obtain a list of file names:

with open('filenames.txt') as fh:
    filenames = [line.strip() for line in fh]

Then, I'm not sure how you intend to use those file names.
If you want your workflow to create those files, it should be made the input section of the top all rule:

rule all:
    input: filenames

And you should of course have a rule that can create such a file:

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