代码之家  ›  专栏  ›  技术社区  ›  dddxxx

根据输入文件的名称使用不同的shell命令

  •  0
  • dddxxx  · 技术社区  · 7 年前

    我正试图用鲑鱼来校准RNA序列数据,然而,因为我使用了多种小鼠品系,所以所需的基因组指数将取决于小鼠品系。我将这些信息保存在文件名中,这样做的目的是,如果输入文件有一个特定的名称,那么应该使用某个索引,否则应该使用另一个索引。

    这个脚本运行得很好,并返回了我需要的所有文件,但是,它总是在 其他的 语句,并完全忽略 如果 语句,尽管文件名在技术上完全相同。

    我尝试了各种方法,但都没有成功,所以我也想知道实现我想要的目标的最佳方法(不一定是最普遍的方法,因为这个管道只供我使用)。

    代码:

    rule salmon_mapping:
            input:
                    fastq="data/raw_data/{sample}.fastq.gz",
                    c57_index="/gpfs/data01/glasslab/home/cag104/refs/Mus_musculus/Ensemble/C57/Salmon_Index/",
                    aj_index="/gpfs/data01/glasslab/home/cag104/refs/Mus_musculus/Ensemble/AJ/Salmon_Index/"
            log:
                    "logs/salmon/{sample}_quant.log"
            params:
                    prefix="{sample}"
            output:
                    "data/processed_data/{sample}/quant.sf",
                    "data/processed_data/{sample}/cmd_info.json"
            run:
                    if {input.fastq} == "data/raw_data/mouse_AJ_M_Liver_Hepatocyte_RNA_notx_CG_1_VML_s20180131_GTCCGC.fastq.gz" or {input.fastq} == "data/raw_data/mouse_AJ_M_Liver_Hepatocyte_RNA_notx_CG_2_VML_s20180131_GTGAAA.fastq.gz":
                            shell("salmon quant -p 16 -i {input.aj_index} -l A -r <(gunzip -c {input.fastq}) -o data/processed_data/{wildcards.sample} &> {log}")
                    else:
                            shell("salmon quant -p 16 -i {input.c57_index} -l A -r <(gunzip -c {input.fastq}) -o data/processed_data/{wildcards.sample} &> {log}"
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   Manavalan Gajapathy Pal    7 年前

    代替 {input.fastq} 在里面 if 语句,但不在中 shell 对账单,带 input.fastq 。在您的示例中, 输入fastq公司 是一个字符串,这是您想要的,而 {input.fastq} 使其成为python set 对象

        2
  •  1
  •   Russ Hyde    7 年前

    使用基于通配符定义规则输入的函数。

    def select_fastq_and_index(wildcards):
        fq = "data/raw_data/{sample}.fastq.gz".format(sample = wildcards["sample"])
        idx = ""
        if wildcards["sample"] in [             
        "mouse_AJ_M_Liver_Hepatocyte_RNA_notx_CG_1_VML_s20180131_GTCCGC",
        "mouse_AJ_M_Liver_Hepatocyte_RNA_notx_CG_2_VML_s20180131_GTGAAA"
            ]:
                idx = foo
        else:
                idx = bar
        return fq, idx
    

    然后重写规则:

    rule salmon_mapping:
            input:
                    select_fastq_and_index
            log:
                    "logs/salmon/{sample}_quant.log"
            params:
                    prefix="{sample}"
            output:
                    "data/processed_data/{sample}/quant.sf",
                    "data/processed_data/{sample}/cmd_info.json"
            shell: """
                salmon quant -p 16 -i {input[1]} -l A \
                -r <(gunzip -c {input[0]}) \
                -o data/processed_data/{wildcards.sample} \
                &> {log}
                """