Snakemake: Обмен переменных - PullRequest
       11

Snakemake: Обмен переменных

2 голосов
/ 30 октября 2019

У меня есть несколько последовательностей ONT, которые были вызваны на MINIT. Таким образом, когда я демультиплексирую с guppy_barcoder, я получаю каталог файлов fastq для каждого штрих-кода. Я хочу использовать snakemake в качестве менеджера рабочего процесса для прохождения этих файлов fastq через наши анализы, но это предполагает замену {штрих-кода} для {sample} в какой-то момент.

BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']
SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']

rule all:
    input:
        directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE)), #guppy_barcoder
        expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample


rule demultiplex:
    input:
        glob.glob("Sequencing_reads/fastq_pass/*fastq")
    output:
        directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE))
    shell:
        "guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r "


rule gather:
    input:
        rules.demultiplex.output
    output:
        "Sequencing_reads/gathered/{sample}_ONT.fastq"
    shell:
        "cat Sequencing_reads/demultiplexed/{wildcards.barcode}/*fastq > {output.fastq} "

Это дает мне ошибку:

RuleException in line 32 of /home/eriny/sandbox/ONT_unicycler_pipeline/ONT_pipeline.smk: 'Wildcards' object has no attribute 'barcode'

Но на самом деле я думаю, что что-то упустил концептуально. Мне бы хотелось, чтобы rule gather было примерно таким:

cat Sequencing_reads/demultiplexed/barcode01/*fastq > Sequencing_reads/gathered/sample01_ONT.fastq

Я попытался настроить некоторые словари, чтобы образец и штрих-код получали один и тот же ключ, но мой синтаксис должен быть нарушен.

Я надеюсь найти способ 1: 1 сопоставить одно имя переменной с другим.

1 Ответ

1 голос
/ 31 октября 2019

Я надеюсь найти 1: 1 способ сопоставления одного имени переменной с другим.

Я думаю, что выборка в словарь - это возможность в сочетании с лямбда-выражением в качестве входной функции. чтобы получить штрих-код, назначенный образцу. Например:

BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']
SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']

sam2bar= dict(zip(SAMPLE, BARCODE))

rule all:
    input:
        expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample

rule demultiplex:
    input:
        glob.glob("Sequencing_reads/fastq_pass/*fastq"),
    output:
        done= touch('demux.done'), # This signals that guppy has completed
    shell:
        "guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r "


rule gather:
    input:
        done= 'demux.done',
        fastq= lambda wc: glob.glob("Sequencing_reads/demultiplexed/%s/*fastq" % sam2bar[wc.sample])
    output:
        fastq= "Sequencing_reads/gathered/{sample}_ONT.fastq"
    shell:
        "cat {input.fastq} > {output.fastq} "
...