Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Snakemake-如何按子目录获取目录中的所有文件_Python_Snakemake - Fatal编程技术网

Python Snakemake-如何按子目录获取目录中的所有文件

Python Snakemake-如何按子目录获取目录中的所有文件,python,snakemake,Python,Snakemake,我有一个包含多个目录的目录: /test/cond1/ /test/cond2/ /test/cond3/ /test/cond4/ 所有子目录都有几个不同的文件: cond1 : a1.txt, a2.txt cond2 : b1.txt, b2.txt, b3.txt cond3 : c1.txt, c2.txt, c4.txt cond4 : d1.txt,c2.txt, c4.txt, d2.txt 我正在使用snakemake运行一个命令,我需要按cond获取所有文件,并用空格分隔

我有一个包含多个目录的目录:

/test/cond1/
/test/cond2/
/test/cond3/
/test/cond4/
所有子目录都有几个不同的文件:

cond1 : a1.txt, a2.txt
cond2 : b1.txt, b2.txt, b3.txt
cond3 : c1.txt, c2.txt, c4.txt
cond4 : d1.txt,c2.txt, c4.txt, d2.txt
我正在使用snakemake运行一个命令,我需要按cond获取所有文件,并用空格分隔

我试着这样做:

def get_motifs_tf(wildcards):
    file_list = sorted(glob.glob("tf_final/{wildcards.cond}/*.bed"))
    return " ".join(file_list)
这是我的规则,蛇头

rule compute_combi_enrichment:
    """
    For a given input, compute the enrichment in n-wise TF combinations using OLOGRAM-MODL.
    """
    input:
        query = 'input/core_silencer/{cond}/core_silencer.bed',
        excl = "input/exclude_region_dhs.bed",
        genome = "input/mm9.chromsizes"

    params:
        trs = get_motifs_tf,
        minibatch_number = 16, minibatch_size = 10   # Modulate depending on available RAM
    threads: 8                                       # Do not use 16 threads to not vampirize all the cluster

    output: 'output/ologram_result/{cond}/00_ologram_stats.tsv',

    shell: """
    set +u; source /gpfs/tagc/home/Apps/anaconda3/bin/activate dev; set -u
    gtftk ologram -z -c {input.genome} -p {input.query} --more-bed {params.trs} \
        -o output/ologram_result/{wildcards.cell_line} --force-chrom-peak --force-chrom-more-bed  \
        -V 3 -k {threads} -mn {params.minibatch_number} -ms {params.minibatch_size} \
        --more-bed-multiple-overlap --bed-excl {input.excl} --no-date \
        --multiple-overlap-max-number-of-combinations 80
    """
in--more bed{params.trs}

我希望得到:

/test/cond1/a1.txt /test/cond1/a2.txt
然后

等等…

我解决了这个问题:

函数中的通配符必须在stp中转换,且不带括号:

def get_motifs_tf(wildcards):
    file_list = sorted(glob.glob("tf_final/"+str(wildcards.cond)+"/*.bed"))
    return " ".join(file_list)
def get_motifs_tf(wildcards):
    file_list = sorted(glob.glob("tf_final/"+str(wildcards.cond)+"/*.bed"))
    return " ".join(file_list)