metatable의 열을 기반으로 snakemake 규칙의 조건부 실행
Jan 15 2021
snakemake 워크 플로에서 조건부로 규칙을 실행하기 위해 텍스트 파일의 열을 사용하려고합니다.
텍스트 파일은 다음과 같습니다.
id end sample_name fq1 fq2
a paired test_paired resources/SRR1945436_1.fastq.gz resources/SRR1945436_2.fastq.gz
b single test_single resources/SRR1945436.fastq.gz NA
텍스트 파일의 각 샘플에 대해 끝 열의 값이 쌍을 이루면 규칙 cp_fastq_pe를 사용하고 end가 단일이면 규칙 cp_fastq_pe를 사용하여 각각 fq1 및 fq2 또는 fq1 파일 만 처리하고 싶습니다.
Snakefile의 관련 부분은 다음과 같습니다.
import pandas as pd
samples = pd.read_table("config/samples.tsv").set_index("id", drop=False)
all_ids=list(samples["id"])
rule cp_fastq_pe:
"""
copy file to resources
"""
input:
fq1=lambda wildcards: samples.loc[wildcards.id, "fq1"],
fq2=lambda wildcards: samples.loc[wildcards.id, "fq2"]
output:
"resources/fq/{id}_1.fq.gz",
"resources/fq/{id}_2.fq.gz"
shell:
"""
cp {input.fq1} {output[0]}
cp {input.fq2} {output[1]}
"""
rule cp_fastq_se:
"""
copy file to resources
"""
input:
fq1=lambda wildcards: samples.loc[wildcards.id, "fq1"]
output:
"resources/fq/{id}.fq.gz",
shell:
"""
cp {input.fq1} {output}
"""
이것이 가능합니까?
답변
2 DmitryKuzminov Jan 15 2021 at 14:54
비슷한 문제가 있었는데 여기서 해결했습니다. Snakemake 입력을 선택 사항이지만 비어 있지 않게 만드는 방법은 무엇입니까?
다음은 문제에 맞게 조정 된 아이디어입니다. 먼저 ruleorder
모호성을 해결하기 위해 를 지정해야합니다 (그렇지 않으면 쌍이 가능할 때마다 항상 싱글을 적용 할 수 있습니다).
ruleorder: cp_fastq_pe > cp_fastq_se
다음으로, cp_fastq_pe
규칙에서 유효한 파일 (쌍이있는 경우)을 반환하거나 존재하지 않는 파일에 대한 자리 표시자를 반환하는 함수를 정의해야합니다.
rule cp_fastq_pe:
input:
fq1=lambda wildcards: samples.loc[wildcards.id, "fq1"],
fq2=lambda wildcards: samples.loc[wildcards.id, "fq2"] if "fq2" in samples else "non-existing-filename"
이 규칙은 "fq2"
필드가 존재하고 유효한 파일을 나타내는 모든 샘플에 적용 됩니다. 나머지 샘플에는 다른 규칙이 선택됩니다.