我需要使用文件的每一行tissuesused.txt
作为snakemake中并行规则的输入。我想总共大约有 48 个工作机会。
for line in $(cat tissuesused.txt)
do
echo "Sorting $line.phen_fastqtl.bed to $line/$line.pheno.bed..."
bedtools sort -header -i $line/$line.phen_fastqtl.bed > $line/$line.pheno.bed
echo "bgzipping $line/$line.pheno.bed..."
bgzip -f $line/$line.pheno.bed
#figure out where tabix outputs
echo "Indexing $line/$line.pheno.bed.gz..."
tabix -p bed $line/$line.pheno.bed.gz
done
我该如何在snakemake中做到这一点?我在网上找不到任何关于此的信息。这项工作发生在管道的中途,因此我不知道如何在蛇文件的顶部为尚不存在的文件定义一个函数。我只想创建一个字符串列表,每个字符串都包含在以下位置找到的一种人体组织的缩写tissuesused.txt
。我找到了一个Snakemake 文档中的部分 https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#functions-as-input-files看起来它们可能相关,但我不确定如何将其应用到我的案例中。先感谢您。
编辑:
这是我到目前为止所拥有的,不确定它是否会起作用:
def fileAsList(file):
with open(file) as f:
for line in f:
lis = []
spl = line.split()
lis.append(spl[0])
return lis
...
rule sort_zip_ind_pheno:
input:
tis=fileAsList("tissuesused.txt"),
chk=".make_tis_dirs.chkpnt"
output:
touch(".sort_zip_ind_pheno.chkpnt")
shell:
"bedtools sort -header -i {input.tis}/{input.tis}.phen_fastqtl.bed > \
{input.tis}/{input.tis}.pheno.bed;"
"bgzip -f {input.tis}/{input.tis}.pheno.bed;"
"tabix -p bed {input.tis}/{input.tis}.pheno.bed.gz"
请告诉我这是否有意义。
我想你正在寻找的是检查站 https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution在《蛇形》中。看一下这个例子:
checkpoint get_tissue:
output:
"tissuesused.txt"
run:
with open(output[0], 'a') as f:
for i in range(9):
f.write(f"{i}\n")
rule read_tissue:
output:
"tissue_{n}.txt"
shell:
"""
echo "this is tissue {wildcards.n}" > {output}
"""
def read_tissues_output(wildcards):
with open(checkpoints.get_tissue.get().output[0]) as f:
samples = [sample for sample in f.read().split('\n') if len(sample) > 0] # we dont want empty lines
return expand("tissue_{sample}.txt", sample=samples)
rule all:
input:
read_tissues_output
并运行它
snakemake --until all
规则所有用途read_tissues_output
作为输入函数(正如您在问题中指定的那样)。然后该函数尝试打开检查点的输出get_tissue
,如果它还不存在,它将生成它。一旦输出存在,函数就会读取文件,并返回我们想要生成的文件(tissue_{1-10}
). Rule read_tissue
可以为我们生成然后(并行)生成这些文件。
edit:
组织使用.txt:
WHLBLD
TESTIS
THYROID
蛇形锉刀
def read_tissues_output():
with open('tissuesused.txt') as f:
samples = [sample for sample in f.read().split('\n') if len(sample) > 0] # we dont want empty lines
return expand("tissue_{sample}.txt", sample=samples)
rule all:
input:
read_tissues_output()
rule read_tissue:
output:
"tissue_{n}.txt"
shell:
"""
echo "this is tissue {wildcards.n}" > {output}
"""
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)